mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
commit
feb09755d2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
Examples/FDRS_common_files/FDRScredentials.h
|
@ -6,20 +6,30 @@
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#define ROLE LORA_SENSOR
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1 = 42.069;
|
||||
float data2 = 21.0345;
|
||||
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;
|
||||
}
|
||||
|
@ -4,73 +4,7 @@
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
#define READING_ID 1 //Unique ID for this sensor
|
||||
#define GTWY_MAC 0x00 //Address of the nearest gateway
|
||||
|
||||
//#define USE_ESPNOW
|
||||
#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#define WIFI_NET mySSID
|
||||
#define WIFI_PASS myPASSWORD
|
||||
#define MQTT_ADDR MQTT_BROKER
|
||||
#define BAND myBAND
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define SOILR_T 8 // Soil Resistance
|
||||
#define SOILR2_T 9 // Soil Resistance #2
|
||||
#define OXYGEN_T 10 // Oxygen
|
||||
#define CO2_T 11 // Carbon Dioxide
|
||||
#define WINDSPD_T 12 // Wind Speed
|
||||
#define WINDHDG_T 13 // Wind Direction
|
||||
#define RAINFALL_T 14 // Rainfall
|
||||
#define MOTION_T 15 // Motion
|
||||
#define VOLTAGE_T 16 // Voltage
|
||||
#define VOLTAGE2_T 17 // Voltage #2
|
||||
#define CURRENT_T 18 // Current
|
||||
#define CURRENT2_T 19 // Current #2
|
||||
#define IT_T 20 // Iterations
|
||||
|
||||
|
||||
#include "sensor_setup.h"
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
@ -84,19 +18,16 @@ typedef struct __attribute__((packed)) DataReading {
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
|
||||
#define DBG(a)
|
||||
#ifdef ESP8266
|
||||
#define UART_IF Serial
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#endif
|
||||
#endif
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
||||
|
||||
|
||||
uint32_t wait_time = 0;
|
||||
@ -147,6 +78,7 @@ void beginFDRS() {
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
DBG(SF);
|
||||
#ifndef __AVR__
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
#endif
|
||||
@ -154,13 +86,14 @@ void beginFDRS() {
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(SF);
|
||||
DBG(" LoRa Initialized.");
|
||||
#endif
|
||||
}
|
||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||
#ifdef USE_LORA
|
||||
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
||||
memcpy(&pkt, mac, 3);
|
||||
memcpy(&pkt, mac, 3); //
|
||||
memcpy(&pkt[3], &LoRaAddress, 2);
|
||||
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
||||
LoRa.beginPacket();
|
||||
|
16
Examples/1_LoRa_Sensor/sensor_setup.h
Normal file
16
Examples/1_LoRa_Sensor/sensor_setup.h
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
#define READING_ID 1 //Unique ID for this sensor
|
||||
#define GTWY_MAC 0x04 //Address of the nearest gateway
|
||||
|
||||
//#define USE_ESPNOW
|
||||
#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
|
||||
//LoRa Configuration
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
@ -7,9 +7,9 @@
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#define ESPNOW_SENSOR
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1;
|
||||
@ -19,18 +19,18 @@ void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1=readHum();
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2=readTemp();
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp(){
|
||||
return 42.069;
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum(){
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
||||
|
16
Examples/2_ESPNOW_Sensor/Sensor_setup.h
Normal file
16
Examples/2_ESPNOW_Sensor/Sensor_setup.h
Normal file
@ -0,0 +1,16 @@
|
||||
#define READING_ID 2 //Unique ID for this sensor
|
||||
#define GTWY_MAC 0x03 //Address of the nearest gateway
|
||||
|
||||
#define USE_ESPNOW
|
||||
//#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
//#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
@ -3,71 +3,8 @@
|
||||
// "fdrs_sensor.h"
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
#define READING_ID 2 //Unique ID for this sensor
|
||||
#define GTWY_MAC 0x00 //Address of the nearest gateway
|
||||
|
||||
#define USE_ESPNOW
|
||||
//#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
#define DEBUG
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#define WIFI_NET mySSID
|
||||
#define WIFI_PASS myPASSWORD
|
||||
#define MQTT_ADDR MQTT_BROKER
|
||||
#define BAND myBAND
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define SOILR_T 8 // Soil Resistance
|
||||
#define SOILR2_T 9 // Soil Resistance #2
|
||||
#define OXYGEN_T 10 // Oxygen
|
||||
#define CO2_T 11 // Carbon Dioxide
|
||||
#define WINDSPD_T 12 // Wind Speed
|
||||
#define WINDHDG_T 13 // Wind Direction
|
||||
#define RAINFALL_T 14 // Rainfall
|
||||
#define MOTION_T 15 // Motion
|
||||
#define VOLTAGE_T 16 // Voltage
|
||||
#define VOLTAGE2_T 17 // Voltage #2
|
||||
#define CURRENT_T 18 // Current
|
||||
#define CURRENT2_T 19 // Current #2
|
||||
#define IT_T 20 // Iterations
|
||||
|
||||
//
|
||||
#include "sensor_setup.h"
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -82,16 +19,16 @@ typedef struct __attribute__((packed)) DataReading {
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
||||
|
||||
|
||||
uint32_t wait_time = 0;
|
||||
@ -141,6 +78,8 @@ void beginFDRS() {
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
DBG(SF);
|
||||
#ifndef __AVR__
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
#endif
|
||||
@ -148,6 +87,7 @@ void beginFDRS() {
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(SF);
|
||||
DBG(" LoRa Initialized.");
|
||||
#endif
|
||||
}
|
||||
|
@ -5,12 +5,11 @@
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#define CREDENTIALS
|
||||
#define DEBUG
|
||||
|
||||
#define ROLE ESPNOW_GATEWAY
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
@ -30,9 +29,6 @@
|
||||
#include <FastLED.h>
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
//#ifdef CREDENTIALS
|
||||
//#include <credentials.h>
|
||||
//#endif
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
|
@ -1,29 +0,0 @@
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
//Type definitions in progress:
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define OXYGEN_T 8 // Oxygen
|
||||
#define CO2_T 9 // Carbon Dioxide
|
||||
#define WINDSPD_T 10 // Wind Speed
|
||||
#define WINDHDG_T 11 // Wind Direction
|
||||
#define RAINFALL_T 12 // Rainfall
|
||||
#define MOTION_T 13 // Motion
|
||||
#define VOLTAGE_T 14 // Voltage
|
||||
#define VOLTAGE2_T 15 // Voltage #2
|
||||
#define CURRENT_T 16 // Current
|
||||
#define CURRENT2_T 17 // Current #2
|
||||
#define IT_T 18 // Iterations
|
@ -1,45 +0,0 @@
|
||||
#define UNIT_MAC 0xFC // THIS UNIT
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
#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 ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define RXD2 21
|
||||
//#define TXD2 22
|
||||
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//#define USE_LORA
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
//#define USE_LED
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
#define UART_IF Serial1
|
@ -2,22 +2,27 @@
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
#include "defaults.h"
|
||||
|
||||
#define UNIT_MAC 0x01 // The address of this gateway
|
||||
#define UNIT_MAC 0x03 // The address of this gateway
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
//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(0x00);
|
||||
#define ESPNOWG_ACT sendESPNOW(0x04);
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
#define LORAG_ACT
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
#define CREDENTIALS
|
||||
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
@ -34,20 +39,3 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#define WIFI_NET mySSID
|
||||
#define WIFI_PASS myPASSWORD
|
||||
#define MQTT_ADDR MQTT_BROKER
|
||||
#define BAND myBAND
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
@ -4,10 +4,19 @@
|
||||
#define DBG(a)
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
// esp_now_peer_info_t peerInfo;
|
||||
#if defined (ESP32)
|
||||
esp_now_peer_info_t peerInfo;
|
||||
#endif
|
||||
|
||||
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||
|
@ -5,10 +5,10 @@
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#define ROLE UART_GATEWAY
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
@ -64,11 +64,13 @@ void setup() {
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
DBG(SF);
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(SF);
|
||||
DBG(" LoRa initialized.");
|
||||
#endif
|
||||
// UART_IF.println(sizeof(DataReading));
|
||||
|
@ -1,29 +0,0 @@
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
//Type definitions in progress:
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define OXYGEN_T 8 // Oxygen
|
||||
#define CO2_T 9 // Carbon Dioxide
|
||||
#define WINDSPD_T 10 // Wind Speed
|
||||
#define WINDHDG_T 11 // Wind Direction
|
||||
#define RAINFALL_T 12 // Rainfall
|
||||
#define MOTION_T 13 // Motion
|
||||
#define VOLTAGE_T 14 // Voltage
|
||||
#define VOLTAGE2_T 15 // Voltage #2
|
||||
#define CURRENT_T 16 // Current
|
||||
#define CURRENT2_T 17 // Current #2
|
||||
#define IT_T 18 // Iterations
|
@ -1,40 +0,0 @@
|
||||
#define UNIT_MAC 0xFC // THIS UNIT
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
#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 ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define RXD2 21
|
||||
//#define TXD2 22
|
||||
|
||||
//#define USE_LORA
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
//#define USE_LED
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
@ -2,28 +2,34 @@
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
#include "defaults.h"
|
||||
|
||||
#define UNIT_MAC 0x00 // The address of this gateway
|
||||
#define UNIT_MAC 0x04 // The address of this gateway
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
//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 ESPNOWG_ACT sendSerial();
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT sendSerial();
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
#define CREDENTIALS
|
||||
#define CREDENTIALS
|
||||
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
#define UART_IF Serial2
|
||||
#else
|
||||
#else
|
||||
#define UART_IF Serial
|
||||
#endif
|
||||
|
||||
@ -34,23 +40,3 @@
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
//WiFi Configuration -- Needed only if is using MQTT
|
||||
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#define WIFI_NET mySSID
|
||||
#define WIFI_PASS myPASSWORD
|
||||
#define MQTT_ADDR MQTT_BROKER
|
||||
#define BAND myBAND
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
@ -3,10 +3,20 @@
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
esp_now_peer_info_t peerInfo;
|
||||
#if defined(ESP32)
|
||||
esp_now_peer_info_t peerInfo;
|
||||
#endif
|
||||
|
||||
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||
@ -130,19 +140,25 @@ void getLoRa() {
|
||||
uint8_t packet[packetSize];
|
||||
uint8_t incLORAMAC[2];
|
||||
LoRa.readBytes((uint8_t *)&packet, packetSize);
|
||||
// for (int i = 0; i < packetSize; i++) {
|
||||
// UART_IF.println(packet[i], HEX);
|
||||
// }
|
||||
for (int i = 0; i < packetSize; i++) {
|
||||
Serial.println(packet[i], HEX);
|
||||
}
|
||||
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
|
||||
DBG("Packet for me");
|
||||
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
|
||||
memcpy(&theData, &packet[5], packetSize - 5); //Split off data portion of packet
|
||||
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) newData = 7; //Check if it is from a registered sender
|
||||
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) {
|
||||
newData = 7; //Check if it is from a registered sender
|
||||
DBG("From Registred sender");
|
||||
}
|
||||
else if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) newData = 8;
|
||||
else newData = 6;
|
||||
DBG (newData);
|
||||
ln = (packetSize - 5) / sizeof(DataReading);
|
||||
newData = 6;
|
||||
DBG("Incoming LoRa.");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -470,7 +486,7 @@ void begin_espnow() {
|
||||
}
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
esp_now_register_recv_cb(OnDataRecv);
|
||||
|
||||
|
||||
peerInfo.channel = 0;
|
||||
peerInfo.encrypt = false;
|
||||
// Register first peer
|
||||
@ -479,7 +495,7 @@ void begin_espnow() {
|
||||
DBG("Failed to add peer bcast");
|
||||
return;
|
||||
}
|
||||
memcpy(peerInfo.peer_addr, ESPNOW1, 6);
|
||||
memcpy(peerInfo.peer_addr, ESPNOW1, 6);
|
||||
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
|
||||
DBG("Failed to add peer 1");
|
||||
return;
|
||||
@ -491,5 +507,4 @@ void begin_espnow() {
|
||||
}
|
||||
#endif
|
||||
DBG(" ESP-NOW Initialized.");
|
||||
DBG(WIFI_NET);
|
||||
}
|
||||
|
@ -6,11 +6,10 @@
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#define ROLE MQTT_GATEWAY
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_config.h"
|
||||
#include "DataReading.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -32,7 +31,6 @@
|
||||
#endif
|
||||
#include "fdrs_functions.h"
|
||||
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(115200);
|
||||
@ -75,7 +73,7 @@ void setup() {
|
||||
#endif
|
||||
// UART_IF.println(sizeof(DataReading));
|
||||
|
||||
client.publish("esp/fdrs/status", "FDRS initialized");
|
||||
client.publish(TOPIC_STATUS, "FDRS initialized");
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
//Type definitions in progress:
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define OXYGEN_T 8 // Oxygen
|
||||
#define CO2_T 9 // Carbon Dioxide
|
||||
#define WINDSPD_T 10 // Wind Speed
|
||||
#define WINDHDG_T 11 // Wind Direction
|
||||
#define RAINFALL_T 12 // Rainfall
|
||||
#define MOTION_T 13 // Motion
|
||||
#define VOLTAGE_T 14 // Voltage
|
||||
#define VOLTAGE2_T 15 // Voltage #2
|
||||
#define CURRENT_T 16 // Current
|
||||
#define CURRENT2_T 17 // Current #2
|
||||
#define IT_T 18 // Iterations
|
@ -1,41 +0,0 @@
|
||||
#define UNIT_MAC 0xFC // THIS UNIT
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
#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 ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define USE_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 USE_LED
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
@ -2,53 +2,39 @@
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
#include "defaults.h"
|
||||
|
||||
//#define UNIT_MAC 0x00 // The address of this gateway
|
||||
#define UNIT_MAC 0x05 // The address of this gateway
|
||||
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFD // LoRa1 Address
|
||||
#define LORA2_PEER 0xFE // LoRa2 Address
|
||||
|
||||
//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
|
||||
#define SERIAL_ACT sendMQTT();
|
||||
|
||||
#define ESPNOWG_ACT
|
||||
#define SERIAL_ACT sendMQTT();
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
#define LORAG_ACT
|
||||
#define ESPNOW1_ACT
|
||||
#define ESPNOW2_ACT
|
||||
#define LORA1_ACT
|
||||
#define LORA2_ACT
|
||||
|
||||
//#define USE_LORA
|
||||
//#define USE_LORA
|
||||
#define USE_WIFI //Used only for MQTT gateway
|
||||
|
||||
#define CREDENTIALS
|
||||
|
||||
#if defined (ESP32)
|
||||
#define RXD2 14
|
||||
#define TXD2 15
|
||||
#define UART_IF Serial1
|
||||
#else
|
||||
#else
|
||||
#define UART_IF Serial
|
||||
#endif
|
||||
|
||||
////LoRa Configuration -- Needed only if using LoRa
|
||||
////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
|
||||
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <credentials.h>
|
||||
#define WIFI_NET mySSID
|
||||
#define WIFI_PASS myPASSWORD
|
||||
#define MQTT_ADDR MQTT_BROKER
|
||||
#define BAND myBAND
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
|
||||
//433E6 for Asia
|
||||
//866E6 for Europe
|
||||
//915E6 for North America
|
||||
#define BAND 915E6
|
||||
#endif
|
||||
|
@ -3,6 +3,14 @@
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
||||
} DataReading;
|
||||
|
||||
const uint8_t espnow_size = 250 / sizeof(DataReading);
|
||||
const uint8_t lora_size = 256 / sizeof(DataReading);
|
||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
@ -206,7 +214,7 @@ void sendMQTT() {
|
||||
}
|
||||
String outgoingString;
|
||||
serializeJson(doc, outgoingString);
|
||||
client.publish("esp/fdrs", (char*) outgoingString.c_str());
|
||||
client.publish(TOPIC_DATA, (char*) outgoingString.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -427,7 +435,7 @@ void releaseMQTT() {
|
||||
}
|
||||
String outgoingString;
|
||||
serializeJson(doc, outgoingString);
|
||||
client.publish("esp/fdrs", (char*) outgoingString.c_str());
|
||||
client.publish(TOPIC_DATA, (char*) outgoingString.c_str());
|
||||
lenMQTT = 0;
|
||||
#endif
|
||||
}
|
||||
@ -438,7 +446,7 @@ void reconnect() {
|
||||
// Attempt to connect
|
||||
if (client.connect("FDRS_GATEWAY")) {
|
||||
// Subscribe
|
||||
client.subscribe("esp/fdrs");
|
||||
client.subscribe(TOPIC_COMMAND);
|
||||
} else {
|
||||
DBG("Connecting MQTT.");
|
||||
delay(5000);
|
||||
|
11
Examples/FDRS_common_files/Explanation.txt
Normal file
11
Examples/FDRS_common_files/Explanation.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Please copy the "FDRS_common_files" directory to your Arduino library directory
|
||||
add a file "FDRScredentials.h" to this directory with this content:
|
||||
|
||||
#define my_SSID ""
|
||||
#define my_PASSWORD ""
|
||||
#define my_MQTT_BROKER "192.168.0.203"
|
||||
|
||||
#define my_BAND 433.2E6
|
||||
#define my_SF 7
|
||||
|
||||
Fill in your stuff and save it
|
74
Examples/FDRS_common_files/FDRSdefaults.h
Normal file
74
Examples/FDRS_common_files/FDRSdefaults.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifdef DEBUG
|
||||
#define DBG(a) (Serial.println(a))
|
||||
#else
|
||||
#define DBG(a)
|
||||
#endif
|
||||
|
||||
#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_LORA
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
uint8_t LoRaAddress[] = {0x42, 0x00}; //Do not touch!!!
|
||||
|
||||
//#define USE_LED
|
||||
#define LED_PIN 32
|
||||
#define NUM_LEDS 4
|
||||
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // do not touch!
|
||||
|
||||
#ifdef CREDENTIALS
|
||||
#include <FDRScredentials.h>
|
||||
#define WIFI_NET my_SSID // ssid of your accesspoint
|
||||
#define WIFI_PASS my_PASSWORD // password of access point
|
||||
#define MQTT_ADDR my_MQTT_BROKER
|
||||
#define BAND my_BAND
|
||||
#define SF my_SF
|
||||
#else
|
||||
#define WIFI_NET "Your SSID"
|
||||
#define WIFI_PASS "Password"
|
||||
#define MQTT_ADDR "192.168.0.8"
|
||||
#define BAND 915E6
|
||||
#define SF 7
|
||||
#endif
|
||||
|
||||
#define STATUS_T 0 // Status
|
||||
#define TEMP_T 1 // Temperature
|
||||
#define TEMP2_T 2 // Temperature #2
|
||||
#define HUMIDITY_T 3 // Relative Humidity
|
||||
#define PRESSURE_T 4 // Atmospheric Pressure
|
||||
#define LIGHT_T 5 // Light (lux)
|
||||
#define SOIL_T 6 // Soil Moisture
|
||||
#define SOIL2_T 7 // Soil Moisture #2
|
||||
#define SOILR_T 8 // Soil Resistance
|
||||
#define SOILR2_T 9 // Soil Resistance #2
|
||||
#define OXYGEN_T 10 // Oxygen
|
||||
#define CO2_T 11 // Carbon Dioxide
|
||||
#define WINDSPD_T 12 // Wind Speed
|
||||
#define WINDHDG_T 13 // Wind Direction
|
||||
#define RAINFALL_T 14 // Rainfall
|
||||
#define MOTION_T 15 // Motion
|
||||
#define VOLTAGE_T 16 // Voltage
|
||||
#define VOLTAGE2_T 17 // Voltage #2
|
||||
#define CURRENT_T 18 // Current
|
||||
#define CURRENT2_T 19 // Current #2
|
||||
#define IT_T 20 // Iterations
|
||||
|
||||
|
||||
#define TOPIC_DATA "FDRS/DATA"
|
||||
#define TOPIC_STATUS "FDRS/STATUS"
|
||||
#define TOPIC_COMMAND "FDRS/COMMAND"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user