uint32_t ICACHE_FLASH_ATTR NTP_SetTimeZone(PACKET_CMD *cmd) { REQUEST req; int timezone; CMD_Request(&req, cmd); if (CMD_GetArgc(&req) != 1) { return 0; } CMD_PopArgs(&req, (uint8_t*)&timezone); if ((timezone > 13) || (timezone < -11)) { return -1; } if (timezone != sntp_get_timezone()) { sntp_stop(); if (true == sntp_set_timezone(timezone)) { sntp_init(); } } return 0; }
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 rtc_timezone(uint8_t timezone) { sntp_stop(); // if (true == sntp_set_timezone(sysCfg.timezone)) sntp_set_timezone(timezone); sntp_init(); myrtc = sntp_get_current_timestamp(); }
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; }
LOCAL void ICACHE_FLASH_ATTR sntp_starts_here(){ ipaddr_aton("192.168.254.30", &NTP1); // sntp_setservername(0, ”bg.pool.ntp.org”); // set server 0 by domain name // sntp_setservername(1, ”us.pool.ntp.org”); // set server 0 by domain name sntp_setserver(0,NTP1); sntp_set_timezone(+2); sntp_init(); os_timer_disarm(&ds18b20_timer); os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)sntp_cb, (void *)0); os_timer_arm(&ds18b20_timer, DELAY, 1); }
void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) { sntp_stop(); setServer(0, server1); setServer(1, server2); setServer(2, server3); sntp_set_timezone(timezone/3600); sntp_set_daylight(daylightOffset_sec); sntp_init(); }
void WEAK_ATTR configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) { sntp_stop(); setServer(0, server1); setServer(1, server2); setServer(2, server3); s_timezone_sec = timezone; s_daylightOffset_sec = daylightOffset_sec; sntp_set_timezone(timezone/3600); sntp_init(); }
irom static app_action_t application_function_ntp_set(const string_t *src, string_t *dst) { int timezone; string_new(static, ip, 32); if((parse_string(1, src, &ip) == parse_ok) && (parse_int(2, src, &timezone, 0) == parse_ok)) { config.ntp_server = ip_addr(string_to_ptr(&ip)); config.ntp_timezone = timezone; sntp_setserver(0, &config.ntp_server); sntp_set_timezone(config.ntp_timezone); } return(application_function_ntp_dump(src, dst)); }
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(); }
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); }
bool sntp_set_timezone_in_seconds(sint32 timezone) { return sntp_set_timezone((sint8)(timezone/(60*60))); //TODO: move this to the same file as sntp_set_timezone() in lwip1.4, and implement correctly over there. }
void ntp_setup(void) { tv_t tv; tz_t tz; time_t sec; struct ip_info getinfo; // Wait until we have an IP address before we set the time if(!network_init) return; if(ntp_init == 0) { ip_addr_t *addr = (ip_addr_t *)safecalloc(sizeof(ip_addr_t),1); // form pool.ntp.org ipaddr_aton("206.108.0.131", addr); sntp_setserver(1,addr); ipaddr_aton("167.114.204.238", addr); sntp_setserver(2,addr); #if 0 // Alternate time setting if the local router does NTP if(wifi_get_ip_info(0, &getinfo)) { printf("NTP:0 GW: %s\n", ipv4_2str(getinfo.gw.addr)); printf("NTP:0 IP: %s\n", ipv4_2str(getinfo.ip.addr)); sntp_setserver(1, & getinfo.gw); sntp_setserver(2, & getinfo.ip); } else { printf("NTP:0 failed to get GW address\n"); return; } #endif if( sntp_set_timezone(0) ) { printf("NTP: set_timeone OK\n"); sntp_init(); safefree(addr); ntp_init = 1; printf("NTP:1\n"); } else { printf("NTP: set_timeone Failed\n"); } } if(ntp_init == 1) { // they hard coded it to +8 hours from GMT if( (sec = sntp_get_current_timestamp()) > 10 ) { sntp_stop(); ntp_init = 2; } } if(ntp_init == 2) { time_t s; tm_t *p; printf("NTP:2\n"); // they return GMT + 8 // sec = sec - (8UL * 3600UL); tv.tv_sec = sec; printf("ntp_init: %s\n", asctime(gmtime(&sec))); printf("ntp_init: %s\n", ctime_gm(&sec)); tv.tv_usec = 0; tz.tz_minuteswest = 300; tz.tz_dsttime = 0; settimeofday(&tv, &tz); printf("SEC:%ld\n",sec); printf("TIME:%s\n", ctime(&sec)); printf("Zone: %d\n", (int) sntp_get_timezone()); ntp_init = 3; set_dst(tv.tv_sec); print_dst_gmt(); print_dst(); p = gmtime(&tv.tv_sec); mktime(p); printf("Localtime: %s\n", asctime(p)); } }