Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7d9e4dfda1
|
|||
9ffea49d71
|
|||
c295d2c169
|
|||
b344fca66e
|
@ -11,6 +11,8 @@
|
|||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
#define VALUES_BUF_SIZE 128
|
||||||
|
#define HEARTBEAT_BUF_SIZE 256
|
||||||
|
|
||||||
|
|
||||||
#define NODEMCU
|
#define NODEMCU
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"releaseTag": "v1.0.0",
|
"releaseTag": "v1.0.3",
|
||||||
"createReleaseTag": "true",
|
"createReleaseTag": "true",
|
||||||
"releaseName": "initial",
|
"releaseName": "heartbeat fix 2",
|
||||||
"description": "initial"
|
"description": "heartbeat message fixed, raincnt has to be static"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,11 +10,13 @@ configItems = [
|
|||||||
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":1883},
|
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":1883},
|
||||||
{"label":"MQTT ValuesTopic", "key":"mqttValuesTopic", "type":"C", "length":64, "default":"IoT/RainSensor2/Values"},
|
{"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 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":"MQTT WatchdogTopic", "key":"mqttWatchdogTopic", "type":"C", "length":64, "default":"IoT/Watchdog"},
|
||||||
{"label":"Values period (s)", "key":"valuesPeriod", "type":"I", "default":3600},
|
{"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":"Debounce time (us)", "key":"debounce", "type":"I", "default":300},
|
||||||
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
||||||
]
|
]
|
||||||
|
|
||||||
magic = 3235774471
|
magic = 3235774472
|
||||||
appName = "ESP8266 based RainSensor/Counter"
|
appName = "ESP8266 based RainSensor/Counter"
|
||||||
|
@ -67,12 +67,13 @@ void loopApplication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t totalCnt = 0;
|
static uint32_t totalCnt = 0;
|
||||||
static uint32_t lastMillis = 0;
|
static uint32_t lastValuesMillis = 0;
|
||||||
if (currentMillis > (lastMillis + (configBlock.valuesPeriod * 1000))) {
|
static uint32_t lastHeartbeatMillis = 0;
|
||||||
lastMillis = currentMillis;
|
static uint32_t rainCnt = 0;
|
||||||
|
if (currentMillis > (lastValuesMillis + (configBlock.valuesPeriod * 1000))) {
|
||||||
|
lastValuesMillis = currentMillis;
|
||||||
|
|
||||||
// rain sensor
|
// rain sensor
|
||||||
uint32_t rainCnt = 0;
|
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
rainCnt = cnt;
|
rainCnt = cnt;
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
@ -84,12 +85,26 @@ void loopApplication() {
|
|||||||
totalCnt += rainCnt;
|
totalCnt += rainCnt;
|
||||||
|
|
||||||
// MQTT publishing
|
// MQTT publishing
|
||||||
#define BUF_SIZE 256
|
char buf[VALUES_BUF_SIZE];
|
||||||
char buf[BUF_SIZE];
|
memset(buf, 0, VALUES_BUF_SIZE);
|
||||||
snprintf(buf, BUF_SIZE-1, "{\"raincnt\":%ld, \"totalCnt\":%ld, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
snprintf(buf, VALUES_BUF_SIZE-1, "{\"raincnt\":%ld, \"totalCnt\":%ld, \"uptime\":%ld}", rainCnt, totalCnt, uptime);
|
||||||
mqttClient.publish(configBlock.mqttValuesTopic, buf);
|
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