Add ability to change MQTT topic and or gateway name by MQTT command. (#1053)

* Add ability to change MQTT topic and or gateway name by MQTT command.

This adds new commands to allow changing the MQTT topic and or gateway name from a command.
The new topic/name will be saved in flash memory and used on subsequent reboots.
Either/both parameters can be sent or combined with other commands.

Example use:
```
mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m
'{
  "mqtt_topic": "topic/",
  "gateway_name: "name"
}'
```

* Update example with /

Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
h2zeroandFlorian authored and GitHub committed 2021-08-05 05:50:16 -05:00
1 parent 702c4b7fea
commit ca616939b8
2 files changed
+24

No files matched your search

+12
View File
@@ -2026,6 +2026,18 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
# endif
}
# endif
if (SYSdata.containsKey("mqtt_topic") || SYSdata.containsKey("gateway_name")) {
if (SYSdata.containsKey("mqtt_topic")) {
strncpy(mqtt_topic, SYSdata["mqtt_topic"], mqtt_topic_max_size);
}
if (SYSdata.containsKey("gateway_name")) {
strncpy(gateway_name, SYSdata["gateway_name"], parameters_size * 2);
}
# ifndef ESPWifiManualSetup
saveMqttConfig();
# endif
client.disconnect(); // reconnects in loop using the new topic/name
}
#endif
#ifdef ZmqttDiscovery