mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Add files via upload
This commit is contained in:
parent
bab95d98bf
commit
2d9c0672dc
@ -1,9 +1,10 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
// This is still in progress. Stay tuned!
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// Setup instructions located in the "fdrs_config.h" file.
|
||||
//
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -19,9 +20,9 @@
|
||||
#include <PubSubClient.h>
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
const char* ssid = "";
|
||||
const char* password = "";
|
||||
const char* mqtt_server = "192.168.0.8";
|
||||
const char* ssid = WIFI_NET;
|
||||
const char* password = WIFI_PASS;
|
||||
const char* mqtt_server = MQTT_ADDR;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@ -46,23 +47,19 @@ void loop() {
|
||||
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
sendESPNOW(2);
|
||||
sendSerial();
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
sendESPNOW(1);
|
||||
sendSerial();
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
sendSerial();
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
sendESPNOW(0);
|
||||
sendSerial();
|
||||
sendMQTT();
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
sendSerial();
|
||||
MQTT_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
|
@ -1,21 +1,29 @@
|
||||
// To configure FDRS:
|
||||
|
||||
// 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 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.
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
// This is still in progress. Stay tuned!
|
||||
|
||||
//#define USE_WIFI //You cannot use ESP-NOW while WiFi is in use
|
||||
#define USE_LORA
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
// THIS UNIT
|
||||
#define UNIT_MAC 0x00
|
||||
#define USE_LORA //Coming soon
|
||||
|
||||
// NEXT UNIT
|
||||
#define NEXT_MAC 0x02
|
||||
#define UNIT_MAC 0x00// THIS UNIT
|
||||
#define PREV_MAC 0x01// ESPNOW1 Address
|
||||
#define NEXT_MAC 0x02// ESPNOW2 Address
|
||||
|
||||
// PREVIOUS UNIT
|
||||
#define PREV_MAC 0x01
|
||||
//Actions -- Define what happens when a message arrives.
|
||||
|
||||
#define ESPNOW1_ACT sendESPNOW(2); sendSerial();
|
||||
#define ESPNOW2_ACT sendESPNOW(1); sendSerial();
|
||||
#define ESPNOWG_ACT sendSerial();
|
||||
#define SERIAL_ACT sendESPNOW(0);
|
||||
#define MQTT_ACT sendSerial();
|
||||
|
||||
//#define ESPNOW1_ACTION
|
||||
//#define ESPNOW2_ACTION
|
||||
//#define ESPNOWG_ACTION
|
||||
//#define SERIAL_ACTION sendMQTT();
|
||||
//#define MQTT_ACTION sendSerial();
|
||||
|
@ -108,6 +108,7 @@ void sendESPNOW(uint8_t interface) {
|
||||
|
||||
}
|
||||
void sendMQTT() {
|
||||
#ifdef USE_WIFI
|
||||
StaticJsonDocument<2048> doc;
|
||||
for (int i = 0; i < ln / sizeof(DataReading); i++) {
|
||||
doc[i]["id"] = theData[i].id;
|
||||
@ -117,6 +118,7 @@ void sendMQTT() {
|
||||
String incomingString;
|
||||
serializeJson(doc, incomingString);
|
||||
client.publish("esp/fdrs", (char*) incomingString.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void sendSerial() {
|
||||
|
Loading…
Reference in New Issue
Block a user