mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
use MQTT start topic to show version & IP & boottime - #342
This commit is contained in:
@@ -597,15 +597,8 @@ void MyESP::_mqttOnConnect() {
|
|||||||
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
|
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
|
||||||
_mqtt_last_connection = millis();
|
_mqtt_last_connection = millis();
|
||||||
|
|
||||||
// say we're alive to the Last Will topic
|
// say we're alive to the Last Will topic, with retain on
|
||||||
// send online appended with the version information as JSON
|
mqttPublish(_mqtt_will_topic, _mqtt_will_online_payload, true);
|
||||||
const size_t capacity = JSON_OBJECT_SIZE(3);
|
|
||||||
StaticJsonDocument<capacity> doc;
|
|
||||||
JsonObject payload = doc.to<JsonObject>();
|
|
||||||
payload["status"] = _mqtt_will_online_payload;
|
|
||||||
payload["version"] = _app_version;
|
|
||||||
payload["IP"] = WiFi.localIP().toString();
|
|
||||||
mqttPublish(_mqtt_will_topic, doc, true); // force retain on
|
|
||||||
|
|
||||||
// subscribe to general subs
|
// subscribe to general subs
|
||||||
mqttSubscribe(MQTT_TOPIC_RESTART);
|
mqttSubscribe(MQTT_TOPIC_RESTART);
|
||||||
@@ -613,7 +606,20 @@ void MyESP::_mqttOnConnect() {
|
|||||||
// subscribe to a start message and send the first publish
|
// subscribe to a start message and send the first publish
|
||||||
// forcing retain to off since we only want to send this once
|
// forcing retain to off since we only want to send this once
|
||||||
mqttSubscribe(MQTT_TOPIC_START);
|
mqttSubscribe(MQTT_TOPIC_START);
|
||||||
mqttPublish(MQTT_TOPIC_START, MQTT_TOPIC_START_PAYLOAD, false);
|
|
||||||
|
// send online appended with the version information as JSON
|
||||||
|
StaticJsonDocument<MYESP_JSON_MAXSIZE_SMALL> doc;
|
||||||
|
JsonObject payload = doc.to<JsonObject>();
|
||||||
|
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
|
// send heartbeat if enabled
|
||||||
heartbeatCheck(true);
|
heartbeatCheck(true);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef MyESP_h
|
#ifndef MyESP_h
|
||||||
#define MyESP_h
|
#define MyESP_h
|
||||||
|
|
||||||
#define MYESP_VERSION "1.2.34"
|
#define MYESP_VERSION "1.2.35"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@@ -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_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most
|
||||||
#define MQTT_TOPIC_START "start"
|
#define MQTT_TOPIC_START "start"
|
||||||
#define MQTT_TOPIC_HEARTBEAT "heartbeat"
|
#define MQTT_TOPIC_HEARTBEAT "heartbeat"
|
||||||
#define MQTT_TOPIC_START_PAYLOAD "start"
|
|
||||||
#define MQTT_TOPIC_RESTART "restart"
|
#define MQTT_TOPIC_RESTART "restart"
|
||||||
#define MQTT_WILL_ONLINE_PAYLOAD "online" // for last will & testament payload
|
#define MQTT_WILL_ONLINE_PAYLOAD "online" // for last will & testament payload
|
||||||
#define MQTT_WILL_OFFLINE_PAYLOAD "offline" // for last will & testament payload
|
#define MQTT_WILL_OFFLINE_PAYLOAD "offline" // for last will & testament payload
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define APP_VERSION "1.9.5b50"
|
#define APP_VERSION "1.9.5b51"
|
||||||
|
|||||||
Reference in New Issue
Block a user