From a8e94156dda32e6b2ca11dcba644c9905dca8f3a Mon Sep 17 00:00:00 2001 From: Timm Bogner <64260873+timmbogner@users.noreply.github.com> Date: Thu, 7 Jul 2022 23:29:03 -0500 Subject: [PATCH] Updated gateway .ino --- FDRS_Gateway/FDRS_Gateway.ino | 3 +- .../3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino | 41 +++++++++++-------- .../4_UART_Gateway/4_UART_Gateway.ino | 41 +++++++++++-------- .../5_MQTT_Gateway/5_MQTT_Gateway.ino | 41 +++++++++++-------- 4 files changed, 74 insertions(+), 52 deletions(-) diff --git a/FDRS_Gateway/FDRS_Gateway.ino b/FDRS_Gateway/FDRS_Gateway.ino index 01acb53..1204c01 100644 --- a/FDRS_Gateway/FDRS_Gateway.ino +++ b/FDRS_Gateway/FDRS_Gateway.ino @@ -30,7 +30,8 @@ #include #include #endif -#include "fdrs_functions.h" +//#include //Use global functions file +#include "fdrs_functions.h" //Use local functions file void setup() { #if defined(ESP8266) diff --git a/examples/Full_System_Example/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino b/examples/Full_System_Example/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino index be1d9a5..5a41da1 100644 --- a/examples/Full_System_Example/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino +++ b/examples/Full_System_Example/3_ESPNOW_Gateway/3_ESPNOW_Gateway.ino @@ -17,6 +17,8 @@ #include #ifdef USE_WIFI #include +#include +#include #endif #ifdef USE_LORA #include @@ -24,7 +26,12 @@ #ifdef USE_LED #include #endif -#include +#ifdef USE_SD_LOG +#include +#include +#endif +#include //Use global functions file +//#include "fdrs_functions.h" //Use local functions file void setup() { #if defined(ESP8266) @@ -51,25 +58,17 @@ void setup() { DBG("WiFi Connected"); client.setServer(mqtt_server, mqtt_port); if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(5); } - DBG("MQTT Connected"); client.setCallback(mqtt_callback); #else begin_espnow(); #endif #ifdef USE_LORA - DBG("Initializing LoRa!"); -#ifdef ESP32 - SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); + begin_lora(); #endif - LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0); - if (!LoRa.begin(FDRS_BAND)) { - while (1); - } - LoRa.setSpreadingFactor(FDRS_SF); - DBG(" LoRa initialized."); +#ifdef USE_SD_LOG + begin_SD(); #endif //DBG(sizeof(DataReading)); @@ -132,12 +131,20 @@ void loop() { getSerial(); } getLoRa(); -#ifdef USE_WIFI + #ifdef USE_WIFI if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(1, true); } - client.loop(); + client.loop(); // for recieving incoming messages and maintaining connection + + timeClient.update(); //update internal clock if possible + #endif +#ifdef USE_SD_LOG +unsigned long current_millis = millis(); +if(current_millis-last_millis >= 1000){ + seconds_since_reset+=(current_millis-last_millis)/1000; + last_millis=current_millis; +} #endif if (newData) { switch (newData) { diff --git a/examples/Full_System_Example/4_UART_Gateway/4_UART_Gateway.ino b/examples/Full_System_Example/4_UART_Gateway/4_UART_Gateway.ino index be1d9a5..5a41da1 100644 --- a/examples/Full_System_Example/4_UART_Gateway/4_UART_Gateway.ino +++ b/examples/Full_System_Example/4_UART_Gateway/4_UART_Gateway.ino @@ -17,6 +17,8 @@ #include #ifdef USE_WIFI #include +#include +#include #endif #ifdef USE_LORA #include @@ -24,7 +26,12 @@ #ifdef USE_LED #include #endif -#include +#ifdef USE_SD_LOG +#include +#include +#endif +#include //Use global functions file +//#include "fdrs_functions.h" //Use local functions file void setup() { #if defined(ESP8266) @@ -51,25 +58,17 @@ void setup() { DBG("WiFi Connected"); client.setServer(mqtt_server, mqtt_port); if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(5); } - DBG("MQTT Connected"); client.setCallback(mqtt_callback); #else begin_espnow(); #endif #ifdef USE_LORA - DBG("Initializing LoRa!"); -#ifdef ESP32 - SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); + begin_lora(); #endif - LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0); - if (!LoRa.begin(FDRS_BAND)) { - while (1); - } - LoRa.setSpreadingFactor(FDRS_SF); - DBG(" LoRa initialized."); +#ifdef USE_SD_LOG + begin_SD(); #endif //DBG(sizeof(DataReading)); @@ -132,12 +131,20 @@ void loop() { getSerial(); } getLoRa(); -#ifdef USE_WIFI + #ifdef USE_WIFI if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(1, true); } - client.loop(); + client.loop(); // for recieving incoming messages and maintaining connection + + timeClient.update(); //update internal clock if possible + #endif +#ifdef USE_SD_LOG +unsigned long current_millis = millis(); +if(current_millis-last_millis >= 1000){ + seconds_since_reset+=(current_millis-last_millis)/1000; + last_millis=current_millis; +} #endif if (newData) { switch (newData) { diff --git a/examples/Full_System_Example/5_MQTT_Gateway/5_MQTT_Gateway.ino b/examples/Full_System_Example/5_MQTT_Gateway/5_MQTT_Gateway.ino index be1d9a5..5a41da1 100644 --- a/examples/Full_System_Example/5_MQTT_Gateway/5_MQTT_Gateway.ino +++ b/examples/Full_System_Example/5_MQTT_Gateway/5_MQTT_Gateway.ino @@ -17,6 +17,8 @@ #include #ifdef USE_WIFI #include +#include +#include #endif #ifdef USE_LORA #include @@ -24,7 +26,12 @@ #ifdef USE_LED #include #endif -#include +#ifdef USE_SD_LOG +#include +#include +#endif +#include //Use global functions file +//#include "fdrs_functions.h" //Use local functions file void setup() { #if defined(ESP8266) @@ -51,25 +58,17 @@ void setup() { DBG("WiFi Connected"); client.setServer(mqtt_server, mqtt_port); if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(5); } - DBG("MQTT Connected"); client.setCallback(mqtt_callback); #else begin_espnow(); #endif #ifdef USE_LORA - DBG("Initializing LoRa!"); -#ifdef ESP32 - SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); + begin_lora(); #endif - LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0); - if (!LoRa.begin(FDRS_BAND)) { - while (1); - } - LoRa.setSpreadingFactor(FDRS_SF); - DBG(" LoRa initialized."); +#ifdef USE_SD_LOG + begin_SD(); #endif //DBG(sizeof(DataReading)); @@ -132,12 +131,20 @@ void loop() { getSerial(); } getLoRa(); -#ifdef USE_WIFI + #ifdef USE_WIFI if (!client.connected()) { - DBG("Connecting MQTT..."); - reconnect(); + reconnect(1, true); } - client.loop(); + client.loop(); // for recieving incoming messages and maintaining connection + + timeClient.update(); //update internal clock if possible + #endif +#ifdef USE_SD_LOG +unsigned long current_millis = millis(); +if(current_millis-last_millis >= 1000){ + seconds_since_reset+=(current_millis-last_millis)/1000; + last_millis=current_millis; +} #endif if (newData) { switch (newData) {