Skip to content

Commit

Permalink
Expose get/set max_current_soft through MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 3, 2023
1 parent 0cd8d93 commit 6677f13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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_soft"] = evse.getMaxConfiguredCurrent();
if(evse.isTemperatureValid(EVSE_MONITOR_TEMP_MONITOR)) {
doc["temp"] = evse.getTemperature(EVSE_MONITOR_TEMP_MONITOR) * TEMP_SCALE_FACTOR;
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
restart_system();
}

// max_current_soft
else if (topic_string == mqtt_topic + "/max_current_soft/set") {
long current = payload_str.toInt();
if(current != evse.getMaxConfiguredCurrent()) {
evse.setMaxConfiguredCurrent(current);
DBUGLN("max_current_soft changed");
DBUG("Flushing RAPI command queue ...");
rapiSender.flush();
DBUGLN(" Done");
StaticJsonDocument<256> event;
event["max_current_soft"] = evse.getMaxConfiguredCurrent();
event_send(event);
}
}

else
{
// If MQTT message is RAPI command
Expand Down Expand Up @@ -371,6 +386,11 @@ mqtt_connect()
mqttclient.subscribe(mqtt_sub_topic);
yield();

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

connecting = false;
});

Expand Down
1 change: 1 addition & 0 deletions src/web_server_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void handleEventLogs(MongooseHttpServerRequest *request)
event["evseState"] = evseState;
event["evseFlags"] = evseFlags;
event["pilot"] = pilot;
event["max_current_soft"] = evse.getMaxConfiguredCurrent();
event["energy"] = energy;
event["elapsed"] = elapsed;
event["temperature"] = temperature;
Expand Down

0 comments on commit 6677f13

Please sign in to comment.