Add support for rain sensors like FC-37 or YL-83
This commit is contained in:
parent
c9f3eee656
commit
b7a808eaa3
|
@ -44,6 +44,10 @@ float temperature = 0.0;
|
||||||
float humidity = 0.0;
|
float humidity = 0.0;
|
||||||
#endif // DHT_TYPE
|
#endif // DHT_TYPE
|
||||||
|
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
bool raining = false;
|
||||||
|
#endif // RAIN_PIN
|
||||||
|
|
||||||
static const char TEXT_PLAIN[] PROGMEM = "text/plain";
|
static const char TEXT_PLAIN[] PROGMEM = "text/plain";
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -56,13 +60,17 @@ void
|
||||||
send_metrics()
|
send_metrics()
|
||||||
{
|
{
|
||||||
static const size_t dht_size = 228;
|
static const size_t dht_size = 228;
|
||||||
char message[dht_size + 1];
|
static const size_t rain_size = 86;
|
||||||
|
|
||||||
size_t message_size =
|
size_t message_size =
|
||||||
#ifdef DHT_TYPE
|
#ifdef DHT_TYPE
|
||||||
dht_size +
|
dht_size +
|
||||||
#endif // DHT_TYPE
|
#endif // DHT_TYPE
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
rain_size +
|
||||||
|
#endif // RAIN_PIN
|
||||||
1;
|
1;
|
||||||
|
char message[message_size];
|
||||||
|
|
||||||
snprintf(message, message_size,
|
snprintf(message, message_size,
|
||||||
#ifdef DHT_TYPE
|
#ifdef DHT_TYPE
|
||||||
|
@ -71,9 +79,19 @@ send_metrics()
|
||||||
"temperature_celsius %.2f\n"
|
"temperature_celsius %.2f\n"
|
||||||
"# HELP relative_humidity Relative humidity, in percents\n"
|
"# HELP relative_humidity Relative humidity, in percents\n"
|
||||||
"# TYPE relative_humidity gauge\n"
|
"# TYPE relative_humidity gauge\n"
|
||||||
"relative_humidity %.2f\n",
|
"relative_humidity %.2f\n"
|
||||||
temperature, humidity
|
|
||||||
#endif // DHT_TYPE
|
#endif // DHT_TYPE
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
"# HELP raining Boolean value checking if it is raining\n"
|
||||||
|
"# TYPE raining gauge\n"
|
||||||
|
"raining %d\n"
|
||||||
|
#endif // RAIN_PIN
|
||||||
|
#ifdef DHT_TYPE
|
||||||
|
, temperature, humidity
|
||||||
|
#endif // DHT_TYPE
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
, raining ? 1 : 0
|
||||||
|
#endif // RAIN_PIN
|
||||||
);
|
);
|
||||||
|
|
||||||
server.send(200, "text/plain; version=0.0.4; charset=utf-8", message);
|
server.send(200, "text/plain; version=0.0.4; charset=utf-8", message);
|
||||||
|
@ -119,6 +137,10 @@ setup()
|
||||||
dht.begin();
|
dht.begin();
|
||||||
#endif // DHT_TYPE
|
#endif // DHT_TYPE
|
||||||
|
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
pinMode(RAIN_PIN, INPUT);
|
||||||
|
#endif // RAIN_PIN
|
||||||
|
|
||||||
Serial.println("All set, starting the loop.");
|
Serial.println("All set, starting the loop.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +155,10 @@ read_sensors()
|
||||||
humidity = dht.readHumidity();
|
humidity = dht.readHumidity();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef RAIN_PIN
|
||||||
|
raining = (digitalRead(RAIN_PIN) == HIGH);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Turn off the LED to indicate work is finished
|
// Turn off the LED to indicate work is finished
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,3 +47,9 @@
|
||||||
//#define DHT_TYPE DHT11
|
//#define DHT_TYPE DHT11
|
||||||
//#define DHT_TYPE DHT22
|
//#define DHT_TYPE DHT22
|
||||||
//#define DHT_PIN D5
|
//#define DHT_PIN D5
|
||||||
|
|
||||||
|
// If you have a rain sensor (FC-37 or YL-83), connect its digital pin (not the
|
||||||
|
// analogue one!), remove the #undef line, and uncomment and change the
|
||||||
|
// #define RAIN_PIN line
|
||||||
|
#undef RAIN_PIN
|
||||||
|
//#define RAIN_PIN D0
|
||||||
|
|
Loading…
Reference in New Issue