diff --git a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino index 0b4fe79..a783669 100644 --- a/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino +++ b/Examples/1_LoRa_Sensor/1_LoRa_Sensor.ino @@ -5,6 +5,9 @@ // 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 ROLE LORA_SENSOR #include "fdrs_sensor.h" diff --git a/Examples/2_ESPNOW_Sensor/2_ESPNOW_Sensor.ino b/Examples/2_ESPNOW_Sensor/2_ESPNOW_Sensor.ino index 0b4fe79..f5be8e2 100644 --- a/Examples/2_ESPNOW_Sensor/2_ESPNOW_Sensor.ino +++ b/Examples/2_ESPNOW_Sensor/2_ESPNOW_Sensor.ino @@ -6,6 +6,10 @@ // An example of how to send data using "fdrs_sensor.h". // +#define DEBUG + +#define ESPNOW_SENSOR + #include "fdrs_sensor.h" float data1 = 42.069; diff --git a/Examples/2_ESPNOW_Sensor/fdrs_sensor.h b/Examples/2_ESPNOW_Sensor/fdrs_sensor.h index 69d9cfc..b3bb7fe 100644 --- a/Examples/2_ESPNOW_Sensor/fdrs_sensor.h +++ b/Examples/2_ESPNOW_Sensor/fdrs_sensor.h @@ -11,8 +11,7 @@ //#define USE_LORA #define DEEP_SLEEP //#define POWER_CTRL 14 -#define DEBUG -//#define CREDENTIALS +#define DEBUG #define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE //LoRa Configuration @@ -22,13 +21,22 @@ #define SS 18 #define RST 14 #define DIO0 26 -//433E6 for Asia -//866E6 for Europe -//915E6 for North America -#define BAND 915E6 //May be overwritten if CREDENTIALS is set #ifdef CREDENTIALS #include +#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 { @@ -74,13 +82,10 @@ typedef struct __attribute__((packed)) DataReading { #include #endif -#define DBG(a) -#ifdef ESP8266 -#define UART_IF Serial -#else #ifdef DEBUG #define DBG(a) (Serial.println(a)) -#endif +#else +#define DBG(a) #endif const uint16_t espnow_size = 250 / sizeof(DataReading); diff --git a/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino b/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino index eab7793..d649334 100644 --- a/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino +++ b/Examples/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino @@ -4,6 +4,8 @@ // // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // + +#define DEBUG #include "fdrs_config.h" #include "DataReading.h" #ifdef ESP8266 diff --git a/Examples/3_ESPNOW_Gateway/defaults.h b/Examples/3_ESPNOW_Gateway/defaults.h index e1cdabc..1e788c6 100644 --- a/Examples/3_ESPNOW_Gateway/defaults.h +++ b/Examples/3_ESPNOW_Gateway/defaults.h @@ -36,10 +36,6 @@ #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 diff --git a/Examples/3_ESPNOW_Gateway/fdrs_config.h b/Examples/3_ESPNOW_Gateway/fdrs_config.h index 1811940..f4c9d28 100644 --- a/Examples/3_ESPNOW_Gateway/fdrs_config.h +++ b/Examples/3_ESPNOW_Gateway/fdrs_config.h @@ -19,16 +19,13 @@ #define CREDENTIALS -//ESP32 Only -- Define UART pins and interface. +#if defined (ESP32) #define RXD2 14 #define TXD2 15 -#define UART_IF Serial1 -#define DEBUG - -//WiFi Configuration -- Needed only if this device is using MQTT -#define WIFI_NET "Your SSID" -#define WIFI_PASS "Password" -#define MQTT_ADDR "192.168.0.8" +#define UART_IF Serial2 +#else +#define UART_IF Serial +#endif ////LoRa Configuration -- Needed only if using LoRa #define SCK 5 @@ -37,11 +34,20 @@ #define SS 18 #define RST 14 #define DIO0 26 + +#ifdef CREDENTIALS +#include +#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 - -#ifdef CREDENTIALS -#include #endif diff --git a/Examples/3_ESPNOW_Gateway/fdrs_functions.h b/Examples/3_ESPNOW_Gateway/fdrs_functions.h index d22d552..7b6d230 100644 --- a/Examples/3_ESPNOW_Gateway/fdrs_functions.h +++ b/Examples/3_ESPNOW_Gateway/fdrs_functions.h @@ -1,15 +1,13 @@ -#define DBG(a) -#ifdef ESP8266 -#define UART_IF Serial -#else #ifdef DEBUG #define DBG(a) (Serial.println(a)) +#else +#define DBG(a) #endif -#endif + 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; +// esp_now_peer_info_t peerInfo; uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC}; diff --git a/Examples/4_UART_Gateway/4_UART_Gateway.ino b/Examples/4_UART_Gateway/4_UART_Gateway.ino index ee4f44d..a52c345 100644 --- a/Examples/4_UART_Gateway/4_UART_Gateway.ino +++ b/Examples/4_UART_Gateway/4_UART_Gateway.ino @@ -4,6 +4,7 @@ // // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // +#define DEBUG #include "fdrs_config.h" #include "DataReading.h" #ifdef ESP8266 diff --git a/Examples/4_UART_Gateway/defaults.h b/Examples/4_UART_Gateway/defaults.h index c80a912..e143c85 100644 --- a/Examples/4_UART_Gateway/defaults.h +++ b/Examples/4_UART_Gateway/defaults.h @@ -42,4 +42,3 @@ #define NUM_LEDS 4 #define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE -#define UART_IF Serial1 diff --git a/Examples/4_UART_Gateway/fdrs_config.h b/Examples/4_UART_Gateway/fdrs_config.h index dc494b5..75ad250 100644 --- a/Examples/4_UART_Gateway/fdrs_config.h +++ b/Examples/4_UART_Gateway/fdrs_config.h @@ -19,11 +19,13 @@ #define CREDENTIALS -//ESP32 Only -- Define UART pins and interface +#if defined (ESP32) #define RXD2 14 #define TXD2 15 -#define UART_IF Serial1 -#define DEBUG +#define UART_IF Serial2 +#else +#define UART_IF Serial +#endif //LoRa Configuration -- Needed only if this device is using LoRa #define SCK 5 diff --git a/Examples/4_UART_Gateway/fdrs_functions.h b/Examples/4_UART_Gateway/fdrs_functions.h index 47c4f6b..44770bf 100644 --- a/Examples/4_UART_Gateway/fdrs_functions.h +++ b/Examples/4_UART_Gateway/fdrs_functions.h @@ -1,10 +1,7 @@ -#define DBG(a) -#ifdef ESP8266 -#define UART_IF Serial -#else #ifdef DEBUG #define DBG(a) (Serial.println(a)) -#endif +#else +#define DBG(a) #endif const uint8_t espnow_size = 250 / sizeof(DataReading); const uint8_t lora_size = 256 / sizeof(DataReading); diff --git a/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino b/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino index 34c3bde..12945d0 100644 --- a/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino +++ b/Examples/5_MQTT_Gateway/5_MQTT_Gateway.ino @@ -4,8 +4,14 @@ // // Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA. // + +#define DEBUG + +#define ROLE MQTT_GATEWAY + #include "fdrs_config.h" #include "DataReading.h" + #ifdef ESP8266 #include #include @@ -29,12 +35,11 @@ void setup() { #if defined(ESP8266) - UART_IF.begin(115200); + Serial.begin(115200); #elif defined(ESP32) Serial.begin(115200); UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2); #endif - DBG("Initializing FDRS Gateway"); DBG("Address:" + String (UNIT_MAC, HEX)); #ifdef USE_LED FastLED.addLeds(leds, NUM_LEDS); @@ -48,11 +53,13 @@ void setup() { DBG("Connecting to Wifi..."); delay(500); } + DBG("WiFi Connected"); client.setServer(mqtt_server, 1883); if (!client.connected()) { DBG("Connecting mqtt..."); reconnect(); } + DBG("MQTT Connected"); client.setCallback(mqtt_callback); #else begin_espnow(); @@ -68,6 +75,8 @@ void setup() { #endif // UART_IF.println(sizeof(DataReading)); + client.publish("esp/fdrs/status", "FDRS initialized"); + } void loop() { diff --git a/Examples/5_MQTT_Gateway/defaults.h b/Examples/5_MQTT_Gateway/defaults.h index c80a912..aa6abd4 100644 --- a/Examples/5_MQTT_Gateway/defaults.h +++ b/Examples/5_MQTT_Gateway/defaults.h @@ -22,9 +22,6 @@ #define LORA1_ACT #define LORA2_ACT -//#define RXD2 21 -//#define TXD2 22 - //#define USE_LORA #define SCK 5 #define MISO 19 @@ -42,4 +39,3 @@ #define NUM_LEDS 4 #define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE -#define UART_IF Serial1 diff --git a/Examples/5_MQTT_Gateway/fdrs_config.h b/Examples/5_MQTT_Gateway/fdrs_config.h index 9765aba..6e4cafa 100644 --- a/Examples/5_MQTT_Gateway/fdrs_config.h +++ b/Examples/5_MQTT_Gateway/fdrs_config.h @@ -19,16 +19,13 @@ #define CREDENTIALS -//ESP32 Only -- Define UART pins and interface. +#if defined (ESP32) #define RXD2 14 #define TXD2 15 #define UART_IF Serial1 -#define DEBUG - -//WiFi Configuration -- Needed only if this device is using MQTT -#define WIFI_NET "Your SSID" -#define WIFI_PASS "Password" -#define MQTT_ADDR "192.168.0.8" +#else +#define UART_IF Serial +#endif ////LoRa Configuration -- Needed only if using LoRa #define SCK 5 @@ -37,10 +34,7 @@ #define SS 18 #define RST 14 #define DIO0 26 -//433E6 for Asia -//866E6 for Europe -//915E6 for North America -#define BAND 915E6 + #ifdef CREDENTIALS #include @@ -52,4 +46,9 @@ #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 diff --git a/Examples/5_MQTT_Gateway/fdrs_functions.h b/Examples/5_MQTT_Gateway/fdrs_functions.h index afedd47..b07dc96 100644 --- a/Examples/5_MQTT_Gateway/fdrs_functions.h +++ b/Examples/5_MQTT_Gateway/fdrs_functions.h @@ -1,10 +1,7 @@ -#define DBG(a) -#ifdef ESP8266 -#define UART_IF Serial -#else #ifdef DEBUG #define DBG(a) (Serial.println(a)) -#endif +#else +#define DBG(a) #endif const uint8_t espnow_size = 250 / sizeof(DataReading); const uint8_t lora_size = 256 / sizeof(DataReading); @@ -102,6 +99,7 @@ void getSerial() { } void mqtt_callback(char* topic, byte * message, unsigned int length) { String incomingString; + DBG(topic); for (int i = 0; i < length; i++) { incomingString += (char)message[i]; }