Clean up of #72

- moved configuration checkup to external file to make sensor and gateway files smaller.
- for sensors the config now only is shown if the sensor does NOT return from Deep Sleep. For example when pressing the reset button or after a crash.
- for gateways the configuration is shown once and also can be forced to be shown with a reset. Code should work for ESP32 and ESP8266 - have only tested it with ESP32.
- fixed issue in fdrs_functions.h - if MQTT_AUTH was enabled but WIFI disabled, the compile crashed.
This commit is contained in:
Sascha 2022-07-22 23:41:52 +02:00
parent 62685452ad
commit 5e85269373
5 changed files with 256 additions and 141 deletions

View File

@ -44,7 +44,18 @@ void setup() {
Serial.begin(115200);
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
#endif
DBG("Address:" + String (UNIT_MAC, HEX));
#ifdef DEBUG_NODE_CONFIG
// find out the reset reason
esp_reset_reason_t resetReason;
resetReason = esp_reset_reason();
if (resetReason != ESP_RST_DEEPSLEEP) {
checkConfig();
}
#endif //DEBUG_NODE_CONFIG
#ifdef USE_LED
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
leds[0] = CRGB::Blue;

View File

@ -17,6 +17,7 @@
#define LORAG_ACT sendSerial();
#define USE_LORA
#define USE_ESPNOW // Missing! Gateways do not have to be ESPNOW activated. It also is making config much easier. Used it there.
//#define USE_WIFI //Used only for MQTT gateway
// Peer addresses

219
fdrs_checkConfig.h Normal file
View File

@ -0,0 +1,219 @@
#ifndef __FDRS_CHECKCONFIG_h__
#define __FDRS_CHECKCONFIG_h__
char* separatorLine2 = "----------------------------------------------------";
// helper function for a nice little header above each section
void printSmallSectionHeader(char* headerText) {
char * separatorLine = "----------------------------------------------------";
DBG(separatorLine);
DBG(headerText);
//DBG(separatorLine);
}
// helper function for a nice little header above each section
void printSectionHeader(char* headerText) {
char * separatorLine = "----------------------------------------------------";
DBG(separatorLine);
DBG(headerText);
DBG(separatorLine);
}
// helper function for a nice little header above each section
void printConfigHeader(char* headerText) {
char * headerAndFooter = "====================================================";
DBG(headerAndFooter);
DBG(headerText);
DBG(headerAndFooter);
}
// check which protocols are activated and which are deactivated
void printActivatedProtocols() {
// current candidates are: WIFI, ESPNOW, LORA, MQTT, ???
printSectionHeader("ACTIVATED PROTOCOLS");
#ifdef USE_LORA
DBG("LoRa : ENABLED");
#else
DBG("LoRa : DISABLED");
#endif
#ifdef USE_ESPNOW
DBG("ESPNow: ENABLED");
#else
DBG("ESPNow: DISABLED");
#endif
#ifdef USE_WIFI
DBG("WiFi : ENABLED");
#else
DBG("WiFi : DISABLED");
#endif
}
void printEspnowDetails() {
#ifdef USE_ESPNOW
#ifdef UNIT_MAC
printSmallSectionHeader("ESP-Now Details:");
DBG("Peer 1 address: " + String(ESPNOW1_PEER, HEX));
DBG("Peer 2 address: " + String(ESPNOW2_PEER, HEX));
#endif //UNIT_MAC
#endif //USE_ESPNOW
}
void printWifiDetails() {
#ifdef USE_WIFI
printSmallSectionHeader("WiFi Details:");
#if defined(WIFI_SSID)
DBG("WiFi SSID used from WIFI_SSID : " + String(FDRS_WIFI_SSID));
#elif defined (GLOBAL_SSID)
DBG("WiFi SSID used from GLOBAL_SSID : " + String(FDRS_WIFI_SSID));
#else
DBG("NO WiFi SSID defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //WIFI_SSID
#if defined(WIFI_PASS)
DBG("WiFi password used from WIFI_PASS : " + String(FDRS_WIFI_PASS));
#elif defined (GLOBAL_SSID)
DBG("WiFi password used from GLOBAL_PASS : " + String(FDRS_WIFI_PASS));
#else
DBG("NO WiFi password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //WIFI_PASS
printSmallSectionHeader("MQTT BROKER CONFIG:");
#if defined(MQTT_ADDR)
DBG("MQTT address used from MQTT_ADDR : " + String(FDRS_MQTT_ADDR));
#elif defined (GLOBAL_MQTT_ADDR)
DBG("MQTT address used from GLOBAL_MQTT_ADDR : " + String(FDRS_MQTT_ADDR));
#else
DBG("NO MQTT address defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_ADDR
#if defined(MQTT_PORT)
DBG("MQTT port used from MQTT_PORT : " + String(FDRS_MQTT_PORT));
#elif defined (GLOBAL_MQTT_PORT)
DBG("MQTT port used from GLOBAL_MQTT_ADDR : " + String(FDRS_MQTT_PORT));
#else
DBG("Using default MQTT port : " + String(FDRS_MQTT_PORT));
#endif //MQTT_PORT
#ifdef FDRS_MQTT_AUTH
printSmallSectionHeader("MQTT AUTHENTIFICATION CONFIG:");
//GLOBAL_MQTT_AUTH
#if defined(MQTT_USER)
DBG("MQTT username used from MQTT_USER : " + String(FDRS_MQTT_USER));
#elif defined (GLOBAL_MQTT_USER)
DBG("MQTT username used from GLOBAL_MQTT_USER : " + String(FDRS_MQTT_USER));
#else
DBG("NO MQTT username defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_USER
#if defined(MQTT_PASS)
DBG("MQTT password used from MQTT_PASS : " + String(FDRS_MQTT_PASS));
#elif defined (GLOBAL_MQTT_PASS)
DBG("MQTT password used from GLOBAL_MQTT_PASS : " + String(FDRS_MQTT_PASS));
#else
DBG("NO MQTT password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_PASS
#endif //FDRS_MQTT_AUTH
DBG("----------------------------------------------------");
DBG(separatorLine2);
#endif //USE_WIFI
}
void printLoraDetails() {
#ifdef USE_LORA
printSmallSectionHeader("LoRa Details:");
#if defined(LORA_BAND)
DBG("LoRa Band used from LORA_BAND : " + String(FDRS_BAND));
#elif defined (GLOBAL_LORA_BAND)
DBG("LoRa Band used from GLOBAL_LORA_BAND: " + String(FDRS_BAND));
#else
DBG("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-BAND
#if defined(LORA_SF)
DBG("LoRa SF used from LORA_SF : " + String(FDRS_SF));
#elif defined (GLOBAL_LORA_SF)
DBG("LoRa SF used from GLOBAL_LORA_SF : " + String(FDRS_SF));
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
DBG("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-SF
#ifdef UNIT_MAC
DBG("LoRa peers");
DBG("Peer 1 address: " + String(LORA1_PEER, HEX));
DBG("Peer 2 address: " + String(LORA2_PEER, HEX));
#endif //UNIT_MAC
#endif //USE_LORA
}
void checkConfig() {
printConfigHeader("NODE CONFIGURATION OVERVIEW");
#ifdef UNIT_MAC
DBG("Node Type : Gateway");
DBG("Gateway ID : " + String(UNIT_MAC, HEX));
#elif defined (READING_ID)
DBG("Node Type : Sensor");
DBG("Reading ID : " + String(READING_ID));
DBG("Sensor's Gateway: " + String(GTWY_MAC, HEX));
#else
DBG("Node Type : UNKNOWN!");
DBG("Please check config!");
DBG("If you have just created a new node type,");
DBG("please add it's config check to:");
DGB("fdrs_checkConfig.h");
#endif
//printConfigHeader("FULL CONFIG OVERVIEW");
printActivatedProtocols();
printSmallSectionHeader("PROTOCOL DETAILS");
#ifdef USE_LORA
printLoraDetails();
#endif
// why is USE_ESPNOW not defined for gateways? This should be implemented as not every gateway has to be an ESP-NOW gateway!
#ifdef USE_ESPNOW
printEspnowDetails();
#endif
#ifdef USE_WIFI
printWifiDetails();
#endif
DBG("----------------------------------------------------");
DBG("");
}
#endif //__FDRS_CHECKCONFIG_h__

View File

@ -91,6 +91,10 @@ enum {
// ASSERT("NO MQTT password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //MQTT_PASS
#if defined (MQTT_AUTH) || defined (GLOBAL_MQTT_AUTH)
#define FDRS_MQTT_AUTH
#endif //MQTT_AUTH
#endif //USE_WIFI
#ifdef USE_LORA
@ -115,12 +119,12 @@ enum {
#endif //USE_LORA
#if defined (MQTT_AUTH) || defined (GLOBAL_MQTT_AUTH)
#define FDRS_MQTT_AUTH
#endif
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
#ifdef DEBUG_NODE_CONFIG
#include "fdrs_checkConfig.h"
#endif
typedef struct __attribute__((packed)) DataReading {
float d;
uint16_t id;
@ -211,103 +215,6 @@ const char* mqtt_user = NULL;
const char* mqtt_pass = NULL;
#endif
void debugConfig() {
#ifdef USE_WIFI
DBG("----------------------------------------------------");
DBG("SENSOR WIFI CONFIG:");
#if defined(WIFI_SSID)
DBG("WiFi SSID used from WIFI_SSID : " + String(FDRS_WIFI_SSID));
#elif defined (GLOBAL_SSID)
DBG("WiFi SSID used from GLOBAL_SSID : " + String(FDRS_WIFI_SSID));
#else
DBG("NO WiFi SSID defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //WIFI_SSID
#if defined(WIFI_PASS)
DBG("WiFi password used from WIFI_PASS : " + String(FDRS_WIFI_PASS));
#elif defined (GLOBAL_SSID)
DBG("WiFi password used from GLOBAL_PASS : " + String(FDRS_WIFI_PASS));
#else
DBG("NO WiFi password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //WIFI_PASS
#if defined(MQTT_ADDR)
DBG("MQTT address used from MQTT_ADDR : " + String(FDRS_MQTT_ADDR));
#elif defined (GLOBAL_MQTT_ADDR)
DBG("MQTT address used from GLOBAL_MQTT_ADDR : " + String(FDRS_MQTT_ADDR));
#else
DBG("NO MQTT address defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_ADDR
#if defined(MQTT_PORT)
DBG("MQTT port used from MQTT_PORT : " + String(FDRS_MQTT_PORT));
#elif defined (GLOBAL_MQTT_PORT)
DBG("MQTT port used from GLOBAL_MQTT_ADDR : " + String(FDRS_MQTT_PORT));
#else
DBG("Using default MQTT port : " + String(FDRS_MQTT_PORT));
#endif //MQTT_PORT
#ifdef FDRS_MQTT_AUTH
DBG("MQTT AUTHENTIFICATION CONFIG:");
//GLOBAL_MQTT_AUTH
#if defined(MQTT_USER)
DBG("MQTT username used from MQTT_USER : " + String(FDRS_MQTT_USER));
#elif defined (GLOBAL_MQTT_USER)
DBG("MQTT username used from GLOBAL_MQTT_USER : " + String(FDRS_MQTT_USER));
#else
DBG("NO MQTT username defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_USER
#if defined(MQTT_PASS)
DBG("MQTT password used from MQTT_PASS : " + String(FDRS_MQTT_PASS));
#elif defined (GLOBAL_MQTT_PASS)
DBG("MQTT password used from GLOBAL_MQTT_PASS : " + String(FDRS_MQTT_PASS));
#else
DBG("NO MQTT password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //MQTT_PASS
#endif //FDRS_MQTT_AUTH
DBG("----------------------------------------------------");
#endif //USE_WIFI
#ifdef USE_LORA
DBG("----------------------------------------------------");
DBG("SENSOR LORA CONFIG:");
#if defined(LORA_BAND)
DBG("LoRa Band used from LORA_BAND : " + String(FDRS_BAND));
#elif defined (GLOBAL_LORA_BAND)
DBG("LoRa Band used from GLOBAL_LORA_BAND: " + String(FDRS_BAND));
#else
DBG("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-BAND
#if defined(LORA_SF)
DBG("LoRa SF used from LORA_SF : " + String(FDRS_SF));
#elif defined (GLOBAL_LORA_SF)
DBG("LoRa SF used from GLOBAL_LORA_SF : " + String(FDRS_SF));
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
DBG("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-BAND
#endif //USE_LORA
DBG("----------------------------------------------------");
DBG("");
}
// Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32
#if defined(ESP8266)
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
@ -843,12 +750,8 @@ void begin_lora() {
while (1);
}
LoRa.setSpreadingFactor(FDRS_SF);
#ifdef DEBUG_NODE_CONFIG
debugConfig();
#else
DBG("LoRa Band: " + String(FDRS_BAND));
DBG("LoRa SF : " + String(FDRS_SF));
#endif //DEBUG_NODE_CONFIG
#endif // USE_LORA
}

View File

@ -18,7 +18,7 @@
#endif
// enable to get detailed info from where single configuration macros have been taken
//#define DEBUG_NODE_CONFIG
#define DEBUG_NODE_CONFIG
#ifdef USE_LORA
@ -50,6 +50,10 @@
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
#ifdef DEBUG_NODE_CONFIG
#include "fdrs_checkConfig.h"
#endif
typedef struct __attribute__((packed)) DataReading {
float d;
uint16_t id;
@ -67,39 +71,12 @@ DataReading fdrsData[espnow_size];
uint8_t data_count = 0;
void debugConfig() {
#ifdef USE_LORA
DBG("----------------------------------------------------");
DBG("SENSOR LORA CONFIG");
DBG("----------------------------------------------------");
#if defined(LORA_BAND)
DBG("LoRa Band used from LORA_BAND : " + String(FDRS_BAND));
#elif defined (GLOBAL_LORA_BAND)
DBG("LoRa Band used from GLOBAL_LORA_BAND: " + String(FDRS_BAND));
#else
DBG("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-BAND
#if defined(LORA_SF)
DBG("LoRa SF used from LORA_SF : " + String(FDRS_SF));
#elif defined (GLOBAL_LORA_SF)
DBG("LoRa SF used from GLOBAL_LORA_SF : " + String(FDRS_SF));
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
DBG("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
//exit(0);
#endif //LORA-BAND
DBG("----------------------------------------------------");
DBG("");
#endif //USE_LORA
}
void beginFDRS() {
#ifdef FDRS_DEBUG
Serial.begin(115200);
// find out the reset reason
esp_reset_reason_t resetReason;
resetReason = esp_reset_reason();
#endif
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
DBG(" Gateway: " + String (GTWY_MAC, HEX));
@ -137,7 +114,7 @@ void beginFDRS() {
}
#endif
DBG(" ESP-NOW Initialized.");
#endif
#endif //USE_ESPNOW
#ifdef USE_LORA
DBG("Initializing LoRa!");
#ifdef ESP32
@ -150,13 +127,16 @@ void beginFDRS() {
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa Initialized.");
#ifdef DEBUG_NODE_CONFIG
debugConfig();
#else
DBG("LoRa Band: " + String(FDRS_BAND));
DBG("LoRa SF : " + String(FDRS_SF));
#endif //DEBUG_NODE_CONFIG
#endif // USE_LORA
#ifdef DEBUG_NODE_CONFIG
if (resetReason != ESP_RST_DEEPSLEEP) {
checkConfig();
}
#endif //DEBUG_NODE_CONFIG
}
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
@ -203,6 +183,7 @@ void sleepFDRS(int sleep_time) {
#ifdef ESP32
esp_sleep_enable_timer_wakeup(sleep_time * 1000000);
esp_deep_sleep_start();
#endif
#ifdef ESP8266
ESP.deepSleep(sleep_time * 1000000);