mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
Added front-end and fixed things.
This commit is contained in:
parent
f624aafcf3
commit
5a65510dd2
87
FDRS_Blynk/FDRS_Blynk.ino
Normal file
87
FDRS_Blynk/FDRS_Blynk.ino
Normal file
@ -0,0 +1,87 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// BLYNK FRONT-END MODULE
|
||||
// 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.
|
||||
|
||||
// Change the following three lines to match your project:
|
||||
#define STASSID "MySSID"
|
||||
#define STAPSK "MyPassword"
|
||||
#define BLKAUTH "MyBlynkAuth"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
|
||||
|
||||
char auth[] = BLKAUTH;
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
byte d;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData[6];
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
Blynk.begin(auth, ssid, password);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Blynk.run();
|
||||
if (Serial.available()) getSerial();
|
||||
}
|
||||
|
||||
void getSerial() {
|
||||
delay(50);
|
||||
StaticJsonDocument<512> doc;
|
||||
//char serial_data[512];
|
||||
String serial_data;
|
||||
int serial_len = 0;
|
||||
while (Serial.available()) {
|
||||
//serial_data[serial_len] = Serial.read();
|
||||
char c = Serial.read();
|
||||
serial_data = serial_data + char(c);
|
||||
serial_len++;
|
||||
}
|
||||
Serial.println(serial_data);
|
||||
DeserializationError error = deserializeJson(doc, serial_data);
|
||||
// Test if parsing succeeds.
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
} else {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
theData[i].n = doc[i]["id0"];
|
||||
theData[i].d = doc[i]["id1"];
|
||||
theData[i].t = doc[i]["data0"];
|
||||
theData[i].h = doc[i]["data1"];
|
||||
}
|
||||
updateBlynk();
|
||||
}
|
||||
}
|
||||
|
||||
void updateBlynk() {
|
||||
Blynk.run();
|
||||
Blynk.virtualWrite(V1, theData[0].t);
|
||||
Blynk.virtualWrite(V3, theData[1].t);
|
||||
Blynk.virtualWrite(V5, theData[2].t);
|
||||
Blynk.virtualWrite(V7, theData[3].t);
|
||||
Blynk.virtualWrite(V9, theData[4].t);
|
||||
Blynk.virtualWrite(V11, theData[5].t);
|
||||
Blynk.virtualWrite(V2, theData[0].h);
|
||||
Blynk.virtualWrite(V4, theData[1].h);
|
||||
Blynk.virtualWrite(V6, theData[2].h);
|
||||
Blynk.virtualWrite(V8, theData[3].h);
|
||||
Blynk.virtualWrite(V10, theData[4].h);
|
||||
Blynk.virtualWrite(V12, theData[5].h);
|
||||
}
|
@ -1,126 +1,74 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions available in the "fdrs_config" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "fdrs_config.h"
|
||||
|
||||
#define STASSID "user"
|
||||
#define STAPSK "pass"
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "pool.ntp.org");
|
||||
|
||||
uint8_t prevAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, PREV_MAC};
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
|
||||
char auth[] = "";
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData[6];
|
||||
bool ledStatus = false;
|
||||
bool newData = false;
|
||||
bool failToggle = false;
|
||||
unsigned long signalTimeout = 60000 * 15;
|
||||
|
||||
// Callback when data is sent
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
Serial.print("Last Packet Send Status: ");
|
||||
if (sendStatus == 0) {
|
||||
Serial.println("Delivery success");
|
||||
ledStatus = true;
|
||||
}
|
||||
else {
|
||||
Serial.println("Delivery fail");
|
||||
ledStatus = false;
|
||||
}
|
||||
digitalWrite(LED_BUILTIN, ledStatus);
|
||||
}
|
||||
|
||||
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&theData, incomingData, sizeof(theData));
|
||||
Serial.print("Data received: ");
|
||||
Serial.println(len);
|
||||
Serial.print("Temp: ");
|
||||
Serial.println(theData[0].t);
|
||||
Serial.print("Humidity: ");
|
||||
Serial.println(theData[0].h);
|
||||
Serial.print("ID: ");
|
||||
Serial.println(theData[0].n);
|
||||
newData = true;
|
||||
|
||||
}
|
||||
void handleBlynk() {
|
||||
signalTimeout = millis() + 60000 * 15;
|
||||
failToggle = false;
|
||||
newData = false;
|
||||
Blynk.run();
|
||||
Blynk.virtualWrite(V1, theData[0].t);
|
||||
Blynk.virtualWrite(V3, theData[1].t);
|
||||
Blynk.virtualWrite(V5, theData[2].t);
|
||||
}
|
||||
void failBlynk() {
|
||||
failToggle = true;
|
||||
timeClient.update();
|
||||
unsigned long epochTime = timeClient.getEpochTime();
|
||||
struct tm *ptm = gmtime ((time_t *)&epochTime);
|
||||
int currentMonth = ptm->tm_mon + 1;
|
||||
int monthDay = ptm->tm_mday;
|
||||
String theOutput = String(currentMonth) + "." + String(monthDay) + "." + timeClient.getFormattedTime();
|
||||
Serial.print(theOutput);
|
||||
Blynk.virtualWrite(V1, "Fail");
|
||||
Blynk.virtualWrite(V3, "Mode");
|
||||
Blynk.virtualWrite(V5, theOutput);
|
||||
}
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
WiFi.mode(WIFI_STA);
|
||||
Serial.println();
|
||||
Serial.println("Sola Gratia FDRS Gateway");
|
||||
Serial.print("Original MAC: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
Serial.println("New MAC:" + WiFi.macAddress());
|
||||
Serial.print("Previous device: ");
|
||||
Serial.println(PREV_MAC);
|
||||
Blynk.begin(auth, ssid, password);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
// Once ESPNow is successfully Init, we will register for Send CB to
|
||||
// get the status of Trasnmitted packet
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
// Register peer
|
||||
esp_now_add_peer(prevAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
timeClient.begin();
|
||||
timeClient.setTimeOffset(-21600);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Blynk.run();
|
||||
if (newData) handleBlynk();
|
||||
if ((!failToggle ) && ( millis() > signalTimeout)) failBlynk();
|
||||
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions located in the "fdrs_config.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "fdrs_config.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
uint8_t prevAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, PREV_MAC};
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
byte d;
|
||||
|
||||
} DataReading;
|
||||
|
||||
|
||||
DataReading theData[6];
|
||||
|
||||
bool newData = false;
|
||||
|
||||
void encodeJSON() {
|
||||
StaticJsonDocument<512> doc;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
doc[i]["id0"] = theData[i].n;
|
||||
doc[i]["id1"] = theData[i].d;
|
||||
doc[i]["data0"] = theData[i].t;
|
||||
doc[i]["data1"] = theData[i].h;
|
||||
}
|
||||
serializeJson(doc, Serial);
|
||||
}
|
||||
|
||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
if (sendStatus == 0) {
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
void OnDataRecv(uint8_t* mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&theData, incomingData, sizeof(theData));
|
||||
newData = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
// Init WiFi and set MAC address
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
// Register peer
|
||||
esp_now_add_peer(prevAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (newData) {
|
||||
newData = false;
|
||||
encodeJSON();
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,33 @@
|
||||
// To configure FDRS:
|
||||
//
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and next in the line of communication.
|
||||
// Be sure that all unused lines are commented out.
|
||||
|
||||
// THIS UNIT
|
||||
//#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 0x01 // Relay 0
|
||||
#define PREV_MAC 0x02 // Relay 1
|
||||
//#define PREV_MAC 0x03 // Gateway
|
||||
//#define PREV_MAC 0x04 //
|
||||
// To configure FDRS:
|
||||
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and/or next in the line of communication.
|
||||
|
||||
// Each device in the system has a unique, one-byte address which
|
||||
// is assigned to the last digit of its MAC address at startup.
|
||||
|
||||
// Each device is configured to know what the previous and/or next
|
||||
// device in the line of communication is.
|
||||
|
||||
// The terminal is considered the "first" device, which can be addressed
|
||||
// to a relay or the gateway.
|
||||
|
||||
// Each relay receives data from its pre-programmed "PREV_MAC" device and
|
||||
// sends the packet verbatim to the address corresponding to "NEXT_MAC".
|
||||
|
||||
// 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 0x02 // Relay 1
|
||||
#define UNIT_MAC 0x03 // Gateway
|
||||
//#define UNIT_MAC 0x04 //
|
||||
|
||||
// PREVIOUS UNIT
|
||||
//#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 //
|
||||
|
@ -1,89 +1,82 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// RELAY MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions available in the "fdrs_config.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "fdrs_config.h"
|
||||
|
||||
uint8_t prevAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, PREV_MAC};
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
uint8_t nextAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, NEXT_MAC};
|
||||
uint8_t incMAC[6];
|
||||
uint8_t outMAC[6];
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData[6];
|
||||
bool newData = false;
|
||||
uint8_t senderMAC[12];
|
||||
|
||||
void passOn() {
|
||||
Serial.print("Packet Received from device: ");
|
||||
if (memcmp(&incMAC, &prevAddress, 6)) memcpy(&outMAC, &nextAddress, 6);
|
||||
if (memcmp(&incMAC, &nextAddress, 6)) memcpy(&outMAC, &prevAddress, 6);
|
||||
Serial.println(outMAC[5]);
|
||||
esp_now_send(outMAC, (uint8_t *) &theData, sizeof(theData));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void OnDataRecv(uint8_t* mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&theData, incomingData, sizeof(theData));
|
||||
memcpy(&incMAC, mac, sizeof(incMAC));
|
||||
Serial.print("Data received: ");
|
||||
Serial.println(len);
|
||||
newData = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
// Init WiFi and set MAC address
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
Serial.println();
|
||||
Serial.println("Sola Gratia FDRS Relay");
|
||||
Serial.print("Original MAC: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
Serial.println("New MAC:" + WiFi.macAddress());
|
||||
Serial.print("Previous device: ");
|
||||
Serial.println(PREV_MAC);
|
||||
Serial.print("Next device: ");
|
||||
Serial.println(NEXT_MAC);
|
||||
Serial.println(" ");
|
||||
// Init ESP-NOW
|
||||
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);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
// Register peer
|
||||
esp_now_add_peer(prevAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
esp_now_add_peer(nextAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (newData) {
|
||||
newData = false;
|
||||
passOn();
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// RELAY MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions located in the "fdrs_config.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "fdrs_config.h"
|
||||
|
||||
uint8_t prevAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, PREV_MAC};
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
uint8_t nextAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, NEXT_MAC};
|
||||
uint8_t incMAC[6];
|
||||
uint8_t outMAC[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
|
||||
|
||||
uint8_t theData[250];
|
||||
bool newData = false;
|
||||
|
||||
void passOn() {
|
||||
if (incMAC[5] == PREV_MAC) outMAC[5] = NEXT_MAC;
|
||||
if (incMAC[5] == NEXT_MAC) outMAC[5] = PREV_MAC;
|
||||
Serial.print("Packet Received from device: ");
|
||||
Serial.println(incMAC[5]);
|
||||
Serial.print("and sent to: ");
|
||||
Serial.println(outMAC[5]);
|
||||
|
||||
esp_now_send(outMAC, (uint8_t *) &theData, sizeof(theData));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void OnDataRecv(uint8_t* mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&theData, incomingData, sizeof(theData));
|
||||
memcpy(&incMAC, mac, sizeof(incMAC));
|
||||
Serial.print("Data received: ");
|
||||
Serial.println(len);
|
||||
newData = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
// Init WiFi and set MAC address
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
Serial.println();
|
||||
Serial.println("Sola Gratia FDRS Relay");
|
||||
Serial.println("New MAC:" + WiFi.macAddress());
|
||||
Serial.print("Previous device: ");
|
||||
Serial.println(PREV_MAC);
|
||||
Serial.print("Next device: ");
|
||||
Serial.println(NEXT_MAC);
|
||||
Serial.println(" ");
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
// Register peer
|
||||
esp_now_add_peer(prevAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
esp_now_add_peer(nextAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (newData) {
|
||||
newData = false;
|
||||
passOn();
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,41 @@
|
||||
// To configure FDRS:
|
||||
//
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and next in the line of communication.
|
||||
// Be sure that all unused lines are commented out.
|
||||
|
||||
// THIS UNIT
|
||||
//#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 0x01 // Relay 0
|
||||
//#define PREV_MAC 0x02 // Relay 1
|
||||
//#define PREV_MAC 0x03 // Gateway
|
||||
//#define PREV_MAC 0x04 //
|
||||
|
||||
// NEXT UNIT
|
||||
//#define NEXT_MAC 0x00 // Terminal
|
||||
//#define NEXT_MAC 0x01 // Relay 0
|
||||
//#define NEXT_MAC 0x02 // Relay 1
|
||||
#define NEXT_MAC 0x03 // Gateway
|
||||
//#define NEXT_MAC 0x04 //
|
||||
// To configure FDRS:
|
||||
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and/or next in the line of communication.
|
||||
|
||||
// Each device in the system has a unique, one-byte address which
|
||||
// is assigned to the last digit of its MAC address at startup.
|
||||
|
||||
// Each device is configured to know what the previous and/or next
|
||||
// device in the line of communication is.
|
||||
|
||||
// The terminal is considered the "first" device, which can be addressed
|
||||
// to a relay or the gateway.
|
||||
|
||||
// Each relay receives data from its pre-programmed "PREV_MAC" device and
|
||||
// sends the packet verbatim to the address corresponding to "NEXT_MAC".
|
||||
|
||||
// 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 0x02 // Relay 1
|
||||
//#define UNIT_MAC 0x03 // Gateway
|
||||
//#define UNIT_MAC 0x04 //
|
||||
|
||||
// PREVIOUS UNIT
|
||||
//#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 //
|
||||
|
||||
// NEXT UNIT
|
||||
//#define NEXT_MAC 0x00 // Terminal
|
||||
//#define NEXT_MAC 0x01 // Relay 0
|
||||
//#define NEXT_MAC 0x02 // Relay 1
|
||||
#define NEXT_MAC 0x03 // Gateway
|
||||
//#define NEXT_MAC 0x04 //
|
||||
|
@ -1,70 +1,83 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// DHT11/DHT22 SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions available in the "topography.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "DHTesp.h"
|
||||
#define SENSOR_ID 2
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x00};
|
||||
int next_send = 0;
|
||||
|
||||
DHTesp dht;
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData;
|
||||
|
||||
|
||||
// Callback when data is sent
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void loadData() {
|
||||
theData.h = dht.getHumidity();
|
||||
theData.t = dht.getTemperature() * 1.8 + 32;
|
||||
theData.n = SENSOR_ID;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
|
||||
// Once ESPNow is successfully Init, we will register for Send CB to
|
||||
// get the status of Trasnmitted packet
|
||||
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_SLAVE, 1, NULL, 0);
|
||||
dht.setup(2, DHTesp::DHT22);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > next_send) {
|
||||
loadData();
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
next_send = millis() + 15000;
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// DHT11/DHT22 SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a one-byte identifier.
|
||||
|
||||
#define SENSOR_ID 0
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "DHTesp.h"
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, TERM_MAC};
|
||||
int next_send = 0;
|
||||
|
||||
DHTesp dht;
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
byte d;
|
||||
|
||||
} DataReading;
|
||||
|
||||
DataReading theData;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void loadData() {
|
||||
float h = dht.getHumidity();
|
||||
float t = dht.getTemperature();
|
||||
if (!(isnan(h) || isnan(t))) {
|
||||
theData.h = h;
|
||||
theData.t = t * 1.8 + 32;
|
||||
theData.n = SENSOR_ID;
|
||||
theData.d = 1;
|
||||
}else{
|
||||
theData.h = -4.20;
|
||||
theData.t = -69.00;
|
||||
theData.n = SENSOR_ID;
|
||||
theData.d = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
|
||||
// Once ESPNow is successfully Init, we will register for Send CB to
|
||||
// get the status of Trasnmitted packet
|
||||
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_SLAVE, 1, NULL, 0);
|
||||
dht.setup(2, DHTesp::DHT22);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > next_send) {
|
||||
loadData();
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
next_send = millis() + 15000;
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,72 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// DALLAS DS18B20 SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions available in the "topography.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#define ONE_WIRE_BUS 2
|
||||
#define SENSOR_ID 3
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x00};
|
||||
int next_send = 0;
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData;
|
||||
|
||||
|
||||
// Callback when data is sent
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void loadData() {
|
||||
sensors.requestTemperatures();
|
||||
theData.h = 0;
|
||||
theData.t = sensors.getTempFByIndex(0);
|
||||
theData.n = SENSOR_ID;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
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_SLAVE, 1, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > next_send) {
|
||||
loadData();
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
next_send = millis() + 15000;
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// DALLAS DS18B20 SENSOR MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Each sensor is assigned a one-byte identifier.
|
||||
|
||||
#define SENSOR_ID 3
|
||||
#define TERM_MAC 0x00 //Terminal MAC
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#define ONE_WIRE_BUS 2
|
||||
|
||||
|
||||
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0x00};
|
||||
int next_send = 0;
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading theData;
|
||||
|
||||
|
||||
// Callback when data is sent
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void loadData() {
|
||||
sensors.requestTemperatures();
|
||||
theData.h = 0;
|
||||
theData.t = sensors.getTempFByIndex(0);
|
||||
theData.n = SENSOR_ID;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
// Init ESP-NOW
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
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_SLAVE, 1, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > next_send) {
|
||||
loadData();
|
||||
esp_now_send(broadcastAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
next_send = millis() + 15000;
|
||||
}
|
||||
}
|
||||
|
@ -1,85 +1,92 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// TERMINAL MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions available in the "fdrs_config.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "fdrs_config.h"
|
||||
|
||||
#define DELAY 60000
|
||||
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
uint8_t nextAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, NEXT_MAC};
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
} DataReading;
|
||||
|
||||
DataReading incData;
|
||||
DataReading theData[6];
|
||||
|
||||
bool newData = false;
|
||||
int wait_time = 0;
|
||||
|
||||
void passForward() {
|
||||
Serial.println("Passing On");
|
||||
esp_now_send(nextAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&incData, incomingData, sizeof(incData));
|
||||
theData[incData.n] = incData;
|
||||
Serial.println(":Packet:");
|
||||
Serial.print("Temp:");
|
||||
Serial.println(incData.t);
|
||||
Serial.print("Humidity:");
|
||||
Serial.println(incData.h);
|
||||
Serial.print("ID:");
|
||||
Serial.println(incData.n);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
//Init WiFi and set MAC address
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
Serial.println();
|
||||
Serial.println("Sola Gratia FDRS Terminal");
|
||||
Serial.print("Original MAC: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
Serial.println("New MAC:" + WiFi.macAddress());
|
||||
Serial.print("Next device: ");
|
||||
Serial.println(NEXT_MAC);
|
||||
// Init ESP-NOW
|
||||
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);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
esp_now_add_peer(nextAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > wait_time) {
|
||||
wait_time = wait_time + DELAY;
|
||||
passForward();
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// TERMINAL MODULE
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions located in the "fdrs_config.h" file.
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#include "fdrs_config.h"
|
||||
|
||||
#define DELAY 5000
|
||||
|
||||
uint8_t selfAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, UNIT_MAC};
|
||||
uint8_t nextAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, NEXT_MAC};
|
||||
|
||||
typedef struct DataReading {
|
||||
float t;
|
||||
float h;
|
||||
byte n;
|
||||
byte d;
|
||||
} DataReading;
|
||||
|
||||
DataReading incData;
|
||||
DataReading theData[6];
|
||||
|
||||
bool newData = false;
|
||||
int wait_time = 0;
|
||||
|
||||
void passForward() {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
theData[i].n = i;
|
||||
theData[i].d = i;
|
||||
theData[i].t = 3.2*i;
|
||||
theData[i].h = 2.1*i;
|
||||
}
|
||||
Serial.println("Passing On");
|
||||
esp_now_send(nextAddress, (uint8_t *) &theData, sizeof(theData));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||
memcpy(&incData, incomingData, sizeof(incData));
|
||||
theData[incData.n] = incData;
|
||||
Serial.println(":Packet:");
|
||||
Serial.print("Temp:");
|
||||
Serial.println(incData.t);
|
||||
Serial.print("Humidity:");
|
||||
Serial.println(incData.h);
|
||||
Serial.print("ID:");
|
||||
Serial.println(incData.n);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Init Serial Monitor
|
||||
Serial.begin(115200);
|
||||
//Init WiFi and set MAC address
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
Serial.println();
|
||||
Serial.println("Sola Gratia FDRS Terminal");
|
||||
Serial.print("Original MAC: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
wifi_set_macaddr(STATION_IF, selfAddress);
|
||||
Serial.println("New MAC:" + WiFi.macAddress());
|
||||
Serial.print("Next device: ");
|
||||
Serial.println(NEXT_MAC);
|
||||
// Init ESP-NOW
|
||||
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);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
esp_now_add_peer(nextAddress, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() > wait_time) {
|
||||
wait_time = wait_time + DELAY;
|
||||
passForward();
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,33 @@
|
||||
// To configure FDRS:
|
||||
//
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and next in the line of communication.
|
||||
// Be sure that all unused lines are commented out.
|
||||
|
||||
// THIS UNIT
|
||||
#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 //
|
||||
|
||||
// NEXT UNIT
|
||||
//#define NEXT_MAC 0x00 // Terminal
|
||||
#define NEXT_MAC 0x01 // Relay 0
|
||||
//#define NEXT_MAC 0x02 // Relay 1
|
||||
//#define NEXT_MAC 0x03 // Gateway
|
||||
//#define NEXT_MAC 0x04 //
|
||||
// To configure FDRS:
|
||||
|
||||
// Uncomment the code corresponding to the unit you are configuring,
|
||||
// then uncomment the code corresponding to the unit you would like
|
||||
// to be previous and/or next in the line of communication.
|
||||
|
||||
// Each device in the system has a unique, one-byte address which
|
||||
// is assigned to the last digit of its MAC address at startup.
|
||||
|
||||
// Each device is configured to know what the previous and/or next
|
||||
// device in the line of communication is.
|
||||
|
||||
// The terminal is considered the "first" device, which can be addressed
|
||||
// to a relay or the gateway.
|
||||
|
||||
// Each relay receives data from its pre-programmed "PREV_MAC" device and
|
||||
// sends the packet verbatim to the address corresponding to "NEXT_MAC".
|
||||
|
||||
// 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 0x02 // Relay 1
|
||||
//#define UNIT_MAC 0x03 // Gateway
|
||||
//#define UNIT_MAC 0x04 //
|
||||
|
||||
// NEXT UNIT
|
||||
//#define NEXT_MAC 0x00 // Terminal
|
||||
#define NEXT_MAC 0x01 // Relay 0
|
||||
//#define NEXT_MAC 0x02 // Relay 1
|
||||
//#define NEXT_MAC 0x03 // Gateway
|
||||
//#define NEXT_MAC 0x04 //
|
||||
|
Loading…
Reference in New Issue
Block a user