From 8af3b17ead8e9ff5ca67e58d254ccc5b4938c7a5 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 3 May 2023 12:25:02 +0200 Subject: [PATCH] Gateway restart through MQTT --- docs/mqtt.md | 2 ++ src/mqtt.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/mqtt.md b/docs/mqtt.md index 3f386c96..ea99d79c 100644 --- a/docs/mqtt.md +++ b/docs/mqtt.md @@ -48,6 +48,8 @@ Main settings: `/divertmode/set [1 | 2]` : enable (1)/ disable (2) divert mode `/shaper/set [0 | 1]` : temporary enable (1)/ disable (0) current shaper ( doesn't survive reboot ) +`/restart` : restarts the gateway + MQTT setup is pre-populated with OpenEnergyMonitor [emonPi default MQTT server credentials](https://guide.openenergymonitor.org/technical/credentials/#mqtt). diff --git a/src/mqtt.cpp b/src/mqtt.cpp index c679eab6..cefdadba 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -183,6 +183,11 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) { mqtt_clear_schedule(payload_str.toInt()); } + // Restart + else if (topic_string == mqtt_topic + "/restart") { + restart_system(); + } + else { // If MQTT message is RAPI command @@ -360,6 +365,12 @@ mqtt_connect() mqtt_sub_topic = mqtt_topic + "/schedule/clear"; mqttclient.subscribe(mqtt_sub_topic); yield(); + + // ask for a system restart + mqtt_sub_topic = mqtt_topic + "/restart"; + mqttclient.subscribe(mqtt_sub_topic); + yield(); + connecting = false; });