diff --git a/firmware/0x00000.bin b/firmware/0x00000.bin index a7c2c1a..f71c07d 100644 Binary files a/firmware/0x00000.bin and b/firmware/0x00000.bin differ diff --git a/firmware/0x10000.bin b/firmware/0x10000.bin index 0206037..a3bf620 100644 Binary files a/firmware/0x10000.bin and b/firmware/0x10000.bin differ diff --git a/firmware/sha1sums b/firmware/sha1sums index cfb3cd8..8176c10 100644 --- a/firmware/sha1sums +++ b/firmware/sha1sums @@ -1,2 +1,2 @@ -1ca55cabb786b24fd4683839ce8d226f35d822c1 0x00000.bin -290bdf2cf693375094de994ca9d5dfaa29d448f0 0x10000.bin +c36c175bf752ea6e3ad3fec38b296a0b7b6bb146 0x00000.bin +32c3b4519d79fc041d2821db41ef99d802bcf45f 0x10000.bin diff --git a/user/user_main.c b/user/user_main.c index 9fdff29..989d9d2 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -444,7 +444,17 @@ void ICACHE_FLASH_ATTR timer_func(void *arg) { if (ntp_sync_done()) { uint8_t *timestr = get_timestr(); - MQTT_local_publish("$SYS/broker/time", get_timestr(config.ntp_timezone), 8, 0, 0); + MQTT_local_publish("$SYS/broker/time", timestr, 8, 0, 0); + + // Save system time to RTC memory + uint32_t test_magic = MAGIC_NUMBER; + system_rtc_mem_write (64, &test_magic, 4); + system_rtc_mem_write (65, (uint32_t *) get_weekday(), 4); + uint8_t timeval[4]; + timeval[0] = atoi(×tr[0]); + timeval[1] = atoi(×tr[3]); + timeval[2] = atoi(×tr[6]); + system_rtc_mem_write (66, (uint32_t *) timeval, 4); #ifdef SCRIPTED check_timestamps(timestr); #endif @@ -781,6 +791,20 @@ void user_init() { blob_zero(RETAINED_SLOT, MAX_RETAINED_LEN); } +#ifdef NTP + // Restore system time from RTC memory (if found) + uint32_t test_magic; + system_rtc_mem_read (64, &test_magic, 4); + if (test_magic == MAGIC_NUMBER) { + char weekday[4]; + system_rtc_mem_read (65, (int *)weekday, 4); + set_weekday_local(weekday); + uint8_t time[4]; + system_rtc_mem_read (66, (int *)time, 4); + set_time_local(time[0], time[1], time[2]); + } +#endif + #ifdef SCRIPTED loop_count = loop_time = 0; script_enabled = false;