The ESP8266 clock seems to drift quite badly so a single NTP sync when
we connect to wifi isn't sufficient to keep our time accurate. Set up a
timer to resync hourly.
- * Copyright 2017 Jonathan McDowell <noodles@earth.li>
+ * Copyright 2017-2019 Jonathan McDowell <noodles@earth.li>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
struct station_config wificfg;
static os_timer_t update_timer;
struct station_config wificfg;
static os_timer_t update_timer;
+static os_timer_t ntp_timer;
static const struct fontchar clocknums[] = {
{ .width = 5,
static const struct fontchar clocknums[] = {
{ .width = 5,
+void ICACHE_FLASH_ATTR ntp_func(void *arg)
+{
+ ntp_get_time();
+}
+
void ICACHE_FLASH_ATTR wifi_callback(System_Event_t *evt)
{
switch (evt->event) {
case EVENT_STAMODE_CONNECTED:
case EVENT_STAMODE_DISCONNECTED:
void ICACHE_FLASH_ATTR wifi_callback(System_Event_t *evt)
{
switch (evt->event) {
case EVENT_STAMODE_CONNECTED:
case EVENT_STAMODE_DISCONNECTED:
+ os_timer_disarm(&ntp_timer);
break;
case EVENT_STAMODE_GOT_IP:
ntp_get_time();
ota_check();
break;
case EVENT_STAMODE_GOT_IP:
ntp_get_time();
ota_check();
+ os_timer_disarm(&ntp_timer);
+ os_timer_setfn(&ntp_timer, ntp_func, NULL);
+ os_timer_arm(&ntp_timer, 3600 * 1000 /* Hourly */, 1);