Setmqtt setting optional (#1021)
* Define MQTTsetMQTT for configuring MQTT over MQTT * Enable MQTTsetMQTT per default on all ESP except RFBridge Co-authored-by: Dave <d.kneisz@gmail.com>
This commit is contained in:
1 parent
c44ab5aeb9
commit
ebe17c8899
3 files changed
+25
-10
No files matched your search
@@ -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.
|
||||
|
||||
+12
-10
@@ -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<bool>("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<uint8_t>("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<const char*>("mqtt_server"), SYSdata.get<unsigned int>("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
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user