mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
Updates and Additions
Updated to work with latest ESP8266 releases Added tipping bucket, capacitive soil moisture, and motion sensor support
This commit is contained in:
parent
fbee9f10a3
commit
afd964ec2b
@ -1,4 +1,4 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY MODULE
|
||||
//
|
||||
@ -104,15 +104,20 @@ void setup() {
|
||||
void getSerial() {
|
||||
String incomingString = Serial.readString();
|
||||
StaticJsonDocument<3072> doc;
|
||||
//Serial.println(incomingString);
|
||||
Serial.println(incomingString);
|
||||
DeserializationError error = deserializeJson(doc, incomingString);
|
||||
if (error) { // Test if parsing succeeds.
|
||||
Serial.println("yikes");
|
||||
|
||||
|
||||
return;
|
||||
} else {
|
||||
DataReading newCMD;
|
||||
newCMD.id = doc[0]["id"];
|
||||
newCMD.t = doc[0]["type"];
|
||||
newCMD.d = doc[0]["data"];
|
||||
|
||||
newCMD.id = doc["id"];
|
||||
newCMD.t = doc["type"];
|
||||
newCMD.d = doc["data"];
|
||||
Serial.println(newCMD.id );
|
||||
esp_now_send(prevAddress, (uint8_t *) &newCMD, sizeof(newCMD));
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,15 @@
|
||||
// The gateway receives the data and outputs it as a json string over the serial port.
|
||||
|
||||
// THIS UNIT
|
||||
//#define UNIT_MAC 0x00 // Terminal
|
||||
#define UNIT_MAC 0x01 // Relay 0
|
||||
#define UNIT_MAC 0x00 // Terminal
|
||||
//#define UNIT_MAC 0x01 // Relay 0
|
||||
//#define UNIT_MAC 0x02 // Relay 1
|
||||
//#define UNIT_MAC 0x03 // Gateway
|
||||
//#define UNIT_MAC 0x04 //
|
||||
|
||||
// PREVIOUS UNIT
|
||||
#define PREV_MAC 0x00 // Terminal
|
||||
//#define PREV_MAC 0x00 // Terminal
|
||||
//#define PREV_MAC 0x01 // Relay 0
|
||||
//#define PREV_MAC 0x02 // Relay 1
|
||||
//#define PREV_MAC 0x03 // Gateway
|
||||
//#define PREV_MAC 0x04 //
|
||||
#define PREV_MAC 0x04 //
|
||||
|
@ -4,8 +4,8 @@
|
||||
// Uses JSON data from the serial port to set Blynk variables.
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// This code has some WDT issues that cause periodic reboots.
|
||||
// If you have any insights into these, I'd love to hear them!
|
||||
// This code was written for the now-outdated version of Blynk, and is mostly here for reference.
|
||||
//
|
||||
|
||||
#define STASSID "" //Your SSID
|
||||
#define STAPSK "" //Your Password
|
||||
|
1
Front-End_Modules/FDRS_NodeRed.json
Normal file
1
Front-End_Modules/FDRS_NodeRed.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
48
README.md
48
README.md
@ -1,44 +1,30 @@
|
||||
# Farm Data Relay System
|
||||
|
||||
The purpose of the Farm Data Relay System is to provide a method of exchanging data between many ESP32 or ESP8266 devices in situations where it would be difficult or energy-consuming to provide full WiFi coverage.
|
||||
|
||||
A major goal is to make the system straight-forward and easy to use, as the primary user may not necessarily be very familiar with Arduino. Using an assigned MAC address scheme allows for the whole system to be configured by setting just a handful of values in code.
|
||||
The goal of the Farm Data Relay System is to provide a way for sensor data to be collected from areas out of wifi range, while not straying from the popular and presentable ESP8266 or soon, the ESP32. I have tested ESP-NOW range to be reliable within at least 500 feet with line of sight, effectively double what would be possible with regular WiFi connections. Another goal is to make the system straight-forward and easy to use, as the primary user will not necessarily be familiar with Arduino.
|
||||
Other than the sensors, each device in the system has a one-byte address. To make things easier, it's good to keep their addresses consecutive with their order in the system. At boot, each device changes its MAC address to "AA:BB:CC:DD:EE:xx" where xx is the device's address identifier.
|
||||
There are three types of units in the FDRS: the terminal, the relays, and the gateway.
|
||||
|
||||
## Nodes
|
||||
Each "node" in the system sends its data as a float 'd' inside of a structure called a DataReading. Its global address is represented by an integer 'id', and has a type represented by a single byte 't'. For example: a BME280 sketch using FDRS will send an array of three DataReadings, one each for temperature, humidity, and pressure. The types for those readings are 1, 2, and 3 respectively.
|
||||
I'm experimenting with nodes that *recieve* DataReadings as well. DataReadings of type 201 are treated as commands.
|
||||
# Terminal
|
||||
The terminal receives individual ESP-NOW packets from the sensor modules and stores them in an array. At the moment, this is arbitrarily set to a six-item array. At a set interval, the terminal sends its data array to the preprogrammed next device in the system, usually a relay.
|
||||
|
||||
## Terminal
|
||||
The terminal is a device that recieves data from the nodes and aggregates them into a larger array. The larger array is then periodically sent through the system to the gateway. The time between sends must be short enough so as not to exceed the maximum legnth of an ESP-NOW packet with DataReadings, which is 31.
|
||||
# Relays
|
||||
Relays are absolute ESP-NOW repeaters. They are programmed with the address of the previous and next device, and when data is received from one, it delivers it to the other. It also works in reverse, but for the moment the system only supports one-way communication.
|
||||
In the FDRS, one can place as many relays as needed to span the distance to the final device in the system: the gateway.
|
||||
|
||||
As I implement the ability to send commands, the terminal has taken on some routing resposibilities as well. When a terminal recieves a DataReading of type 200, it associates the last byte of the incoming MAC with the ID of the reading in an array. This array is referenced in order for the terminal to forward any commands it recieves to their proper destinations.
|
||||
# Gateway
|
||||
The gateway takes the packet of ESP-NOW data and interprets it into JSON format, then outputs it over the serial port. From here it can be collected by another microcontroller or a Raspberry Pi for further processing.
|
||||
I've included an ESP8266 sketch for receiving the JSON over serial and posting it to Blynk as well.
|
||||
|
||||
## Relays
|
||||
Relays are absolute ESP-NOW repeaters. They are programmed with the address of the previous and next device, and when data is received from one, it delivers it to the other. The "DEFT_MAC" setting defines where a relay will send an incoming packet with an unknown address. This can be used to direct sensor packets either to the terminal or the gateway.
|
||||
# Sensors
|
||||
The sensors are pre-set with the address of the terminal and their own one-byte identifier. This ID is sent along with each data reading and will define its position in the larger data array at the terminal and beyond.
|
||||
|
||||
In the FDRS, one can place as many relays as needed to span the distance to the gateway, which is the final device in the system. Being honest, I now have access to WiFi close to my terminal, so I no longer need any relays at all. They're still handy though.
|
||||
# Future plans
|
||||
The code is currently all written for ESP8266. The NEXT major addition will be ESP32 support. The two work with ESP-NOW just slightly differently in Arduino, but I will be porting it very soon.
|
||||
|
||||
## Gateway
|
||||
The gateway takes the packet of DataReadings and interprets it into json format, then outputs it over the serial port. From here it can be collected by another microcontroller or a Raspberry Pi front-end to be sent to the cloud for further processing and storage.
|
||||
Future plans include two-way communication, some basic routing ability for the relays, and optimizing the underlying protocols needed for the first two goals. I'd like to eventually be able to send commands to remotely adjust irrigation/ventilation or even send weather data such as tornado warnings to the terminal in future iterations of this project.
|
||||
|
||||
## Front-end
|
||||
### Node-Red
|
||||
I'm very excited to have begun learning about and supporting Node-Red via Raspberry Pi. I've soldered the serial and power connections of a WeMos D1 Mini directly to my RPi Zero W. I am getting pretty busy with actual farming, so this will make it a lot easier to develop front-end applications in the short-term.
|
||||
### Blynk
|
||||
This is for the original Blynk! I won't have time to learn the new system for a while, so it will probably remain in this state for a bit...
|
||||
|
||||
Each DataReading that is recieved via serial is set to its blynk virtual pin counterpart. I've also implemented "set" and "get" commands for the blynk terminal, but these are still experimental.
|
||||
|
||||
The Blynk sketch has been giving me problems, but it does still work. It suffers from a couple seemingly random WDT resets that I'm still struggling to pin down. This doesn't affect much functionality much for me, but I'd graciously accept any advice in that area.
|
||||
|
||||
## Future plans
|
||||
Future plans are to include as many types of nodes and front end modules as I can fathom. I'm working on sketches to remotely adjust irrigation/ventilation, as well as an idea for RGB lanterns, with colors controlled by FDRS. I'm also looking into the ability to display certain readings on a screen and send manual commands from the terminal itself, or other devices within the system locally.
|
||||
|
||||
## Thank you
|
||||
# Thank you
|
||||
...very much for checking out my project! There are a few topics I've glossed over here that I intend to elaborate on in the future. If you have any questions, please feel free to contact me at bogner1@gmail.com.
|
||||
|
||||
Also a big thank you to both ***Sola Gratia Farm*** and ***The IDEA Store*** of *Urbana, IL, USA*, without whom this project would not exist.
|
||||
Also a big thank you to both Sola Gratia Farm and the IDEA Store of Urbana, IL, USA, without whom this project would not exist.
|
||||
|
||||
|
||||
[***In loving memory of Gay Holman, an extraordinary individual.***](https://www.facebook.com/CFECI/posts/2967989419953119)
|
||||
|
@ -6,9 +6,9 @@
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
//
|
||||
|
||||
#define TEMP_ID 0 //Unique ID for each data reading
|
||||
#define HUM_ID 1
|
||||
#define PRES_ID 2
|
||||
#define TEMP_ID 1 //Unique ID for each data reading
|
||||
#define HUM_ID 11
|
||||
#define PRES_ID 21
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define SLEEPYTIME 30 //Time to sleep in seconds
|
||||
|
||||
@ -33,6 +33,7 @@ void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
Wire.begin();
|
||||
while (!bme.begin(0x76)) {
|
||||
delay(10);
|
||||
@ -41,10 +42,10 @@ void setup() {
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -4,7 +4,7 @@
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
//
|
||||
//
|
||||
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define SLEEPYTIME 30 //Time to sleep in seconds
|
||||
@ -39,6 +39,8 @@ void setup() {
|
||||
delay(10);
|
||||
}
|
||||
Serial.println("BMP INIT");
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
|
66
Sensors/CapacitiveSoil/CapacitiveSoil.ino
Normal file
66
Sensors/CapacitiveSoil/CapacitiveSoil.ino
Normal file
@ -0,0 +1,66 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// CAPACITIVE SOIL MOISTURE SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
//
|
||||
#define CALIBRATION_MODE 0
|
||||
#define CALIB_H 285
|
||||
#define CALIB_L 485
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define SLEEPYTIME 60 //Time to sleep in seconds
|
||||
#define SOIL_ID 51 //Unique ID (0 - 255) for each data reading
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "DataReading.h"
|
||||
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, TERM_MAC};
|
||||
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
Serial.print("Last Packet Send Status: ");
|
||||
if (sendStatus == 0) {
|
||||
Serial.println("Delivery success");
|
||||
}
|
||||
else {
|
||||
Serial.println("Delivery fail");
|
||||
}
|
||||
ESP.deepSleep(30e6);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
|
||||
loadData();
|
||||
}
|
||||
void loop() {
|
||||
|
||||
}
|
||||
void loadData() {
|
||||
uint16_t s = analogRead(0);
|
||||
if (!CALIBRATION_MODE) {
|
||||
if (s < CALIB_H) s = CALIB_H;
|
||||
if (s > CALIB_L) s = CALIB_L;
|
||||
s = map(s, CALIB_H, CALIB_L, 100, 0);
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println(s);
|
||||
DataReading Soil;
|
||||
Soil.d = s;
|
||||
Soil.id = SOIL_ID;
|
||||
Soil.t = 5;
|
||||
DataReading thePacket[1];
|
||||
thePacket[0] = Soil;
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &thePacket, sizeof(thePacket));
|
||||
}
|
7
Sensors/CapacitiveSoil/DataReading.h
Normal file
7
Sensors/CapacitiveSoil/DataReading.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
typedef struct DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
@ -38,6 +38,8 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
dht.setup(DHT_PIN, DHTesp::DHT22);
|
||||
Serial.println("DHT Initialized");
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -7,9 +7,9 @@
|
||||
//
|
||||
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define SLEEPYTIME 60 //Time to sleep in seconds
|
||||
#define TEMP_ID 1 //Unique ID (0 - 255) for each data reading
|
||||
#define ONE_WIRE_BUS 2 //Pin that the DS18B20 is connected to
|
||||
#define SLEEPYTIME 30 //Time to sleep in seconds
|
||||
#define TEMP_ID 4 //Unique ID (0 - 255) for each data reading
|
||||
#define ONE_WIRE_BUS 13 //Pin that the DS18B20 is connected to
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
@ -34,15 +34,18 @@ void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
sensors.begin();
|
||||
Serial.println("DS18B20 Initialized");
|
||||
WiFi.mode(WIFI_STA);
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
|
||||
sensors.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -57,9 +60,9 @@ void loadData() {
|
||||
DataReading Temp;
|
||||
Temp.id = TEMP_ID;
|
||||
Temp.t = 1;
|
||||
if (tempC = DEVICE_DISCONNECTED_C) Temp.d = -69.00;
|
||||
else Temp.d = tempC;
|
||||
|
||||
// if (tempC = DEVICE_DISCONNECTED_C) Temp.d = -69.00;
|
||||
// else Temp.d = tempC;
|
||||
Temp.d = tempC;
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &Temp, sizeof(Temp));
|
||||
|
||||
}
|
||||
|
7
Sensors/MotionDetector/DataReading.h
Normal file
7
Sensors/MotionDetector/DataReading.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
typedef struct DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
85
Sensors/MotionDetector/MotionDetector.ino
Normal file
85
Sensors/MotionDetector/MotionDetector.ino
Normal file
@ -0,0 +1,85 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// MOTION SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
// This code is unfinished, but may work.
|
||||
//
|
||||
#define MOTION_PIN 13
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define MOTION_ID 100 //Unique ID (0 - 255) for each data reading
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "DataReading.h"
|
||||
unsigned int theCount = 0;
|
||||
unsigned long nextCheck = 0;
|
||||
boolean motionDetected = false;
|
||||
unsigned long isr_time = millis();
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, TERM_MAC};
|
||||
|
||||
|
||||
ICACHE_RAM_ATTR void detectsMovement() {
|
||||
if (millis() > isr_time + 15000) {
|
||||
nextCheck = millis();
|
||||
isr_time = millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
Serial.print("Last Packet Send Status: ");
|
||||
if (sendStatus == 0) {
|
||||
Serial.println("Delivery success");
|
||||
}
|
||||
else {
|
||||
Serial.println("Delivery fail");
|
||||
}
|
||||
}
|
||||
// Checks if motion was detected, sets LED HIGH and starts a timer
|
||||
|
||||
void setup() {
|
||||
// Serial port for debugging purposes
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
|
||||
pinMode(MOTION_PIN, INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(MOTION_PIN), detectsMovement, RISING);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if ( millis() > nextCheck) {
|
||||
checkDetector();
|
||||
|
||||
}
|
||||
}
|
||||
void checkDetector() {
|
||||
|
||||
Serial.println("Checking");
|
||||
|
||||
nextCheck = millis() + 15000;
|
||||
motionDetected = digitalRead(MOTION_PIN);
|
||||
if (motionDetected == HIGH) {
|
||||
Serial.println("Motion Detected");
|
||||
|
||||
DataReading Motion;
|
||||
Motion.d = theCount;
|
||||
Motion.id = MOTION_ID;
|
||||
Motion.t = 8;
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &Motion, sizeof(Motion));
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
7
Sensors/TippingBucket/DataReading.h
Normal file
7
Sensors/TippingBucket/DataReading.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
typedef struct DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
65
Sensors/TippingBucket/TippingBucket.ino
Normal file
65
Sensors/TippingBucket/TippingBucket.ino
Normal file
@ -0,0 +1,65 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// TIPPING BUCKET RAINFALL SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a two-byte identifier along with a one-byte sensor type
|
||||
//
|
||||
#define REED_PIN 2
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
#define RAIN_ID 0 //Unique ID (0 - 255) for each data reading
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "DataReading.h"
|
||||
unsigned int theCount = 0;
|
||||
unsigned long lastTrigger = 0;
|
||||
boolean clicked = false;
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, TERM_MAC};
|
||||
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
Serial.print("Last Packet Send Status: ");
|
||||
if (sendStatus == 0) {
|
||||
Serial.println("Delivery success");
|
||||
}
|
||||
else {
|
||||
Serial.println("Delivery fail");
|
||||
}
|
||||
}
|
||||
// Checks if motion was detected, sets LED HIGH and starts a timer
|
||||
ICACHE_RAM_ATTR void detectsMovement() {
|
||||
clicked = true;
|
||||
lastTrigger = millis();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Serial port for debugging purposes
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
// Register peer
|
||||
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
|
||||
pinMode(REED_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(REED_PIN), detectsMovement, FALLING);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (clicked && millis() - lastTrigger > 100) {
|
||||
theCount++;
|
||||
Serial.print("CLICK.");
|
||||
Serial.println(theCount);
|
||||
clicked = false;
|
||||
DataReading Rain;
|
||||
Rain.d = theCount;
|
||||
Rain.id = RAIN_ID;
|
||||
Rain.t = 7;
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &Rain, sizeof(Rain));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user