Cleanups
This commit is contained in:
parent
e73944fba8
commit
662c934258
|
|
@ -1,7 +1,12 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <RH_ASK.h>
|
||||||
|
|
||||||
#define SERVER_ADDRESS 0x01
|
/**
|
||||||
|
* Baud Rate for the 433 Mhz connection.
|
||||||
|
* Caution: Must be the same for sender & receiver!
|
||||||
|
**/
|
||||||
#define RH_SPEED 1000
|
#define RH_SPEED 1000
|
||||||
|
|
||||||
#define RH_RX_PIN 11
|
#define RH_RX_PIN 11
|
||||||
|
|
||||||
#define RH_BUF_LEN 5
|
#define RH_BUF_LEN 5
|
||||||
|
|
@ -9,8 +14,7 @@ uint8_t rh_buf[RH_BUF_LEN];
|
||||||
|
|
||||||
#define RH_ASK_MAX_MESSAGE_LEN RH_BUF_LEN
|
#define RH_ASK_MAX_MESSAGE_LEN RH_BUF_LEN
|
||||||
|
|
||||||
#include <RHDatagram.h>
|
|
||||||
#include <RH_ASK.h>
|
|
||||||
|
|
||||||
RH_ASK driver(RH_SPEED, RH_RX_PIN);
|
RH_ASK driver(RH_SPEED, RH_RX_PIN);
|
||||||
|
|
||||||
|
|
@ -18,6 +22,9 @@ float t = 0;
|
||||||
float h = 0;
|
float h = 0;
|
||||||
long bat = 0;
|
long bat = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message identifier constants:
|
||||||
|
* */
|
||||||
#define MSG_START 0x00
|
#define MSG_START 0x00
|
||||||
#define MSG_TEMP 0x01
|
#define MSG_TEMP 0x01
|
||||||
#define MSG_HUMID 0x02
|
#define MSG_HUMID 0x02
|
||||||
|
|
@ -37,32 +44,31 @@ void loop() {
|
||||||
|
|
||||||
uint8_t len = sizeof(rh_buf);
|
uint8_t len = sizeof(rh_buf);
|
||||||
if (driver.recv(rh_buf, &len)) {
|
if (driver.recv(rh_buf, &len)) {
|
||||||
Serial.println("got message: ");
|
|
||||||
switch (rh_buf[0]) {
|
switch (rh_buf[0]) {
|
||||||
case MSG_START:
|
case MSG_START:
|
||||||
// start message
|
// start message
|
||||||
Serial.println("0x00 start byte");
|
Serial.println("0x00 start byte");
|
||||||
break;
|
break;
|
||||||
case MSG_TEMP:
|
case MSG_TEMP:
|
||||||
// DHT data
|
// DHT Temperature
|
||||||
Serial.println("0x01 DHT data");
|
Serial.println("0x01 DHT Temp");
|
||||||
memcpy(&t, &rh_buf[1], 4);
|
memcpy(&t, &rh_buf[1], 4);
|
||||||
Serial.print(t);
|
Serial.print(t);
|
||||||
Serial.print("°C - ");
|
Serial.println(" °C");
|
||||||
break;
|
break;
|
||||||
case MSG_HUMID:
|
case MSG_HUMID:
|
||||||
// battery data
|
// DHT Humidity:
|
||||||
Serial.println("0x02 DHT Humidity");
|
Serial.println("0x02 DHT Humidity");
|
||||||
memcpy(&t, &rh_buf[1], 4);
|
memcpy(&t, &rh_buf[1], 4);
|
||||||
Serial.print(t);
|
Serial.print(t);
|
||||||
Serial.print("%");
|
Serial.println(" %");
|
||||||
break;
|
break;
|
||||||
case MSG_BAT:
|
case MSG_BAT:
|
||||||
// battery data
|
// battery data
|
||||||
Serial.println("0x03 Battery");
|
Serial.println("0x03 Battery");
|
||||||
memcpy(&bat, &rh_buf[1], 4);
|
memcpy(&bat, &rh_buf[1], 4);
|
||||||
Serial.print(bat);
|
Serial.print(bat);
|
||||||
Serial.print("mV");
|
Serial.println(" mV");
|
||||||
break;
|
break;
|
||||||
case MSG_ERR:
|
case MSG_ERR:
|
||||||
// error
|
// error
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue