take over counter handling from old project
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* defines.h
|
* defines.h
|
||||||
*
|
*
|
||||||
* Created on: Aug 20, 2017
|
* Created on: Jul 26, 2020
|
||||||
* Author: wn
|
* Author: wn
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #define WS2811
|
|
||||||
#define PL9823
|
|
||||||
|
|
||||||
#define NODEMCU
|
#define NODEMCU
|
||||||
// #define ESP01
|
// #define ESP01
|
||||||
@ -28,20 +26,8 @@
|
|||||||
#define CONFIG_SWITCH D2
|
#define CONFIG_SWITCH D2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WS2811
|
|
||||||
#define PIXEL_PIN 1 // NODEMCU numbering
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PL9823
|
#define REED_PIN 13
|
||||||
#ifdef ESP01
|
|
||||||
#define PIXEL_PIN 2
|
|
||||||
#endif
|
|
||||||
#ifdef NODEMCU
|
|
||||||
#define PIXEL_PIN D1
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NUM_OF_LEDs 300
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* DEFINES_H_ */
|
#endif /* DEFINES_H_ */
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"releaseTag": "v1.0.6",
|
"releaseTag": "v1.0.0",
|
||||||
"createReleaseTag": "true",
|
"createReleaseTag": "true",
|
||||||
"releaseName": "colorPattern and watchdog",
|
"releaseName": "initial",
|
||||||
"description": "introduce the colorPattern config option (swap R and G) and use the mqtt boilerplate code with watchdog support"
|
"description": "initial"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ configItems = [
|
|||||||
{"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 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":"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}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -24,6 +24,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
volatile uint32_t cnt = 0;
|
||||||
|
uint32_t uptime = 0;
|
||||||
|
|
||||||
|
void count() {
|
||||||
|
static uint32_t lastEvent = 0;
|
||||||
|
uint32_t currentEvent = micros();
|
||||||
|
if (currentEvent > (lastEvent + configBlock.debounce)) {
|
||||||
|
lastEvent = currentEvent;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// void subscribeApplication() {
|
// void subscribeApplication() {
|
||||||
// }
|
// }
|
||||||
@ -36,12 +50,44 @@
|
|||||||
void setupApplication() {
|
void setupApplication() {
|
||||||
mqttSetup();
|
mqttSetup();
|
||||||
|
|
||||||
|
pinMode(REED_PIN, INPUT_PULLUP);
|
||||||
|
attachInterrupt(REED_PIN, count, FALLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loopApplication() {
|
void loopApplication() {
|
||||||
mqttLoop();
|
mqttLoop();
|
||||||
|
|
||||||
|
uint32_t currentMillis = millis();
|
||||||
|
|
||||||
|
static uint32_t lastUptimeMillis = 0;
|
||||||
|
if (currentMillis > (lastUptimeMillis + 1000)) {
|
||||||
|
lastUptimeMillis = currentMillis;
|
||||||
|
uptime++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t lastMillis = 0;
|
||||||
|
if (currentMillis > (lastMillis + (configBlock.period * 1000))) {
|
||||||
|
lastMillis = currentMillis;
|
||||||
|
|
||||||
|
// rain sensor
|
||||||
|
uint32_t rainCnt = 0;
|
||||||
|
noInterrupts();
|
||||||
|
rainCnt = cnt;
|
||||||
|
cnt = 0;
|
||||||
|
interrupts();
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print(rainCnt);
|
||||||
|
Serial.println();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MQTT publishing
|
||||||
|
#define BUF_SIZE 256
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
snprintf(buf, BUF_SIZE-1, "{\"raincnt\":%ld, \"uptime\":%ld}", rainCnt, uptime);
|
||||||
|
mqttClient.publish(configBlock.mqttValuesTopic, buf);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user