All values in one message

This commit is contained in:
2021-04-15 22:36:26 +02:00
parent 09c96271c8
commit fd9aad5e2f
2 changed files with 36 additions and 37 deletions

View File

@@ -23,7 +23,7 @@
#define RH_OWN_ADDR 0xca // 202
// RadioHead bitrate in bit/s
#define RH_SPEED 1000
#define RH_SPEED 300
/*
define when to wake up
@@ -33,7 +33,7 @@
#define WATCHDOG_WAKEUP 9
// 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 WATCHDOG_SLEEP_FURTHER 2
// pins for the radio hardware
#define RH_RX_PIN 6 // not used, set to a non-existent pin
@@ -59,8 +59,8 @@
#include "dht22.h"
dht22 dht;
#define RH_BUF_LEN 5
uint8_t rh_buf[RH_BUF_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00};
#define RH_BUF_LEN 11
uint8_t rh_buf[RH_BUF_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// reduce the RadioHead max message length to save memory
#define RH_ASK_MAX_MESSAGE_LEN RH_BUF_LEN
@@ -74,6 +74,7 @@ uint8_t rh_buf[RH_BUF_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00};
#define MSG_HUMID 0x02
#define MSG_BAT 0x03
#define MSG_SOIL 0x04
#define MSG_HEADER 0x05
#define MSG_ERR 0xee
RH_ASK rh_driver(RH_SPEED, RH_RX_PIN, RH_TX_PIN, RH_PTT_PIN);
@@ -151,22 +152,12 @@ void loop()
}
else if (dht_read_data(&dht, &t, &h) == 1)
{
if (counter % 3 == 0)
{
rh_buf[0] = MSG_TEMP;
rh_buf[0] = MSG_HEADER;
memcpy(&rh_buf[1], &t, 4);
}
else if (counter % 3 == 1)
{
rh_buf[0] = MSG_HUMID;
memcpy(&rh_buf[1], &h, 4);
}
else if (counter % 3 == 2)
{
rh_buf[0] = MSG_SOIL;
memcpy(&rh_buf[5], &h, 4);
soil = analogRead(SOIL_PIN);
memcpy(&rh_buf[1], &soil, 2);
}
memcpy(&rh_buf[9], &soil, 2);
rh_send(RH_BUF_LEN);
}
else