Skip to content

Commit

Permalink
Gateway restart through MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 5, 2023
1 parent f5f3404 commit 282ae46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Main settings:

`<base-topic>/divertmode/set [1 | 2]` : enable (1)/ disable (2) divert mode
`<base-topic>/shaper/set [0 | 1]` : temporary enable (1)/ disable (0) current shaper ( doesn't survive reboot )
`<base-topic>/restart` : restarts the gateway



MQTT setup is pre-populated with OpenEnergyMonitor [emonPi default MQTT server credentials](https://guide.openenergymonitor.org/technical/credentials/#mqtt).
Expand Down
11 changes: 11 additions & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
});

Expand Down

0 comments on commit 282ae46

Please sign in to comment.