start topic show datetime #347 #348

This commit is contained in:
Paul
2020-03-12 14:35:08 +01:00
parent f5f2791bcf
commit 9321b53e40
5 changed files with 46 additions and 21 deletions

View File

@@ -590,6 +590,36 @@ void MyESP::_mqttPublishQueue() {
_mqttRemoveLastPublish();
}
// send online appended with the version information as JSON
void MyESP::_sendStartTopic() {
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();
// exclude millis() just in case
if (real_time > 10000L) {
char s[25];
// ISO 8601 describes an internationally accepted way to represent dates and times using numbers
snprintf_P(s,
25,
PSTR("%04u-%02u-%02uT%02u:%02u:%02u"),
to_year(real_time),
to_month(real_time),
to_day(real_time),
to_hour(real_time),
to_minute(real_time),
to_second(real_time)
);
payload["boottime"] = s;
}
}
mqttPublish(MQTT_TOPIC_START, doc, true); // send with retain on
}
// MQTT onConnect - when a connect is established
void MyESP::_mqttOnConnect() {
myDebug_P(PSTR("[MQTT] MQTT connected"));
@@ -607,19 +637,10 @@ void MyESP::_mqttOnConnect() {
// forcing retain to off since we only want to send this once
mqttSubscribe(MQTT_TOPIC_START);
// 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;
// send start topic now unless NTP is enabled, otherwise wait for the time
if (!_ntp_enabled) {
_sendStartTopic();
}
mqttPublish(MQTT_TOPIC_START, doc, false);
// send heartbeat if enabled
heartbeatCheck(true);
@@ -2868,9 +2889,11 @@ void MyESP::_bootupSequence() {
// check if its booted
if (boot_status == MYESP_BOOTSTATUS_BOOTED) {
if ((_ntp_enabled) && (now() > 10000) && !_have_ntp_time) {
if ((_ntp_enabled) && (now() > 10000L) && !_have_ntp_time) {
_have_ntp_time = true;
writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
// send start topic
_sendStartTopic();
}
return;
}

View File

@@ -9,7 +9,7 @@
#ifndef MyESP_h
#define MyESP_h
#define MYESP_VERSION "1.2.35"
#define MYESP_VERSION "1.2.36"
#include <ArduinoJson.h>
#include <ArduinoOTA.h>
@@ -347,6 +347,7 @@ class MyESP {
void _printMQTTQueue();
void _mqttPublishQueue();
void _mqttRemoveLastPublish();
void _sendStartTopic();
AsyncMqttClient mqttClient; // the MQTT class
uint32_t _mqtt_reconnect_delay;
mqtt_callback_f _mqtt_callback_f;

View File

@@ -798,8 +798,8 @@ bool publishEMSValues_boiler() {
// last_boilerActive stores heating in bit 1 and tap water in bit 2
static uint8_t last_boilerActive = 0xFF; // for remembering last setting of the tap water or heating on/off
if (last_boilerActive != ((EMS_Boiler.tapwaterActive << 1) + EMS_Boiler.heatingActive)) {
myESP.mqttPublish(TOPIC_BOILER_TAPWATER_ACTIVE, EMS_Boiler.tapwaterActive == 1 ? "1" : "0");
myESP.mqttPublish(TOPIC_BOILER_HEATING_ACTIVE, EMS_Boiler.heatingActive == 1 ? "1" : "0");
myESP.mqttPublish(TOPIC_BOILER_TAPWATER_ACTIVE, EMS_Boiler.tapwaterActive ? "1" : "0");
myESP.mqttPublish(TOPIC_BOILER_HEATING_ACTIVE, EMS_Boiler.heatingActive ? "1" : "0");
last_boilerActive = ((EMS_Boiler.tapwaterActive << 1) + EMS_Boiler.heatingActive); // remember last state
}
@@ -1908,9 +1908,9 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
// wwOneTime
if (strcmp(topic, TOPIC_BOILER_CMD_WWONETIME) == 0) {
if (message[0] == '1' || strcmp(message, "on") == 0) {
if (message[0] == MYESP_MQTT_PAYLOAD_ON || strcmp(message, "on") == 0) {
ems_setWarmWaterOnetime(true);
} else if (message[0] == '0' || strcmp(message, "off") == 0) {
} else if (message[0] == MYESP_MQTT_PAYLOAD_OFF || strcmp(message, "off") == 0) {
ems_setWarmWaterOnetime(false);
}
return;
@@ -1918,9 +1918,9 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
// wwCirculation
if (strcmp(topic, TOPIC_BOILER_CMD_WWCIRCULATION) == 0) {
if (message[0] == '1' || strcmp(message, "on") == 0) {
if (message[0] == MYESP_MQTT_PAYLOAD_ON || strcmp(message, "on") == 0) {
ems_setWarmWaterCirculation(true);
} else if (message[0] == '0' || strcmp(message, "off") == 0) {
} else if (message[0] == MYESP_MQTT_PAYLOAD_OFF || strcmp(message, "off") == 0) {
ems_setWarmWaterCirculation(false);
}
return;

View File

@@ -953,6 +953,7 @@ void _checkActive() {
if (EMS_Boiler.selFlowTemp != EMS_VALUE_INT_NOTSET && EMS_Boiler.burnGas != EMS_VALUE_INT_NOTSET) {
EMS_Boiler.heatingActive = ((EMS_Boiler.selFlowTemp >= EMS_BOILER_SELFLOWTEMP_HEATING) && (EMS_Boiler.burnGas == EMS_VALUE_BOOL_ON));
}
}
/**

View File

@@ -1 +1 @@
#define APP_VERSION "1.9.5b54"
#define APP_VERSION "1.9.5b55"