From 39d9f1ba6afcfb5bce98c3308cd35404a7d631a0 Mon Sep 17 00:00:00 2001 From: Timm Bogner <64260873+timmbogner@users.noreply.github.com> Date: Wed, 25 May 2022 19:11:38 -0500 Subject: [PATCH] tubbleschruting --- Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino | 7 ++- Examples/1_LoRa_Sensor/fdrs_sensor.h | 50 +++++++++++++++++--- Examples/1_LoRa_Sensor/sensor_config.h | 27 +++++++++++ Examples/1_LoRa_Sensor/sensor_setup.h | 16 ------- Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino | 7 +-- Examples/5_MQTT_Gateway/fdrs_config.h | 55 +++++++++------------- Examples/5_MQTT_Gateway/fdrs_functions.h | 4 ++ 7 files changed, 101 insertions(+), 65 deletions(-) create mode 100644 Examples/1_LoRa_Sensor/sensor_config.h delete mode 100644 Examples/1_LoRa_Sensor/sensor_setup.h diff --git a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino index 10fd9f5..9826a5f 100644 --- a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino +++ b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino @@ -5,10 +5,8 @@ // 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". // -#define DEBUG -#define CREDENTIALS -#include + #include "fdrs_sensor.h" float data1; @@ -27,7 +25,8 @@ void loop() { } float readTemp() { - return 42.069; + // return 42.069; + return 42.5; } float readHum() { diff --git a/Examples/1_LoRa_Sensor/fdrs_sensor.h b/Examples/1_LoRa_Sensor/fdrs_sensor.h index 8edcdac..9aaaa08 100644 --- a/Examples/1_LoRa_Sensor/fdrs_sensor.h +++ b/Examples/1_LoRa_Sensor/fdrs_sensor.h @@ -4,7 +4,7 @@ // // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // -#include "sensor_setup.h" +#include "sensor_config.h" #if defined(ESP8266) #include #include @@ -13,11 +13,47 @@ #include #include #endif - #ifdef USE_LORA #include #endif +#ifdef GLOBALS +#define FDRS_BAND GLOBAL_BAND +#define FDRS_SF GLOBAL_SF +#else +#define FDRS_BAND BAND +#define FDRS_SF SF +#endif + +#ifdef DEBUG +#define DBG(a) (Serial.println(a)) +#else +#define DBG(a) +#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 MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems. + typedef struct __attribute__((packed)) DataReading { float d; uint16_t id; @@ -28,7 +64,7 @@ typedef struct __attribute__((packed)) 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; DataReading fdrsData[espnow_size]; @@ -78,22 +114,22 @@ void beginFDRS() { #ifdef USE_LORA DBG("Initializing LoRa!"); DBG(BAND); - DBG(SF); + DBG(SF); #ifndef __AVR__ SPI.begin(SCK, MISO, MOSI, SS); #endif LoRa.setPins(SS, RST, DIO0); - if (!LoRa.begin(BAND)) { + if (!LoRa.begin(FDRS_BAND)) { while (1); } - LoRa.setSpreadingFactor(SF); + LoRa.setSpreadingFactor(FDRS_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(); diff --git a/Examples/1_LoRa_Sensor/sensor_config.h b/Examples/1_LoRa_Sensor/sensor_config.h new file mode 100644 index 0000000..d8b9c27 --- /dev/null +++ b/Examples/1_LoRa_Sensor/sensor_config.h @@ -0,0 +1,27 @@ +// FARM DATA RELAY SYSTEM +// +// Sensor Configuration +// +#include //Uncomment if you install the globals file + +#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 + +//LoRa Configuration +#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 diff --git a/Examples/1_LoRa_Sensor/sensor_setup.h b/Examples/1_LoRa_Sensor/sensor_setup.h deleted file mode 100644 index 1b2b861..0000000 --- a/Examples/1_LoRa_Sensor/sensor_setup.h +++ /dev/null @@ -1,16 +0,0 @@ - -#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 diff --git a/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino b/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino index 1141809..ff4e738 100644 --- a/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino +++ b/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino @@ -5,11 +5,7 @@ // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // -#define DEBUG -#define CREDENTIALS - #include "fdrs_config.h" - #ifdef ESP8266 #include #include @@ -75,8 +71,9 @@ void setup() { #endif //DBG(sizeof(DataReading)); +#ifdef USE_WIFI client.publish(TOPIC_STATUS, "FDRS initialized"); - +#endif } void loop() { diff --git a/Examples/5_MQTT_Gateway/fdrs_config.h b/Examples/5_MQTT_Gateway/fdrs_config.h index e64682b..643a0dd 100644 --- a/Examples/5_MQTT_Gateway/fdrs_config.h +++ b/Examples/5_MQTT_Gateway/fdrs_config.h @@ -10,23 +10,17 @@ //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 sendSerial(); +#define SERIAL_ACT //sendMQTT(); #define MQTT_ACT -#define LORAG_ACT +#define LORAG_ACT sendSerial(); -#define USE_LORA -#define USE_WIFI //Used only for MQTT gateway +//#define USE_LORA +//#define USE_WIFI //Used only for MQTT gateway -#define WIFI_SSID "Your SSID" -#define WIFI_PASS "Your Password" -#define MQTT_ADDR "192.168.0.8" - -// Peer Actions -#define ESPNOW1_ACT -#define ESPNOW2_ACT -#define LORA1_ACT -#define LORA2_ACT +#define WIFI_SSID "Your SSID" +#define WIFI_PASS "Your Password" +#define MQTT_ADDR "192.168.0.8" // Peer addresses #define ESPNOW1_PEER 0x04 // ESPNOW1 Address @@ -34,23 +28,11 @@ #define LORA1_PEER 0x04 // LoRa1 Address #define LORA2_PEER 0x05 // LoRa2 Address -// 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_LORA -#define SCK 5 -#define MISO 19 -#define MOSI 27 -#define SS 18 -#define RST 14 -#define DIO0 26 +// Peer Actions +#define ESPNOW1_ACT +#define ESPNOW2_ACT +#define LORA1_ACT +#define LORA2_ACT //Pins for UART data interface (ESP32 only) #define RXD2 14 @@ -69,6 +51,15 @@ #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 @@ -77,5 +68,3 @@ #define TOPIC_DATA "FDRS/DATA" #define TOPIC_STATUS "FDRS/STATUS" #define TOPIC_COMMAND "FDRS/COMMAND" - -#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems. diff --git a/Examples/5_MQTT_Gateway/fdrs_functions.h b/Examples/5_MQTT_Gateway/fdrs_functions.h index 65850eb..3bbeade 100644 --- a/Examples/5_MQTT_Gateway/fdrs_functions.h +++ b/Examples/5_MQTT_Gateway/fdrs_functions.h @@ -3,11 +3,13 @@ #else #define DBG(a) #endif + #if defined (ESP32) #define UART_IF Serial1 #else #define UART_IF Serial #endif + #ifdef GLOBALS #define FDRS_WIFI_SSID GLOBAL_SSID #define FDRS_WIFI_PASS GLOBAL_PASS @@ -22,6 +24,8 @@ #define FDRS_SF SF #endif +#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems. + typedef struct __attribute__((packed)) DataReading { float d; uint16_t id;