diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index b1417029e..aace62b7d 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,11 +1,14 @@ -/* 6.2.1.19 20181023 +/* 6.2.1.20 20181028 + * Add command SetOption35 0..255 (seconds) to delay mDNS initialization to control possible Wifi connect problems + * + * 6.2.1.19 20181023 * Fix header file execution order by renaming user_config.h to my_user_config.h * Fix invalid JSON floating point result from nan (Not a Number) and inf (Infinity) into null (#4147) * Fix rule mqtt#connected trigger when mqtt is disabled (#4149) * Initial release of RF transceiving using library RcSwitch (#2702) * Change default OTA Url to http://thehackbox.org/tasmota/release/sonoff.bin (#4170) * Add Tuya Software Serial to support additional Tuya configurations (#4178) - * Add sonoff-basic.bin without most sensors + * Add define USE_BASIC for selecting image sonoff-basic without most sensors * * 6.2.1.18 20181019 * Add more API callbacks and document API.md diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 70e0e9a3d..15d003cd1 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -202,7 +202,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MAX_PARAM8}; +enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 153e55fb7..5eadb50a8 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -186,6 +186,7 @@ byte reset_web_log_flag = 0; // Reset web console log byte devices_present = 0; // Max number of devices supported byte seriallog_level; // Current copy of Settings.seriallog_level byte syslog_level; // Current copy of Settings.syslog_level +byte mdns_delayed_start = 0; // mDNS delayed start boolean latest_uptime_flag = true; // Signal latest uptime boolean pwm_present = false; // Any PWM channel configured with SetOption15 0 boolean mdns_begun = false; // mDNS active @@ -2580,6 +2581,7 @@ void setup() } baudrate = Settings.baudrate * 1200; + mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START]; seriallog_level = Settings.seriallog_level; seriallog_timer = SERIALLOG_TIMER; #ifndef USE_EMULATION diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 2c70d6928..4a1b9ac5d 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06020112 +#define VERSION 0x06020114 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index 88545e211..67d55a8ab 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -715,7 +715,6 @@ boolean GetUsedInModule(byte val, uint8_t *arr) if (GPIO_RFRECV == val) { return true; } #endif - if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { offset = (GPIO_REL1_INV - GPIO_REL1); } @@ -1558,19 +1557,29 @@ void WifiCheck(uint8_t param) ota_state_flag = 3; } #endif // BE_MINIMAL + #ifdef USE_DISCOVERY if (!mdns_begun) { - mdns_begun = MDNS.begin(my_hostname); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS "%s"), (mdns_begun) ? D_INITIALIZED : D_FAILED); - AddLog(LOG_LEVEL_INFO); + if (mdns_delayed_start) { + AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MDNS D_ATTEMPTING_CONNECTION)); + mdns_delayed_start--; + } else { + mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START]; + mdns_begun = MDNS.begin(my_hostname); + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS "%s"), (mdns_begun) ? D_INITIALIZED : D_FAILED); + AddLog(LOG_LEVEL_INFO); + } } #endif // USE_DISCOVERY + #ifdef USE_WEBSERVER if (Settings.webserver) { StartWebserver(Settings.webserver, WiFi.localIP()); #ifdef USE_DISCOVERY #ifdef WEBSERVER_ADVERTISE - MDNS.addService("http", "tcp", WEB_PORT); + if (mdns_begun) { + MDNS.addService("http", "tcp", WEB_PORT); + } #endif // WEBSERVER_ADVERTISE #endif // USE_DISCOVERY } else { @@ -1580,12 +1589,14 @@ void WifiCheck(uint8_t param) if (Settings.flag2.emulation) { UdpConnect(); } #endif // USE_EMULATION #endif // USE_WEBSERVER + #ifdef USE_KNX if (!knx_started && Settings.flag.knx_enabled) { KNXStart(); knx_started = true; } #endif // USE_KNX + } else { WifiState(0); #if defined(USE_WEBSERVER) && defined(USE_EMULATION) @@ -1646,38 +1657,6 @@ void EspRestart() ESP.restart(); } -#ifdef USE_DISCOVERY -/*********************************************************************************************\ - * mDNS -\*********************************************************************************************/ - -#ifdef MQTT_HOST_DISCOVERY -boolean MdnsDiscoverMqttServer() -{ - if (!mdns_begun) { - return false; - } - - int n = MDNS.queryService("mqtt", "tcp"); // Search for mqtt service - - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_QUERY_DONE " %d"), n); - AddLog(LOG_LEVEL_INFO); - - if (n > 0) { - // Note: current strategy is to get the first MQTT service (even when many are found) - snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str()); - Settings.mqtt_port = MDNS.port(0); - - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"), - MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port); - AddLog(LOG_LEVEL_INFO); - } - - return n > 0; -} -#endif // MQTT_HOST_DISCOVERY -#endif // USE_DISCOVERY - /*********************************************************************************************\ * Basic I2C routines \*********************************************************************************************/ diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index bb1a86e13..ed24d31ed 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -197,6 +197,32 @@ void MqttLoop() /*********************************************************************************************/ +#ifdef USE_DISCOVERY +#ifdef MQTT_HOST_DISCOVERY +boolean MqttDiscoverServer() +{ + if (!mdns_begun) { return false; } + + int n = MDNS.queryService("mqtt", "tcp"); // Search for mqtt service + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_QUERY_DONE " %d"), n); + AddLog(LOG_LEVEL_INFO); + + if (n > 0) { + // Note: current strategy is to get the first MQTT service (even when many are found) + snprintf_P(Settings.mqtt_host, sizeof(Settings.mqtt_host), MDNS.IP(0).toString().c_str()); + Settings.mqtt_port = MDNS.port(0); + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS D_MQTT_SERVICE_FOUND " %s, " D_IP_ADDRESS " %s, " D_PORT " %d"), + MDNS.hostname(0).c_str(), Settings.mqtt_host, Settings.mqtt_port); + AddLog(LOG_LEVEL_INFO); + } + + return n > 0; +} +#endif // MQTT_HOST_DISCOVERY +#endif // USE_DISCOVERY + int MqttLibraryType() { return (int)MQTT_LIBRARY_TYPE; @@ -468,9 +494,7 @@ void MqttReconnect() #ifndef USE_MQTT_TLS #ifdef USE_DISCOVERY #ifdef MQTT_HOST_DISCOVERY - if (!strlen(Settings.mqtt_host)) { - MdnsDiscoverMqttServer(); - } + if (!strlen(Settings.mqtt_host) && !MqttDiscoverServer()) { return; } #endif // MQTT_HOST_DISCOVERY #endif // USE_DISCOVERY #endif // USE_MQTT_TLS @@ -539,6 +563,13 @@ void MqttCheck() if (!MqttIsConnected()) { global_state.mqtt_down = 1; if (!mqtt_retry_counter) { +#ifndef USE_MQTT_TLS +#ifdef USE_DISCOVERY +#ifdef MQTT_HOST_DISCOVERY + if (!strlen(Settings.mqtt_host) && !mdns_begun) { return; } +#endif // MQTT_HOST_DISCOVERY +#endif // USE_DISCOVERY +#endif // USE_MQTT_TLS MqttReconnect(); } else { mqtt_retry_counter--; diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index f8eff5ddc..8bd5e529c 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -809,6 +809,11 @@ void HandleHueApi(String *path) * user part and allow every caller as with Web or WeMo. * * (c) Heiko Krupp, 2017 + * + * Hue URL + * http://sonoff/api/username/lights/1/state with post data {"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40} + * is converted by webserver to + * http://sonoff/api/username/lights/1/state with arg plain={"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40} */ uint8_t args = 0;