Testing, device-id, esp-receiver configurable
This commit is contained in:
parent
61374b584a
commit
2e72d8dc42
|
|
@ -3,3 +3,4 @@
|
||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.vscode/ipch
|
.vscode/ipch
|
||||||
|
config.h
|
||||||
|
|
@ -19,4 +19,5 @@ lib_deps =
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
bblanchon/ArduinoJson@^6.17.3
|
bblanchon/ArduinoJson@^6.17.3
|
||||||
build_flags = -D USE_ESPRESSIF
|
build_flags = -D USE_ESPRESSIF
|
||||||
|
upload_port = /dev/ttyUSB0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef __CONFIG_H__
|
||||||
|
#define __CONFIG_H__
|
||||||
|
/**
|
||||||
|
* For project specific settings. Copy to config.h and place your settings there.
|
||||||
|
**/
|
||||||
|
|
||||||
|
const char *MQTT_BROKER = "192.168.178.74";
|
||||||
|
const char *MQTT_SENSOR_TOPIC = "living/sensor2";
|
||||||
|
const char *MQTT_CLIENT_ID = "living_mobile_sensor";
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -29,14 +29,20 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this file does not exist create it from the config.h.example file
|
||||||
|
* Place project specific settings here. It should not be checked in.
|
||||||
|
* */
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
const int AirValue = 800; //replace the value with value when placed in air
|
const int AirValue = 800; //replace the value with value when placed in air
|
||||||
const int WaterValue = 345; //replace the value with value when placed in water
|
const int WaterValue = 345; //replace the value with value when placed in water
|
||||||
|
|
||||||
volatile boolean new_value = false;
|
volatile boolean new_value = false;
|
||||||
|
|
||||||
const char *MQTT_BROKER = "192.168.178.74";
|
|
||||||
const char *MQTT_SENSOR_TOPIC = "living/sensor2";
|
|
||||||
const char *MQTT_CLIENT_ID = "living_mobile_sensor";
|
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
|
|
@ -44,13 +50,11 @@ PubSubClient mqttClient(MQTT_BROKER, 1883, espClient);
|
||||||
|
|
||||||
RH_ASK driver(RH_SPEED, RH_RX_PIN);
|
RH_ASK driver(RH_SPEED, RH_RX_PIN);
|
||||||
|
|
||||||
/**
|
// Message Headers:
|
||||||
* Message identifier constants:
|
#define MSG_START 0x10
|
||||||
* */
|
#define MSG_BAT 0x20
|
||||||
#define MSG_START 0x00
|
#define MSG_TEMPHUM 0x30
|
||||||
#define MSG_BAT 0x03
|
#define MSG_ERR 0x40
|
||||||
#define MSG_HEADER 0x05
|
|
||||||
#define MSG_ERR 0xee
|
|
||||||
|
|
||||||
char buff[20];
|
char buff[20];
|
||||||
|
|
||||||
|
|
@ -137,13 +141,17 @@ void loop()
|
||||||
if (driver.recv(rh_buf, &len))
|
if (driver.recv(rh_buf, &len))
|
||||||
{
|
{
|
||||||
Serial.println("Message received.");
|
Serial.println("Message received.");
|
||||||
switch (rh_buf[0])
|
uint8_t header = rh_buf[0] & 0xf0;
|
||||||
|
uint8_t device_id = rh_buf[0] &0x0f;
|
||||||
|
Serial.print("Device ID: ");
|
||||||
|
Serial.println(device_id);
|
||||||
|
switch (rh_buf[0] & 0xf0)
|
||||||
{
|
{
|
||||||
case MSG_START:
|
case MSG_START:
|
||||||
// start message
|
// start message
|
||||||
Serial.println("0x00 start byte");
|
Serial.println("0x00 start byte, first message from sensor");
|
||||||
break;
|
break;
|
||||||
case MSG_HEADER:
|
case MSG_TEMPHUM:
|
||||||
// DHT Temperature
|
// DHT Temperature
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
Serial.println("DHT Temp");
|
Serial.println("DHT Temp");
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ void test_message_header() {
|
||||||
TEST_ASSERT_EQUAL(0x11, header);
|
TEST_ASSERT_EQUAL(0x11, header);
|
||||||
|
|
||||||
// header
|
// header
|
||||||
TEST_ASSERT_EQUAL(0x10, header & 0x10);
|
TEST_ASSERT_EQUAL(0x10, header & 0xf0);
|
||||||
|
|
||||||
// id
|
// id
|
||||||
TEST_ASSERT_EQUAL(0x01, header & 0x01);
|
TEST_ASSERT_EQUAL(0x01, header & 0x0f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue