DHT-usage switchable, MQTT authentication optional, soil-sensor-parameter moved to config-file

This commit is contained in:
Julian Langhoff
2021-05-09 21:19:55 +02:00
parent 8bc1861024
commit 0ae0e76f68
5 changed files with 53 additions and 18 deletions

View File

@@ -14,4 +14,7 @@
// Sleep this many again before waging up. Sleep time in s = WATCHDOG_WAKEUP s * WATCHDOG_SLEEP_FURTHER, e.g. 8*8s = 64s
#define WATCHDOG_SLEEP_FURTHER 8
// define wether to use a DHT-Sensor or not
bool USE_DHT_SENSOR = true;
#endif

View File

@@ -68,7 +68,10 @@ void setup()
pinMode(SOIL_PIN, INPUT);
// init the DHT22
dht_init(&dht, DHT_PIN);
if (USE_DHT_SENSOR == 1)
{
dht_init(&dht, DHT_PIN);
}
uint8_t num_blink = 3;
@@ -112,24 +115,35 @@ void loop()
memcpy(&rh_buf[1], &battery, 4);
rh_send(rh_buf,RH_BUF_LEN);
}
else if (dht_read_data(&dht, &t, &h) == 1)
else if (USE_DHT_SENSOR == 1)
{
rh_buf[0] = MSG_TEMPHUM;
memcpy(&rh_buf[1], &t, 4);
memcpy(&rh_buf[5], &h, 4);
soil = analogRead(SOIL_PIN);
memcpy(&rh_buf[9], &soil, 2);
if (dht_read_data(&dht, &t, &h) == 1)
{
rh_buf[0] = MSG_TEMPHUM;
memcpy(&rh_buf[1], &t, 4);
memcpy(&rh_buf[5], &h, 4);
soil = analogRead(SOIL_PIN);
memcpy(&rh_buf[9], &soil, 2);
rh_send(rh_buf,RH_BUF_LEN);
rh_send(rh_buf,RH_BUF_LEN);
}
else
{
// error message
blink(4);
digitalWrite(TRANSISTOR_BASE_PIN, HIGH);
delay(5);
rh_buf[0] = MSG_ERR;
rh_send(rh_buf,1);
}
}
else
{
// error message
blink(4);
digitalWrite(TRANSISTOR_BASE_PIN, HIGH);
delay(5);
rh_buf[0] = MSG_ERR;
rh_send(rh_buf,1);
rh_buf[0] = MSG_HUM;
soil = analogRead(SOIL_PIN);
memcpy(&rh_buf[1], &soil, 2);
rh_send(rh_buf,RH_BUF_LEN);
}
counter++;

View File

@@ -47,6 +47,7 @@
#define MSG_BAT 0x20
#define MSG_TEMPHUM 0x30
#define MSG_ERR 0x40
#define MSG_HUM 0x50 // case, sensor just reads soil-humidity
// for watchdog wakeup
// https://gist.github.com/dwhacks/8055287