mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
intermediate step: examples folder must be fully lower cases
This commit is contained in:
parent
6793750a78
commit
c6c477e681
@ -1,33 +1,33 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// Basic Sensor Example
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1;
|
||||
float data2;
|
||||
|
||||
void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// Basic Sensor Example
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1;
|
||||
float data2;
|
||||
|
||||
void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
@ -1,32 +1,32 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// Basic Sensor Example
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1;
|
||||
float data2;
|
||||
|
||||
void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// Basic Sensor Example
|
||||
//
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1;
|
||||
float data2;
|
||||
|
||||
void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
@ -1,169 +1,169 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
@ -1,78 +1,78 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG
|
||||
|
||||
#define UNIT_MAC 0x03 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||
|
||||
#define ESPNOWG_ACT sendESPNOW(0x04);
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG
|
||||
|
||||
#define UNIT_MAC 0x03 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||
|
||||
#define ESPNOWG_ACT sendESPNOW(0x04);
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
@ -1,169 +1,169 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
@ -1,78 +1,78 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG
|
||||
|
||||
#define UNIT_MAC 0x04 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||
|
||||
#define ESPNOWG_ACT sendSerial();
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT sendSerial();
|
||||
|
||||
#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG
|
||||
|
||||
#define UNIT_MAC 0x04 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||
|
||||
#define ESPNOWG_ACT sendSerial();
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT sendSerial();
|
||||
|
||||
#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
@ -1,169 +1,169 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#include "fdrs_config.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
#elif defined(ESP32)
|
||||
#include <esp_now.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#endif
|
||||
#include <ArduinoJson.h>
|
||||
#ifdef USE_WIFI
|
||||
#include <PubSubClient.h>
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
#ifdef USE_LED
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
#elif defined(ESP32)
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
||||
#ifdef USE_LED
|
||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||
leds[0] = CRGB::Blue;
|
||||
FastLED.show();
|
||||
#endif
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
DBG("Connecting to WiFi...");
|
||||
DBG(FDRS_WIFI_SSID);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
DBG("WiFi Connected");
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
DBG("MQTT Connected");
|
||||
client.setCallback(mqtt_callback);
|
||||
#else
|
||||
begin_espnow();
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(FDRS_BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(FDRS_SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
|
||||
//DBG(sizeof(DataReading));
|
||||
#ifdef USE_WIFI
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef ESPNOWG_DELAY
|
||||
if (millis() > timeESPNOWG) {
|
||||
timeESPNOWG += ESPNOWG_DELAY;
|
||||
if (lenESPNOWG > 0) releaseESPNOW(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW1_DELAY
|
||||
if (millis() > timeESPNOW1) {
|
||||
timeESPNOW1 += ESPNOW1_DELAY;
|
||||
if (lenESPNOW1 > 0) releaseESPNOW(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPNOW2_DELAY
|
||||
if (millis() > timeESPNOW2) {
|
||||
timeESPNOW2 += ESPNOW2_DELAY;
|
||||
if (lenESPNOW2 > 0) releaseESPNOW(2);
|
||||
}
|
||||
#endif
|
||||
#ifdef SERIAL_DELAY
|
||||
if (millis() > timeSERIAL) {
|
||||
timeSERIAL += SERIAL_DELAY;
|
||||
if (lenSERIAL > 0) releaseSerial();
|
||||
}
|
||||
#endif
|
||||
#ifdef MQTT_DELAY
|
||||
if (millis() > timeMQTT) {
|
||||
timeMQTT += MQTT_DELAY;
|
||||
if (lenMQTT > 0) releaseMQTT();
|
||||
}
|
||||
#endif
|
||||
#ifdef LORAG_DELAY
|
||||
if (millis() > timeLORAG) {
|
||||
timeLORAG += LORAG_DELAY;
|
||||
if (lenLORAG > 0) releaseLoRa(0);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA1_DELAY
|
||||
if (millis() > timeLORA1) {
|
||||
timeLORA1 += LORA1_DELAY;
|
||||
if (lenLORA1 > 0) releaseLoRa(1);
|
||||
}
|
||||
#endif
|
||||
#ifdef LORA2_DELAY
|
||||
if (millis() > timeLORA2) {
|
||||
timeLORA2 += LORA2_DELAY;
|
||||
if (lenLORA2 > 0) releaseLoRa(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (UART_IF.available()) {
|
||||
getSerial();
|
||||
}
|
||||
getLoRa();
|
||||
#ifdef USE_WIFI
|
||||
if (!client.connected()) {
|
||||
DBG("Connecting MQTT...");
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
#endif
|
||||
if (newData) {
|
||||
switch (newData) {
|
||||
case 1: //ESP-NOW #1
|
||||
ESPNOW1_ACT
|
||||
break;
|
||||
case 2: //ESP-NOW #2
|
||||
ESPNOW2_ACT
|
||||
break;
|
||||
case 3: //ESP-NOW General
|
||||
ESPNOWG_ACT
|
||||
break;
|
||||
case 4: //Serial
|
||||
SERIAL_ACT
|
||||
break;
|
||||
case 5: //MQTT
|
||||
MQTT_ACT
|
||||
break;
|
||||
case 6: //LoRa General
|
||||
LORAG_ACT
|
||||
break;
|
||||
case 7: //LoRa #1
|
||||
LORA1_ACT
|
||||
break;
|
||||
case 8: //LoRa #2
|
||||
LORA2_ACT
|
||||
break;
|
||||
}
|
||||
newData = 0;
|
||||
}
|
||||
}
|
@ -1,80 +1,80 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG //Enable debugging information over serial
|
||||
|
||||
#define UNIT_MAC 0x05 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(),
|
||||
// bufferLoRa(interface), bufferESPNOW(interface), bufferSerial(), and bufferMQTT().
|
||||
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT sendMQTT();
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds - Uncomment to enable any buffer
|
||||
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
//#include <fdrs_globals.h> //Uncomment if you install the globals file
|
||||
#define DEBUG //Enable debugging information over serial
|
||||
|
||||
#define UNIT_MAC 0x05 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(),
|
||||
// bufferLoRa(interface), bufferESPNOW(interface), bufferSerial(), and bufferMQTT().
|
||||
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT sendMQTT();
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
// Peer addresses
|
||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0x0F // ESPNOW2 Address
|
||||
#define LORA1_PEER 0x0E // LoRa1 Address
|
||||
#define LORA2_PEER 0x0F // LoRa2 Address
|
||||
|
||||
// Peer Actions
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//Pins for UART data interface (ESP32 only)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
|
||||
//LoRa Configuration -- Needed only if using LoRa
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
|
||||
// Buffer Delays - in milliseconds - Uncomment to enable any buffer
|
||||
|
||||
//#define ESPNOW1_DELAY 0
|
||||
//#define ESPNOW2_DELAY 0
|
||||
//#define ESPNOWG_DELAY 0
|
||||
//#define SERIAL_DELAY 0
|
||||
//#define MQTT_DELAY 0
|
||||
#define LORAG_DELAY 1000
|
||||
//#define LORA1_DELAY 1000
|
||||
//#define LORA2_DELAY 1000
|
||||
|
||||
//#define USE_LED //Not yet fully implemented
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
|
||||
#define WIFI_SSID "Your SSID"
|
||||
#define WIFI_PASS "Your Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||
|
||||
//MQTT Credentials -- Needed only if MQTT broker requires authentication
|
||||
//#define MQTT_AUTH //uncomment to enable MQTT authentication
|
||||
#define MQTT_USER "Your MQTT Username"
|
||||
#define MQTT_PASS "Your MQTT Password"
|
||||
|
||||
// MQTT Topics
|
||||
#define TOPIC_DATA "fdrs/data"
|
||||
#define TOPIC_STATUS "fdrs/status"
|
||||
#define TOPIC_COMMAND "fdrs/command"
|
Loading…
Reference in New Issue
Block a user