Skip to content

Commit

Permalink
/config/set
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Aug 17, 2023
1 parent 84b6794 commit 5bedec6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
}
}

else if (topic_string == mqtt_topic + "/config/set") {
const size_t capacity = JSON_OBJECT_SIZE(128) + 1024;
DynamicJsonDocument doc(capacity);
DeserializationError error = deserializeJson(doc, payload_str);
if(!error)
{
bool config_modified = config_deserialize(doc);
if(config_modified)
{
config_commit(false);
DBUGLN("Config updated");
}
}
}

// Restart
else if (topic_string == mqtt_topic + "/restart") {
mqtt_restart_device(payload_str);
Expand Down Expand Up @@ -386,6 +401,10 @@ mqtt_connect()
mqttclient.subscribe(mqtt_sub_topic);
yield();

mqtt_sub_topic = mqtt_topic + "/config/set";
mqttclient.subscribe(mqtt_sub_topic);
yield();

// ask for a system restart
mqtt_sub_topic = mqtt_topic + "/restart";
mqttclient.subscribe(mqtt_sub_topic);
Expand Down

0 comments on commit 5bedec6

Please sign in to comment.