diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d6b3ae0e5..c228c4e6d 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.12.0b +/* 5.12.0c + * Fix intermittent exception when dns lookup is used while sleep is enabled + * + * 5.12.0b * Add serial debug info * Add Multichannel Gas sensor using MultiChannel_Gas_Sensor library (#1245) * Add optional usage of %d or %X suffices in MQTT client to append chipid (#1871) @@ -19,7 +22,7 @@ * 5.12.0a * Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image * Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850) - * Change default paremeters in user_config.h to undefined for easy installation (#1851) + * Change default parameters in user_config.h to undefined for easy installation (#1851) * Change max user configurable hold time from 10 to 25 seconds (#1851) * * 5.12.0 20180209 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 1f2a524d9..f0ba58af8 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C0002 // 5.12.0b +#define VERSION 0x050C0003 // 5.12.0c // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/support.ino b/sonoff/support.ino index a086f1207..f8c706a31 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -17,8 +17,8 @@ along with this program. If not, see . */ -IPAddress syslog_host_addr; // Syslog host IP address -unsigned long syslog_host_refresh = 0; +IPAddress syslog_host_addr; // Syslog host IP address +uint32_t syslog_host_hash = 0; // Syslog host name hash /*********************************************************************************************\ * Watchdog extension (https://github.com/esp8266/Arduino/issues/1532) @@ -414,6 +414,15 @@ void SetSerialBaudrate(int baudrate) } } +uint32_t GetHash(const char *buffer, size_t size) +{ + uint32_t hash = 0; + for (uint16_t i = 0; i <= size; i++) { + hash += (uint8_t)*buffer++ * (i +1); + } + return hash; +} + /*********************************************************************************************\ * Wifi \*********************************************************************************************/ @@ -1245,7 +1254,7 @@ void RtcSecond() uint32_t dstoffset; TIME_T tmpTime; - if ((ntp_sync_minute > 59) && (3 == RtcTime.minute)) ntp_sync_minute = 1; // If sync prepare for a new cycle + if ((ntp_sync_minute > 59) && (RtcTime.minute > 2)) ntp_sync_minute = 1; // If sync prepare for a new cycle uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP.getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id if ((WL_CONNECTED == WiFi.status()) && (offset == RtcTime.second) && ((RtcTime.year < 2016) || (ntp_sync_minute == RtcTime.minute))) { ntp_time = sntp_get_current_timestamp(); @@ -1396,9 +1405,9 @@ void Syslog() // Destroys log_data char syslog_preamble[64]; // Hostname + Id - if ((static_cast(syslog_host_addr) == 0) || ((millis() - syslog_host_refresh) > 60000)) { - WiFi.hostByName(Settings.syslog_host, syslog_host_addr); - syslog_host_refresh = millis(); + if (syslog_host_hash != GetHash(Settings.syslog_host, strlen(Settings.syslog_host))) { + syslog_host_hash = GetHash(Settings.syslog_host, strlen(Settings.syslog_host)); + WiFi.hostByName(Settings.syslog_host, syslog_host_addr); // If sleep enabled this might result in exception so try to do it once using hash } if (PortUdp.beginPacket(syslog_host_addr, Settings.syslog_port)) { snprintf_P(syslog_preamble, sizeof(syslog_preamble), PSTR("%s ESP-"), my_hostname);