diff --git a/src/mqtt.cpp b/src/mqtt.cpp index cefdadba..a1834cb2 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -289,6 +289,7 @@ mqtt_connect() event_send(doc); // Publish MQTT override/claim + mqtt_publish_config(); mqtt_publish_override(); mqtt_publish_claim(); mqtt_publish_schedule(); @@ -396,6 +397,9 @@ mqtt_publish(JsonDocument &data) { topic += kv.key().c_str(); String val = kv.value().as(); mqttclient.publish(topic, val, config_mqtt_retained()); + if("config_updates" == kv.key().c_str()) { + mqtt_publish_config(); + } topic = mqtt_topic + "/"; } @@ -489,6 +493,53 @@ mqtt_publish_schedule() { } } +void +mqtt_publish_config() { + if(!config_mqtt_enabled() || !mqttclient.connected()) { + return; + } + const size_t capacity = JSON_OBJECT_SIZE(128) + 1024; + DynamicJsonDocument doc(capacity); + + // Read only information + doc["firmware"] = evse.getFirmwareVersion(); + doc["protocol"] = "-"; + doc["espflash"] = ESPAL.getFlashChipSize(); + doc["espinfo"] = ESPAL.getChipInfo(); + doc["buildenv"] = buildenv; + doc["version"] = currentfirmware; + doc["evse_serial"] = evse.getSerial(); + doc["wifi_serial"] = serial; + + // Static supported protocols + JsonArray mqtt_supported_protocols = doc.createNestedArray("mqtt_supported_protocols"); + mqtt_supported_protocols.add("mqtt"); + mqtt_supported_protocols.add("mqtts"); + + JsonArray http_supported_protocols = doc.createNestedArray("http_supported_protocols"); + http_supported_protocols.add("http"); + + // OpenEVSE module config + doc["diode_check"] = evse.isDiodeCheckEnabled(); + doc["gfci_check"] = evse.isGfiTestEnabled(); + doc["ground_check"] = evse.isGroundCheckEnabled(); + doc["relay_check"] = evse.isStuckRelayCheckEnabled(); + doc["vent_check"] = evse.isVentRequiredEnabled(); + doc["temp_check"] = evse.isTemperatureCheckEnabled(); + doc["service"] = static_cast(evse.getServiceLevel()); + doc["scale"] = evse.getCurrentSensorScale(); + doc["offset"] = evse.getCurrentSensorOffset(); + doc["max_current_soft"] = evse.getMaxConfiguredCurrent(); + + doc["min_current_hard"] = evse.getMinCurrent(); + doc["max_current_hard"] = evse.getMaxHardwareCurrent(); + + // WiFi module config + config_serialize(doc, true, false, true); + + mqtt_publish_json(doc, "/config"); +} + void mqtt_publish_json(JsonDocument &data, const char* topic) { Profile_Start(mqtt_publish_json); diff --git a/src/mqtt.h b/src/mqtt.h index 68c9e548..8243a536 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -30,6 +30,7 @@ extern void mqtt_loop(); // data: a comma seperated list of name:value pairs to send // ------------------------------------------------------------------- extern void mqtt_publish(JsonDocument &data); +extern void mqtt_publish_config(); extern void mqtt_publish_claim(); extern void mqtt_set_claim(bool override, EvseProperties &props); extern void mqtt_publish_override();