diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 72fe5d2aa..c78cddc9b 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -5,6 +5,7 @@ * Add some MQTT housekeeping which might solve issue (#5755) * Add command SetOption65 0/1 and more Tuya Serial based device support (#5815) * Fix include of my_user_config.h in sonoff_aws_iot.cpp (#5930) + * Fix exception 9 when syslog is enabled and NTP is just synced (#5917) * * 6.5.0.14 20190602 * Change webserver HTML input, button, textarea, and select name based on id diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index da0c83db1..575776072 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -173,6 +173,7 @@ bool i2c_flg = false; // I2C configured bool spi_flg = false; // SPI configured bool soft_spi_flg = false; // Software SPI configured bool ntp_force_sync = false; // Force NTP sync +bool ntp_synced_message = false; // NTP synced message flag myio my_module; // Active copy of Module GPIOs (17 x 8 bits) gpio_flag my_module_flag; // Active copy of Template GPIO flags StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) @@ -1995,6 +1996,12 @@ void PerformEverySecond(void) { uptime++; + if (ntp_synced_message) { + // Moved here to fix syslog UDP exception 9 during RtcSecond + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + ntp_synced_message = false; + } + if (BOOT_LOOP_TIME == uptime) { RtcReboot.fast_reboot_count = 0; RtcRebootSave(); diff --git a/sonoff/support.ino b/sonoff/support.ino index 0bbd58ffe..ef04075a3 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1503,7 +1503,7 @@ void Syslog(void) memmove(log_data + strlen(syslog_preamble), log_data, sizeof(log_data) - strlen(syslog_preamble)); log_data[sizeof(log_data) -1] = '\0'; memcpy(log_data, syslog_preamble, strlen(syslog_preamble)); - PortUdp.write(log_data); + PortUdp.write(log_data, strlen(log_data)); PortUdp.endPacket(); delay(1); // Add time for UDP handling (#5512) } else { diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino index fd9575b32..03efeb510 100644 --- a/sonoff/support_rtc.ino +++ b/sonoff/support_rtc.ino @@ -365,7 +365,11 @@ void RtcSecond(void) RtcTime.year = tmpTime.year + 1970; daylight_saving_time = RuleToTime(Settings.tflag[1], RtcTime.year); standard_time = RuleToTime(Settings.tflag[0], RtcTime.year); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + + // Do not use AddLog here if syslog is enabled. UDP will force exception 9 +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + ntp_synced_message = true; + if (local_time < 1451602800) { // 2016-01-01 rules_flag.time_init = 1; } else {