forked from mhendriks/P1-Dongel-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_Water.ino
35 lines (32 loc) · 1.1 KB
/
_Water.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void handleWater(){
if ( WtrMtr && WtrTimeBetween ) {
DebugTf("Wtr delta readings: %d | debounces: %d | waterstand: %i.%i\n",WtrTimeBetween,debounces, P1Status.wtr_m3, P1Status.wtr_l);
WtrTimeBetween = 0;
}
}
void sendMQTTWater(){
if (!WtrMtr) return;
sprintf(cMsg,"%d.%3.3d",P1Status.wtr_m3,P1Status.wtr_l);
MQTTSend("water",cMsg);
}
void IRAM_ATTR iWater() {
WtrTimeBetween = now() - WtrPrevReading;
if (DUE(WaterTimer)) { //negeer te korte foutieve meting (1500 ltr/uur / 3600 = 0,4l/sec kan daarom niet zo zijn dat binnen de 1/0,4 = 2,4s er nog een puls komt) = debounce timer
P1Status.wtr_l += WtrFactor;
WtrPrevReading = now();
if (P1Status.wtr_l >= 1000) {
P1Status.wtr_m3++;
P1Status.wtr_l = 0;
CHANGE_INTERVAL_MS(StatusTimer, 100); //schrijf status weg bij elke m3
}
} else debounces++;
}
void setupWater() {
#ifdef ARDUINO_ESP32C3_DEV
pinMode(IO_WATER_SENSOR, INPUT_PULLUP);
#else
pinMode(IO_WATER_SENSOR, INPUT);
#endif
attachInterrupt(IO_WATER_SENSOR, iWater, RISING);
DebugTln(F("WaterSensor setup completed"));
}