diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index b030d63b3..0d0fc91da 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -740,6 +740,8 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } } else if (CMND_GPIOS == command_code) { + mytmplt cmodule; + memcpy_P(&cmodule, &kModules[Settings.module], sizeof(cmodule)); for (byte i = 0; i < GPIO_SENSOR_END; i++) { if (!jsflg) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_GPIOS "%d\":["), lines); @@ -747,12 +749,14 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data); } jsflg = 1; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, i, GetTextIndexed(stemp1, sizeof(stemp1), i, kSensorNames)); - if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == GPIO_SENSOR_END -1)) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data); - MqttPublishPrefixTopic_P(RESULT_OR_STAT, type); - jsflg = 0; - lines++; + if (!GetUsedInModule(i, cmodule.gp.io)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, i, GetTextIndexed(stemp1, sizeof(stemp1), i, kSensorNames)); + if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == GPIO_SENSOR_END -1)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data); + MqttPublishPrefixTopic_P(RESULT_OR_STAT, type); + jsflg = 0; + lines++; + } } } mqtt_data[0] = '\0'; @@ -1000,7 +1004,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) break; case 99: AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); - ESP.restart(); + EspRestart(); break; default: snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_ONE_TO_RESTART); @@ -1937,7 +1941,7 @@ void StateLoop() restart_flag--; if (restart_flag <= 0) { AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); - ESP.restart(); + EspRestart(); } } break; @@ -2012,8 +2016,7 @@ void ArduinoOTAInit() } snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA %s. " D_RESTARTING), error_str); AddLog(LOG_LEVEL_INFO); - delay(100); // Allow time for message xfer - ESP.restart(); + EspRestart(); }); ArduinoOTA.onEnd([]() @@ -2021,8 +2024,7 @@ void ArduinoOTAInit() if ((LOG_LEVEL_DEBUG <= seriallog_level)) Serial.println(); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA " D_SUCCESSFUL ". " D_RESTARTING)); AddLog(LOG_LEVEL_INFO); - delay(100); // Allow time for message xfer - ESP.restart(); + EspRestart(); }); ArduinoOTA.begin(); diff --git a/sonoff/support.ino b/sonoff/support.ino index b9f5e6676..89c80bd44 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -671,7 +671,7 @@ void ShowSource(int source) void GetFeatures() { - feature_drv1 = 0x00000000; // xdrv_00_mqtt.ino, xdrv_01_light.ino, xdrv_04_snfbridge.ino + feature_drv1 = 0x00000000; // xdrv_01_mqtt.ino, xdrv_01_light.ino, xdrv_04_snfbridge.ino // feature_drv1 |= 0x00000001; // feature_drv1 |= 0x00000002; @@ -1033,6 +1033,7 @@ void WifiBegin(uint8_t flag) WiFi.mode(WIFI_OFF); // See https://github.com/esp8266/Arduino/issues/2186 #endif + WiFi.persistent(false); // Solve possible wifi init errors WiFi.disconnect(true); // Delete SDK wifi config delay(200); WiFi.mode(WIFI_STA); // Disable AP mode @@ -1246,13 +1247,30 @@ int WifiState() void WifiConnect() { - WiFi.persistent(false); // Solve possible wifi init errors + WiFi.persistent(false); // Solve possible wifi init errors wifi_status = 0; wifi_retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2); wifi_retry = wifi_retry_init; wifi_counter = 1; } +void WifiDisconnect() +{ + // Courtesy of EspEasy + WiFi.persistent(true); // use SDK storage of SSID/WPA parameters + ETS_UART_INTR_DISABLE(); + wifi_station_disconnect(); // this will store empty ssid/wpa into sdk storage + ETS_UART_INTR_ENABLE(); + WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters +} + +void EspRestart() +{ + delay(100); // Allow time for message xfer + WifiDisconnect(); + ESP.restart(); +} + #ifdef USE_DISCOVERY /*********************************************************************************************\ * mDNS diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 697199491..843067706 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -181,7 +181,7 @@ * - Disable a feature by preceding it with // \*********************************************************************************************/ -//#define USE_ARDUINO_OTA // Add optional support for Arduino OTA (+4k5 code) +//#define USE_ARDUINO_OTA // Add optional support for Arduino OTA (+13k code) // -- Localization -------------------------------- // If non selected the default en-GB will be used