MeterLogger
Functions
unix_time.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ICACHE_FLASH_ATTR void init_unix_time (void)
 
ICACHE_FLASH_ATTR uint32_t get_unix_time (void)
 
ICACHE_FLASH_ATTR uint32_t get_uptime (void)
 

Function Documentation

◆ get_unix_time()

ICACHE_FLASH_ATTR uint32_t get_unix_time ( void  )

Definition at line 55 of file unix_time.c.

References current_unix_time, and sntp_get_current_timestamp().

Referenced by en61107_received_task(), en61107_request_send(), kmp_received_task(), kmp_request_send(), and minute_timer_func().

55  {
57 
58  return current_unix_time;
59 }
uint32 sntp_get_current_timestamp()
uint32_t current_unix_time
Definition: unix_time.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_uptime()

ICACHE_FLASH_ATTR uint32_t get_uptime ( void  )

Definition at line 61 of file unix_time.c.

References current_unix_time, init_time, ntp_offline_second_counter, and sntp_get_current_timestamp().

Referenced by add_watchdog(), reset_watchdog(), and watchdog_timer_func().

61  {
63  if (init_time == 0) {
65  }
66  else {
68  }
69 }
uint32 sntp_get_current_timestamp()
uint32_t init_time
Definition: unix_time.c:8
uint32_t ntp_offline_second_counter
Definition: unix_time.c:10
uint32_t current_unix_time
Definition: unix_time.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_unix_time()

ICACHE_FLASH_ATTR void init_unix_time ( void  )

Definition at line 37 of file unix_time.c.

References ntp_offline_second_counter, ntp_offline_second_counter_timer, ntp_offline_second_counter_timer_func(), NULL, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, sntp_check_timer, sntp_check_timer_func(), sntp_init(), sntp_set_timezone(), and sntp_setservername().

37  {
38  // init sntp
39  sntp_setservername(0, "dk.pool.ntp.org"); // set server 0 by domain name
40  sntp_setservername(1, "us.pool.ntp.org"); // set server 1 by domain name
41  sntp_set_timezone(0); // UTC time
42  sntp_init();
43 
44  // start timer to make sure we go ntp reply
47  os_timer_arm(&sntp_check_timer, 2000, 0);
48 
52  os_timer_arm(&ntp_offline_second_counter_timer, 1000, 1); // every seconds
53 }
static os_timer_t ntp_offline_second_counter_timer
Definition: unix_time.c:14
void sntp_init(void)
#define os_timer_disarm
Definition: osapi.h:51
#define NULL
Definition: def.h:47
#define os_timer_func_t
Definition: os_type.h:35
ICACHE_FLASH_ATTR static void ntp_offline_second_counter_timer_func(void *arg)
Definition: unix_time.c:33
#define os_timer_setfn
Definition: osapi.h:52
ICACHE_FLASH_ATTR static void sntp_check_timer_func(void *arg)
Definition: unix_time.c:16
void sntp_setservername(u8_t idx, char *server)
static os_timer_t sntp_check_timer
Definition: unix_time.c:6
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
uint32_t ntp_offline_second_counter
Definition: unix_time.c:10
bool sntp_set_timezone(sint8 timezone)
Here is the call graph for this function: