Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
9ffea49d71
|
|||
c295d2c169
|
|||
b344fca66e
|
@ -11,6 +11,8 @@
|
||||
// #define DEBUG
|
||||
|
||||
|
||||
#define VALUES_BUF_SIZE 128
|
||||
#define HEARTBEAT_BUF_SIZE 256
|
||||
|
||||
|
||||
#define NODEMCU
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"releaseTag": "v1.0.0",
|
||||
"releaseTag": "v1.0.2",
|
||||
"createReleaseTag": "true",
|
||||
"releaseName": "initial",
|
||||
"description": "initial"
|
||||
"releaseName": "heartbeat fix",
|
||||
"description": "heartbeat message fixed"
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,11 +10,13 @@ configItems = [
|
||||
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":1883},
|
||||
{"label":"MQTT ValuesTopic", "key":"mqttValuesTopic", "type":"C", "length":64, "default":"IoT/RainSensor2/Values"},
|
||||
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RainSensor2/Debug"},
|
||||
{"label":"MQTT HeartbeatTopic", "key":"mqttHeartbeatTopic", "type":"C", "length":64, "default":"IoT/RainSensor2/Heartbeat"},
|
||||
{"label":"MQTT WatchdogTopic", "key":"mqttWatchdogTopic", "type":"C", "length":64, "default":"IoT/Watchdog"},
|
||||
{"label":"Values period (s)", "key":"valuesPeriod", "type":"I", "default":3600},
|
||||
{"label":"Heartbeat period (s)", "key":"heartbeatPeriod", "type":"I", "default":5},
|
||||
{"label":"Debounce time (us)", "key":"debounce", "type":"I", "default":300},
|
||||
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
||||
]
|
||||
|
||||
magic = 3235774471
|
||||
magic = 3235774472
|
||||
appName = "ESP8266 based RainSensor/Counter"
|
||||
|
@ -67,12 +67,13 @@ 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;
|
||||
uint32_t rainCnt = 0;
|
||||
if (currentMillis > (lastValuesMillis + (configBlock.valuesPeriod * 1000))) {
|
||||
lastValuesMillis = currentMillis;
|
||||
|
||||
// rain sensor
|
||||
uint32_t rainCnt = 0;
|
||||
noInterrupts();
|
||||
rainCnt = cnt;
|
||||
cnt = 0;
|
||||
@ -84,12 +85,26 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
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, "{\"lastValues\":{\"raincnt\":%ld, \"totalCnt\":%ld}, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
||||
mqttClient.publish(configBlock.mqttHeartbeatTopic, heartbeatBuf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user