fix heartbeat
This commit is contained in:
@ -69,12 +69,11 @@ void loopApplication() {
|
||||
static uint32_t totalCnt = 0;
|
||||
static uint32_t lastValuesMillis = 0;
|
||||
static uint32_t lastHeartbeatMillis = 0;
|
||||
char buf[VALUES_BUF_SIZE];
|
||||
uint32_t rainCnt = 0;
|
||||
if (currentMillis > (lastValuesMillis + (configBlock.valuesPeriod * 1000))) {
|
||||
lastValuesMillis = currentMillis;
|
||||
|
||||
// rain sensor
|
||||
uint32_t rainCnt = 0;
|
||||
noInterrupts();
|
||||
rainCnt = cnt;
|
||||
cnt = 0;
|
||||
@ -86,6 +85,7 @@ void loopApplication() {
|
||||
totalCnt += rainCnt;
|
||||
|
||||
// MQTT publishing
|
||||
char buf[VALUES_BUF_SIZE];
|
||||
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);
|
||||
@ -101,7 +101,7 @@ void loopApplication() {
|
||||
// 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);
|
||||
snprintf(heartbeatBuf, HEARTBEAT_BUF_SIZE-1, "{\"lastValues\":{\"raincnt\":%ld, \"totalCnt\":%ld}, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
||||
mqttClient.publish(configBlock.mqttHeartbeatTopic, heartbeatBuf);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user