void GetTime::begin() { config = new Configuration("Time", new ConfigurationItem("maxcount", 10), new ConfigurationItem("ntp1", "ntp.scarlet.be"), new ConfigurationItem("ntp2", "ntp.belnet.be"), new ConfigurationItem("timezone", 1), NULL); max_count = config->GetValue("maxcount"); ntp1 = (char *)config->GetStringValue("ntp1"); ntp2 = (char *)config->GetStringValue("ntp2"); timezone = config->GetValue("timezone"); #if 0 //UPnPService::begin(config); //alarmpin = config->GetValue("pin"); #endif sntp_init(); sntp_setservername(0, ntp1); sntp_setservername(1, ntp2); (void)sntp_set_timezone(timezone); // Wire.begin(); }
void ICACHE_FLASH_ATTR sntp_test() { sntp_init(); sntp_setservername(0, (char*)"cn.pool.ntp.org"); sntp_setservername(1, (char*)"1.cn.pool.ntp.org"); sntp_setservername(2, (char*)"2.cn.pool.ntp.org"); os_timer_disarm(&test_timer); os_timer_setfn(&test_timer, test_timer_cb, NULL); os_timer_arm(&test_timer, 0, 0); // Start immediately. }
void ICACHE_FLASH_ATTR rtc_init(uint8_t timezone) { sntp_setservername(0, NTP_SERVER1); sntp_setservername(1, NTP_SERVER2); // sntp_setservername(2, NTP_SERVER3); sntp_stop(); // if (true == sntp_set_timezone(sysCfg.timezone)) sntp_set_timezone(timezone); sntp_init(); myrtc = 0; }
static void get_time() { struct timeval now; int sntp_retry_cnt = 0; int sntp_retry_time = 0; sntp_setoperatingmode(0); sntp_setservername(0, "pool.ntp.org"); sntp_init(); while (1) { for (int32_t i = 0; (i < (SNTP_RECV_TIMEOUT / 100)) && now.tv_sec < 1525952900; i++) { vTaskDelay(100 / portTICK_RATE_MS); gettimeofday(&now, NULL); } if (now.tv_sec < 1525952900) { sntp_retry_time = SNTP_RECV_TIMEOUT << sntp_retry_cnt; if (SNTP_RECV_TIMEOUT << (sntp_retry_cnt + 1) < SNTP_RETRY_TIMEOUT_MAX) { sntp_retry_cnt ++; } printf("SNTP get time failed, retry after %d ms\n", sntp_retry_time); vTaskDelay(sntp_retry_time / portTICK_RATE_MS); } else { printf("SNTP get time success\n"); break; } } }
/** * Initialize this module. * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC). */ void sntp_init(void) { #ifdef SNTP_SERVER_ADDRESS #if SNTP_SERVER_DNS sntp_setservername(0, SNTP_SERVER_ADDRESS); #else #error SNTP_SERVER_ADDRESS string not supported SNTP_SERVER_DNS==0 #endif #endif /* SNTP_SERVER_ADDRESS */ if (sntp_pcb == NULL) { SNTP_RESET_RETRY_TIMEOUT(); sntp_pcb = udp_new(); LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL); if (sntp_pcb != NULL) { udp_recv(sntp_pcb, sntp_recv, NULL); #if SNTP_STARTUP_DELAY sys_timeout((u32_t)SNTP_STARTUP_DELAY_FUNC, sntp_request, NULL); #else sntp_request(NULL); #endif } } }
static void setServer(int id, const char* name_or_ip) { if (name_or_ip) { //TODO: check whether server is given by name or IP sntp_setservername(id, (char*) name_or_ip); } }
void start_sntp_service(void) { char *ntp_server = NULL; /*os_printf("+start_sntp_service\n");*/ // check if need to set ntp server ntp_server = sntp_getservername(0); /*os_printf("ntp_server:(%p)%s\n", ntp_server, ntp_server);*/ if ((ntp_server == NULL) || (os_strcmp(ntp_server, NTP_SERVER1) != 0)) { // no ntp server. set it sntp_setservername(0, NTP_SERVER1); sntp_setservername(1, NTP_SERVER2); sntp_setservername(2, NTP_SERVER3); } sntp_init(); }
void ICACHE_FLASH_ATTR user_sntp_init(void) { static os_timer_t user_sntp_timer; // 配置sntp服务器 sntp_setservername(0,"0.cn.pool.ntp.org"); sntp_setservername(1,"1.cn.pool.ntp.org"); sntp_setservername(2,"2.cn.pool.ntp.org"); // sntp初始化 sntp_init(); // 定时器初始化 os_timer_disarm(&user_sntp_timer); os_timer_setfn(&user_sntp_timer, sntp_timer_cb , NULL); os_timer_arm(&user_sntp_timer, SNTP_READ_INTERVAL, 1); }
void wifiConnectCb(uint8_t status) { if(status == STATION_GOT_IP){ sntp_setservername(0, "pool.ntp.org"); // set sntp server after got ip address sntp_init(); os_timer_disarm(&sntp_timer); os_timer_setfn(&sntp_timer, (os_timer_func_t *)sntpfn, NULL); os_timer_arm(&sntp_timer, 1000, 1);//1s } else { MQTT_Disconnect(&mqttClient); } }
void ICACHE_FLASH_ATTR user_init() { // init UART for debugging baud rate comes from user_config.h uart_div_modify(0, UART_CLK_FREQ / BAUD_RATE); os_printf("\r\nESP8266 OOK decoding\r\n"); // speed boost (hopefully) //system_update_cpu_freq(160); system_update_cpu_freq(80); // setup loop callback in system task queue system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0); // init wifi using creds in wifi_config.h. Put your own creds in the file connect_wifi(WIFI_SSID, WIFI_PSK); // apparently an accurate system time is needed for SSL, so start up // SNTP stuff. // SNTP is also used for timestamping emails and alarm triggeringings sntp_setservername(0, "time.nist.gov"); sntp_setservername(1, "time-c.nist.gov"); sntp_set_timezone(TIMEZONE); sntp_init(); // init stuff for the ook decoder gpio_init(); gpio_intr_handler_register(ook_intr_handler, (void*) &unprocessedPackets); init_ook_decoder(); // webserver-related initialisation init_web_server(); attach_btn_clear(clearTriggeredSensors); attach_btn_arm_alarm(arm_alarm); attach_btn_disarm_alarm(disarm_alarm); // update so we don't just have a blank page on startup updateWebpage(); }
//Called from the wifi callback, Set the clock from NTP void ICACHE_FLASH_ATTR NIXE_Set_Clock_Wifi() { sntp_setservername(0, "se.pool.ntp.org"); // set server 0 by domain name sntp_setservername(1, "0.europe.pool.ntp.org"); // set server 1 by domain name sntp_set_timezone(+1); sntp_init(); uint32 current_stamp; current_stamp = sntp_get_current_timestamp(); os_printf("sntp: %d, %s \n",current_stamp, sntp_get_real_time(current_stamp)); //Update the External RTC via i2c // init tm Struct /* time->tm_sec time->tm_min time->tm_hour time->tm_wday time->tm_mday time->tm_mon time->tm_year */ time_t unix = sntp_get_current_timestamp(); //nixietime = gmtime(&unix); //gmtime not in sdk.. tm_sec + tm_min*60 tm_hour*3600 tm_yday*86400 + (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 ds1307_setTime(nixietime); }
void ICACHE_FLASH_ATTR at_exeCmdNTP(uint8_t id) { uint8 buffer[255] = {0}; sntp_stop(); int i; uint32 tm = 0; int ntp_servers_len = sizeof(ntp_servers) / sizeof(ntp_servers[0]); for (i = 0; i < 3; i++) { if (i >= ntp_servers_len) break; sntp_setservername(i, ntp_servers[i]); } sntp_set_timezone(NTP_OFFSET); sntp_init(); os_sprintf(buffer, "NTP init\r\n"); at_port_print(buffer); at_response_ok(); }
static void initialize_sntp(void) { sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, "pool.ntp.org"); sntp_init(); }