diff --git a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino index 8d04447..10fd9f5 100644 --- a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino +++ b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino @@ -11,15 +11,25 @@ #include #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; +} diff --git a/Examples/1_LoRa_Sensor/fdrs_sensor.h b/Examples/1_LoRa_Sensor/fdrs_sensor.h index 06cc3bc..8edcdac 100644 --- a/Examples/1_LoRa_Sensor/fdrs_sensor.h +++ b/Examples/1_LoRa_Sensor/fdrs_sensor.h @@ -4,58 +4,7 @@ // // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // - -#include - -#define ROLE LORA_SENSOR - -#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 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 - -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 #include @@ -69,6 +18,13 @@ typedef struct __attribute__((packed)) DataReading { #include #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}; diff --git a/Examples/1_LoRa_Sensor/sensor_setup.h b/Examples/1_LoRa_Sensor/sensor_setup.h new file mode 100644 index 0000000..7da1520 --- /dev/null +++ b/Examples/1_LoRa_Sensor/sensor_setup.h @@ -0,0 +1,16 @@ + +#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 + +//LoRa Configuration +#define SCK 5 +#define MISO 19 +#define MOSI 27 +#define SS 18 +#define RST 14 +#define DIO0 26 diff --git a/Examples/2_ESPNOW_Sensor/Sensor_setup.h b/Examples/2_ESPNOW_Sensor/Sensor_setup.h new file mode 100644 index 0000000..2c9a7ff --- /dev/null +++ b/Examples/2_ESPNOW_Sensor/Sensor_setup.h @@ -0,0 +1,16 @@ +#define READING_ID 2 //Unique ID for this sensor +#define GTWY_MAC 0x01 //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 diff --git a/Examples/2_ESPNOW_Sensor/fdrs_sensor.h b/Examples/2_ESPNOW_Sensor/fdrs_sensor.h index e8f35fa..36333b0 100644 --- a/Examples/2_ESPNOW_Sensor/fdrs_sensor.h +++ b/Examples/2_ESPNOW_Sensor/fdrs_sensor.h @@ -4,52 +4,7 @@ // // 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 0x01 //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 - -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 @@ -64,6 +19,13 @@ typedef struct __attribute__((packed)) DataReading { #include #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}; diff --git a/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino b/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino index 87f3e42..5d44c3d 100644 --- a/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino +++ b/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino @@ -12,7 +12,6 @@ #include #include "fdrs_config.h" -#include "DataReading.h" #ifdef ESP8266 #include #include diff --git a/Examples/3_ESPNOW_Gateway/DataReading.h b/Examples/3_ESPNOW_Gateway/DataReading.h deleted file mode 100644 index 44da713..0000000 --- a/Examples/3_ESPNOW_Gateway/DataReading.h +++ /dev/null @@ -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 diff --git a/Examples/3_ESPNOW_Gateway/fdrs_functions.h b/Examples/3_ESPNOW_Gateway/fdrs_functions.h index 3326e28..003a919 100644 --- a/Examples/3_ESPNOW_Gateway/fdrs_functions.h +++ b/Examples/3_ESPNOW_Gateway/fdrs_functions.h @@ -4,6 +4,13 @@ #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}; diff --git a/Examples/4_UART_Gateway/4_UART_Gateway.ino b/Examples/4_UART_Gateway/4_UART_Gateway.ino index a3b9647..b6a5e4e 100644 --- a/Examples/4_UART_Gateway/4_UART_Gateway.ino +++ b/Examples/4_UART_Gateway/4_UART_Gateway.ino @@ -11,7 +11,6 @@ #include #include "fdrs_config.h" -#include "DataReading.h" #ifdef ESP8266 #include #include diff --git a/Examples/4_UART_Gateway/DataReading.h b/Examples/4_UART_Gateway/DataReading.h deleted file mode 100644 index 44da713..0000000 --- a/Examples/4_UART_Gateway/DataReading.h +++ /dev/null @@ -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 diff --git a/Examples/4_UART_Gateway/fdrs_config.h b/Examples/4_UART_Gateway/fdrs_config.h index 16e5e8a..fa94b9d 100644 --- a/Examples/4_UART_Gateway/fdrs_config.h +++ b/Examples/4_UART_Gateway/fdrs_config.h @@ -11,9 +11,6 @@ //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 DEBUG -#define CREDENTIALS - #define ESPNOWG_ACT sendSerial(); #define SERIAL_ACT #define MQTT_ACT diff --git a/Examples/4_UART_Gateway/fdrs_functions.h b/Examples/4_UART_Gateway/fdrs_functions.h index eb8ba12..5eb0d4c 100644 --- a/Examples/4_UART_Gateway/fdrs_functions.h +++ b/Examples/4_UART_Gateway/fdrs_functions.h @@ -1,3 +1,16 @@ +#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 uint8_t espnow_size = 250 / sizeof(DataReading); const uint8_t lora_size = 256 / sizeof(DataReading); const uint8_t mac_prefix[] = {MAC_PREFIX};