Skip to content

Commit

Permalink
Merge pull request #620 from mathieucarbou/restart
Browse files Browse the repository at this point in the history
Expose restart and max_current through mqtt
  • Loading branch information
KipK authored May 7, 2023
2 parents 290528a + 383cf8d commit 40c7ee1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion src/divert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
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 40c7ee1

Please sign in to comment.