diff --git a/src/MyESP.cpp b/src/MyESP.cpp index 9ca191110..db5428c69 100644 --- a/src/MyESP.cpp +++ b/src/MyESP.cpp @@ -597,15 +597,8 @@ void MyESP::_mqttOnConnect() { _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN; _mqtt_last_connection = millis(); - // say we're alive to the Last Will topic - // send online appended with the version information as JSON - const size_t capacity = JSON_OBJECT_SIZE(3); - StaticJsonDocument doc; - JsonObject payload = doc.to(); - payload["status"] = _mqtt_will_online_payload; - payload["version"] = _app_version; - payload["IP"] = WiFi.localIP().toString(); - mqttPublish(_mqtt_will_topic, doc, true); // force retain on + // say we're alive to the Last Will topic, with retain on + mqttPublish(_mqtt_will_topic, _mqtt_will_online_payload, true); // subscribe to general subs mqttSubscribe(MQTT_TOPIC_RESTART); @@ -613,7 +606,20 @@ void MyESP::_mqttOnConnect() { // subscribe to a start message and send the first publish // forcing retain to off since we only want to send this once mqttSubscribe(MQTT_TOPIC_START); - mqttPublish(MQTT_TOPIC_START, MQTT_TOPIC_START_PAYLOAD, false); + + // send online appended with the version information as JSON + StaticJsonDocument doc; + JsonObject payload = doc.to(); + payload["version"] = _app_version; + payload["IP"] = WiFi.localIP().toString(); + // add time if we know it + if ((_ntp_enabled) && (NTP.tcr->abbrev != nullptr)) { + uint32_t real_time = getSystemTime(); + char s[30]; + snprintf_P(s, 30, PSTR("%02d:%02d:%02d %s"), to_hour(real_time), to_minute(real_time), to_second(real_time), NTP.tcr->abbrev); + payload["boottime"] = s; + } + mqttPublish(MQTT_TOPIC_START, doc, false); // send heartbeat if enabled heartbeatCheck(true); diff --git a/src/MyESP.h b/src/MyESP.h index aa50c097f..51729e17c 100644 --- a/src/MyESP.h +++ b/src/MyESP.h @@ -9,7 +9,7 @@ #ifndef MyESP_h #define MyESP_h -#define MYESP_VERSION "1.2.34" +#define MYESP_VERSION "1.2.35" #include #include @@ -86,7 +86,6 @@ extern struct rst_info resetInfo; #define MQTT_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most #define MQTT_TOPIC_START "start" #define MQTT_TOPIC_HEARTBEAT "heartbeat" -#define MQTT_TOPIC_START_PAYLOAD "start" #define MQTT_TOPIC_RESTART "restart" #define MQTT_WILL_ONLINE_PAYLOAD "online" // for last will & testament payload #define MQTT_WILL_OFFLINE_PAYLOAD "offline" // for last will & testament payload diff --git a/src/version.h b/src/version.h index 4036f5327..bdc83bbf2 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define APP_VERSION "1.9.5b50" +#define APP_VERSION "1.9.5b51"