heartbeat added
This commit is contained in:
@ -67,9 +67,11 @@ void loopApplication() {
|
||||
}
|
||||
|
||||
static uint32_t totalCnt = 0;
|
||||
static uint32_t lastMillis = 0;
|
||||
if (currentMillis > (lastMillis + (configBlock.valuesPeriod * 1000))) {
|
||||
lastMillis = currentMillis;
|
||||
static uint32_t lastValuesMillis = 0;
|
||||
static uint32_t lastHeartbeatMillis = 0;
|
||||
char buf[VALUES_BUF_SIZE];
|
||||
if (currentMillis > (lastValuesMillis + (configBlock.valuesPeriod * 1000))) {
|
||||
lastValuesMillis = currentMillis;
|
||||
|
||||
// rain sensor
|
||||
uint32_t rainCnt = 0;
|
||||
@ -84,12 +86,25 @@ void loopApplication() {
|
||||
totalCnt += rainCnt;
|
||||
|
||||
// MQTT publishing
|
||||
#define BUF_SIZE 256
|
||||
char buf[BUF_SIZE];
|
||||
snprintf(buf, BUF_SIZE-1, "{\"raincnt\":%ld, \"totalCnt\":%ld, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
||||
memset(buf, 0, VALUES_BUF_SIZE);
|
||||
snprintf(buf, VALUES_BUF_SIZE-1, "{\"raincnt\":%ld, \"totalCnt\":%ld, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
||||
mqttClient.publish(configBlock.mqttValuesTopic, buf);
|
||||
}
|
||||
|
||||
if (currentMillis > (lastHeartbeatMillis + (configBlock.heartbeatPeriod * 1000))) {
|
||||
lastHeartbeatMillis = currentMillis;
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("Publishing heartbeat");
|
||||
#endif
|
||||
|
||||
// MQTT publishing
|
||||
char heartbeatBuf[HEARTBEAT_BUF_SIZE];
|
||||
memset(heartbeatBuf, 0, HEARTBEAT_BUF_SIZE);
|
||||
snprintf(heartbeatBuf, HEARTBEAT_BUF_SIZE-1, "{\"lastMessage\":%s, \"uptime\":%ld}", buf, uptime);
|
||||
mqttClient.publish(configBlock.mqttHeartbeatTopic, heartbeatBuf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user