6.2.1.20 Add mDNS delay option

6.2.1.20 20181028
 * Add command SetOption35 0..255 (seconds) to delay mDNS initialization to control possible Wifi connect problems
This commit is contained in:
Theo Arends 2018-10-28 17:57:25 +01:00
parent 6119c43610
commit 5c78561b07
6 changed files with 59 additions and 44 deletions

View File

@ -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 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 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) * Fix rule mqtt#connected trigger when mqtt is disabled (#4149)
* Initial release of RF transceiving using library RcSwitch (#2702) * Initial release of RF transceiving using library RcSwitch (#2702)
* Change default OTA Url to http://thehackbox.org/tasmota/release/sonoff.bin (#4170) * Change default OTA Url to http://thehackbox.org/tasmota/release/sonoff.bin (#4170)
* Add Tuya Software Serial to support additional Tuya configurations (#4178) * 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 * 6.2.1.18 20181019
* Add more API callbacks and document API.md * Add more API callbacks and document API.md

View File

@ -202,7 +202,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED };
enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; 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}; 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};

View File

@ -186,6 +186,7 @@ byte reset_web_log_flag = 0; // Reset web console log
byte devices_present = 0; // Max number of devices supported byte devices_present = 0; // Max number of devices supported
byte seriallog_level; // Current copy of Settings.seriallog_level byte seriallog_level; // Current copy of Settings.seriallog_level
byte syslog_level; // Current copy of Settings.syslog_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 latest_uptime_flag = true; // Signal latest uptime
boolean pwm_present = false; // Any PWM channel configured with SetOption15 0 boolean pwm_present = false; // Any PWM channel configured with SetOption15 0
boolean mdns_begun = false; // mDNS active boolean mdns_begun = false; // mDNS active
@ -2580,6 +2581,7 @@ void setup()
} }
baudrate = Settings.baudrate * 1200; baudrate = Settings.baudrate * 1200;
mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START];
seriallog_level = Settings.seriallog_level; seriallog_level = Settings.seriallog_level;
seriallog_timer = SERIALLOG_TIMER; seriallog_timer = SERIALLOG_TIMER;
#ifndef USE_EMULATION #ifndef USE_EMULATION

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_ #ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_
#define VERSION 0x06020113 #define VERSION 0x06020114
#define D_PROGRAMNAME "Sonoff-Tasmota" #define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends" #define D_AUTHOR "Theo Arends"

View File

@ -715,7 +715,6 @@ boolean GetUsedInModule(byte val, uint8_t *arr)
if (GPIO_RFRECV == val) { return true; } if (GPIO_RFRECV == val) { return true; }
#endif #endif
if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) {
offset = (GPIO_REL1_INV - GPIO_REL1); offset = (GPIO_REL1_INV - GPIO_REL1);
} }
@ -1558,19 +1557,29 @@ void WifiCheck(uint8_t param)
ota_state_flag = 3; ota_state_flag = 3;
} }
#endif // BE_MINIMAL #endif // BE_MINIMAL
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
if (!mdns_begun) { if (!mdns_begun) {
mdns_begun = MDNS.begin(my_hostname); if (mdns_delayed_start) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_MDNS "%s"), (mdns_begun) ? D_INITIALIZED : D_FAILED); AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MDNS D_ATTEMPTING_CONNECTION));
AddLog(LOG_LEVEL_INFO); 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 #endif // USE_DISCOVERY
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
if (Settings.webserver) { if (Settings.webserver) {
StartWebserver(Settings.webserver, WiFi.localIP()); StartWebserver(Settings.webserver, WiFi.localIP());
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
#ifdef WEBSERVER_ADVERTISE #ifdef WEBSERVER_ADVERTISE
MDNS.addService("http", "tcp", WEB_PORT); if (mdns_begun) {
MDNS.addService("http", "tcp", WEB_PORT);
}
#endif // WEBSERVER_ADVERTISE #endif // WEBSERVER_ADVERTISE
#endif // USE_DISCOVERY #endif // USE_DISCOVERY
} else { } else {
@ -1580,12 +1589,14 @@ void WifiCheck(uint8_t param)
if (Settings.flag2.emulation) { UdpConnect(); } if (Settings.flag2.emulation) { UdpConnect(); }
#endif // USE_EMULATION #endif // USE_EMULATION
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
#ifdef USE_KNX #ifdef USE_KNX
if (!knx_started && Settings.flag.knx_enabled) { if (!knx_started && Settings.flag.knx_enabled) {
KNXStart(); KNXStart();
knx_started = true; knx_started = true;
} }
#endif // USE_KNX #endif // USE_KNX
} else { } else {
WifiState(0); WifiState(0);
#if defined(USE_WEBSERVER) && defined(USE_EMULATION) #if defined(USE_WEBSERVER) && defined(USE_EMULATION)
@ -1646,38 +1657,6 @@ void EspRestart()
ESP.restart(); 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 * Basic I2C routines
\*********************************************************************************************/ \*********************************************************************************************/

View File

@ -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() int MqttLibraryType()
{ {
return (int)MQTT_LIBRARY_TYPE; return (int)MQTT_LIBRARY_TYPE;
@ -468,9 +494,7 @@ void MqttReconnect()
#ifndef USE_MQTT_TLS #ifndef USE_MQTT_TLS
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
#ifdef MQTT_HOST_DISCOVERY #ifdef MQTT_HOST_DISCOVERY
if (!strlen(Settings.mqtt_host)) { if (!strlen(Settings.mqtt_host) && !MqttDiscoverServer()) { return; }
MdnsDiscoverMqttServer();
}
#endif // MQTT_HOST_DISCOVERY #endif // MQTT_HOST_DISCOVERY
#endif // USE_DISCOVERY #endif // USE_DISCOVERY
#endif // USE_MQTT_TLS #endif // USE_MQTT_TLS
@ -539,6 +563,13 @@ void MqttCheck()
if (!MqttIsConnected()) { if (!MqttIsConnected()) {
global_state.mqtt_down = 1; global_state.mqtt_down = 1;
if (!mqtt_retry_counter) { 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(); MqttReconnect();
} else { } else {
mqtt_retry_counter--; mqtt_retry_counter--;