diff --git a/docs/use/gateway.md b/docs/use/gateway.md index 46c4495a99..43b80bd0af 100644 --- a/docs/use/gateway.md +++ b/docs/use/gateway.md @@ -41,6 +41,11 @@ Auto discovery is enable by default on release binaries, on platformio (except f If the new connection fails the gateway will fallback to the previous connection. ::: +Define 'MQTTsetWIFI' to activate this +``` +build_flags = '-DMQTTsetWIFI' +``` + ## Change the MQTT broker credentials ``` mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m @@ -57,6 +62,10 @@ Server, port, and secure_flag are only required if changing connection to anothe If the new connection fails the gateway will fallback to the previous connection. ::: +Define 'MQTTsetMQTT' to activate this +``` +build_flags = '-DMQTTsetMQTT' +``` # Firmware update from MQTT (ESP only) diff --git a/main/main.ino b/main/main.ino index d5d9e92872..9d8a745d38 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1798,10 +1798,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding } } +# ifdef MQTTsetWIFI if (SYSdata.containsKey("wifi_ssid") && SYSdata.containsKey("wifi_pass")) { -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) stopProcessing(); -# endif +# endif String prev_ssid = WiFi.SSID(); String prev_pass = WiFi.psk(); client.disconnect(); @@ -1816,22 +1817,24 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding WiFi.disconnect(true); WiFi.begin(prev_ssid.c_str(), prev_pass.c_str()); if (WiFi.waitForConnectResult() != WL_CONNECTED) { -# if defined(ESP8266) +# if defined(ESP8266) ESP.reset(); -# else +# else ESP.restart(); -# endif +# endif } } -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) startProcessing(); -# endif +# endif } +# endif +# ifdef MQTTsetMQTT if (SYSdata.containsKey("mqtt_user") && SYSdata.containsKey("mqtt_pass")) { -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) stopProcessing(); -# endif +# endif client.disconnect(); bool update_server = false; void* prev_client = nullptr; @@ -1875,9 +1878,9 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding delete prev_client; } } -# ifndef ESPWifiManualSetup +# ifndef ESPWifiManualSetup saveMqttConfig(); -# endif +# endif } else { if (update_server) { if (prev_client != nullptr) { @@ -1892,10 +1895,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding strcpy(mqtt_pass, prev_pass.c_str()); connectMQTT(); } -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) startProcessing(); -# endif +# endif } +# endif #endif #ifdef ZmqttDiscovery