From ebe17c8899d7c0850729e43c4226472748dc545b Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Wed, 14 Jul 2021 17:25:09 -0500 Subject: [PATCH] Setmqtt setting optional (#1021) * Define MQTTsetMQTT for configuring MQTT over MQTT * Enable MQTTsetMQTT per default on all ESP except RFBridge Co-authored-by: Dave --- docs/use/gateway.md | 11 +++++++++++ main/main.ino | 22 ++++++++++++---------- platformio.ini | 2 ++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/use/gateway.md b/docs/use/gateway.md index b34070b97e..f08b15c9b4 100644 --- a/docs/use/gateway.md +++ b/docs/use/gateway.md @@ -52,6 +52,17 @@ mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m "mqtt_secure": "false" }' ``` +::: info +By default this function is not available on the pre built binary of RFBridge, in order to have less code size and enable to have OTA update working properly. So as to enable it remove from the rf bridge env: +``` +build_flags = '-UMQTTsetMQTT' +``` +Arduino boards does not have this function per default also, to add it: +``` +build_flags = '-DMQTTsetMQTT' +``` +::: + ::: tip Server, port, and secure_flag are only required if changing connection to another broker. If the new connection fails the gateway will fallback to the previous connection. diff --git a/main/main.ino b/main/main.ino index 450238b415..3bf7fdd107 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1897,6 +1897,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding # endif } +# ifdef MQTTsetMQTT if (SYSdata.containsKey("mqtt_user") && SYSdata.containsKey("mqtt_pass")) { bool update_server = false; bool secure_connect = SYSdata.get("mqtt_secure"); @@ -1909,7 +1910,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding Log.error(F("mqtt_server provided without mqtt_secure defined - ignoring command" CR)); return; } -# if MQTT_SECURE_SELF_SIGNED +# if MQTT_SECURE_SELF_SIGNED if (use_ss_cert) { cert_index = SYSdata.get("mqtt_cert_index"); if (cert_index >= sizeof(certs_array) / sizeof(ss_certs)) { @@ -1917,11 +1918,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding return; } } -# endif +# endif -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) stopProcessing(); -# endif +# endif client.disconnect(); update_server = true; if (secure_connect != mqtt_secure) { @@ -1942,9 +1943,9 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding client.setServer(SYSdata.get("mqtt_server"), SYSdata.get("mqtt_port")); } else { -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) stopProcessing(); -# endif +# endif client.disconnect(); } @@ -1965,9 +1966,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) { @@ -1985,10 +1986,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding } connectMQTT(); } -# if defined(ZgatewayBT) && defined(ESP32) +# if defined(ZgatewayBT) && defined(ESP32) startProcessing(); -# endif +# endif } +# endif #endif #ifdef ZmqttDiscovery diff --git a/platformio.ini b/platformio.ini index 94e4319714..b739c06d79 100644 --- a/platformio.ini +++ b/platformio.ini @@ -153,6 +153,7 @@ build_flags = '-DTRACE=1' '-DCONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED' '-DCONFIG_BT_NIMBLE_ROLE_BROADCASTER_DISABLED' + '-DMQTTsetMQTT' ;'-DCORE_DEBUG_LEVEL=4' [com-arduino] @@ -190,6 +191,7 @@ build_flags = '-DLED_INFO=13' '-DLED_INFO_ON=0' '-DGateway_Name="OpenMQTTGateway_SRFB"' + '-UMQTTsetMQTT' ;We remove this function to have sufficient FLASH available for OTA, you should also use ESPWifiManualSetup to save flash memory and have OTA working board_build.flash_mode = dout [env:esp32dev-all-test]