Baud Rate, Removed arduino projects
This commit is contained in:
77
esp-receiver/src/main.cpp
Normal file
77
esp-receiver/src/main.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#define SERVER_ADDRESS 0x01
|
||||
#define RH_SPEED 1000
|
||||
#define RH_RX_PIN 11
|
||||
|
||||
#define RH_BUF_LEN 5
|
||||
uint8_t rh_buf[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);
|
||||
|
||||
float t = 0;
|
||||
float h = 0;
|
||||
long bat = 0;
|
||||
|
||||
#define MSG_START 0x00
|
||||
#define MSG_TEMP 0x01
|
||||
#define MSG_HUMID 0x02
|
||||
#define MSG_BAT 0x03
|
||||
#define MSG_ERR 0xee
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
if (!driver.init()) {
|
||||
Serial.println("init failed");
|
||||
} else {
|
||||
Serial.println("init done");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint8_t len = sizeof(rh_buf);
|
||||
if (driver.recv(rh_buf, &len)) {
|
||||
Serial.println("got message: ");
|
||||
switch (rh_buf[0]) {
|
||||
case MSG_START:
|
||||
// start message
|
||||
Serial.println("0x00 start byte");
|
||||
break;
|
||||
case MSG_TEMP:
|
||||
// DHT data
|
||||
Serial.println("0x01 DHT data");
|
||||
memcpy(&t, &rh_buf[1], 4);
|
||||
Serial.print(t);
|
||||
Serial.print("°C - ");
|
||||
break;
|
||||
case MSG_HUMID:
|
||||
// battery data
|
||||
Serial.println("0x02 DHT Humidity");
|
||||
memcpy(&t, &rh_buf[1], 4);
|
||||
Serial.print(t);
|
||||
Serial.print("%");
|
||||
break;
|
||||
case MSG_BAT:
|
||||
// battery data
|
||||
Serial.println("0x03 Battery");
|
||||
memcpy(&bat, &rh_buf[1], 4);
|
||||
Serial.print(bat);
|
||||
Serial.print("mV");
|
||||
break;
|
||||
case MSG_ERR:
|
||||
// error
|
||||
Serial.println("0xEE error");
|
||||
break;
|
||||
default:
|
||||
// should never happen
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user