-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrain_sensor.h
50 lines (41 loc) · 988 Bytes
/
rain_sensor.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Weatherstation
rain sensor
Author: Christian Langrock
Date: 2022-August-06
*/
char* strMQTTTopicRain {mqtt_topic_rain};
void init_rain_sensor() {
if (debugOutput) {
Serial.println("Rain sensor");
}
pinMode(DIGITAL_PIN_RAIN, INPUT);
// build MQTT topic
if (debugOutput) {
Serial.print("MQTT topic prefix for rainning: ");
Serial.println(strMQTTTopicRain);
}
}
struct Rain_array check_raining() {
struct Rain_array OutArray;
String raining;
float rainVal = analogRead(ANALOG_PIN);
bool isRaining = digitalRead(DIGITAL_PIN_RAIN);
if (isRaining) {
raining = "No";
OutArray.Result = "False";
}
else {
raining = "Yes";
OutArray.Result = "True";
}
rainVal = map(rainVal, 0, 1023, 100, 0);
OutArray.Moisture = rainVal;
if (debugMeasure) {
Serial.print("Raining: ");
Serial.println(raining);
Serial.print("Moisture: ");
Serial.print(rainVal);
Serial.println("%");
}
return OutArray;
}