From 8af3b17ead8e9ff5ca67e58d254ccc5b4938c7a5 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 3 May 2023 12:25:02 +0200 Subject: [PATCH 1/3] 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; }); From 55e96672f7b5c431ab35e2df2f2870bbff60bf15 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Fri, 5 May 2023 16:44:40 +0200 Subject: [PATCH 2/3] Expose max_current through MQTT --- src/input.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/input.cpp b/src/input.cpp index 5b3530fc..9dfb90c3 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -73,6 +73,7 @@ class InputTask : public MicroTasks::Task event["vehicle"] = evse.isVehicleConnected() ? 1 : 0; event["colour"] = evse.getStateColour(); event["pilot"] = evse.getChargeCurrent(); + event["max_current"] = evse.getMaxCurrent(); event["manual_override"] = manual.isActive() ? 1 : 0; //TODO: remove this event["status"] = evse.getState().toString(); event["elapsed"] = evse.getSessionElapsed(); @@ -104,6 +105,7 @@ void create_rapi_json(JsonDocument &doc) doc["voltage"] = evse.getVoltage() * VOLTS_SCALE_FACTOR; doc["power"] = evse.getPower() * POWER_SCALE_FACTOR; doc["pilot"] = evse.getChargeCurrent(); + doc["max_current"] = evse.getMaxCurrent(); if(evse.isTemperatureValid(EVSE_MONITOR_TEMP_MONITOR)) { doc["temp"] = evse.getTemperature(EVSE_MONITOR_TEMP_MONITOR) * TEMP_SCALE_FACTOR; } else { From 383cf8dfdbb0634f12992236c1ac4619bc13b8b7 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Fri, 5 May 2023 21:36:38 +0200 Subject: [PATCH 3/3] Fix "divert_active" topic which was no updated first time with the current value --- src/divert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/divert.cpp b/src/divert.cpp index f8b24fd5..38ce147e 100644 --- a/src/divert.cpp +++ b/src/divert.cpp @@ -245,10 +245,10 @@ void DivertTask::update_state() if(_state != current_evse_state) { _state = current_evse_state; - event["divert_active"] = isActive(); } } + event["divert_active"] = isActive(); event["charge_rate"] = _charge_rate; event["trigger_current"] = trigger_current; event["voltage"] = voltage;