Merge pull request #72 from Gulpman/dev

Dev - partial fix of #71
This commit is contained in:
Timm Bogner 2022-07-22 01:55:23 -05:00 committed by GitHub
commit 62685452ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 386 additions and 85 deletions

View File

@ -660,6 +660,7 @@ void begin_espnow() {
#endif //ESP8266
DBG(" ESP-NOW Initialized.");
}
void begin_lora() {
#ifdef USE_LORA
DBG("Initializing LoRa!");
@ -673,8 +674,11 @@ void begin_lora() {
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa initialized.");
DBG("LoRa Band: " + String(FDRS_BAND));
DBG("LoRa SF : " + String(FDRS_SF));
#endif //USE_LORA
}
void begin_SD() {
#ifdef USE_SD_LOG
DBG("Initializing SD card...");
@ -689,6 +693,7 @@ void begin_SD() {
}
#endif //USE_SD_LOG
}
void begin_FS() {
#ifdef USE_FS_LOG
DBG("Initializing LittleFS...");

View File

@ -57,8 +57,8 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7
// Buffer Delays - in milliseconds - Uncomment to enable any buffer

View File

@ -17,13 +17,30 @@
#include <LoRa.h>
#endif
#ifdef FDRS_GLOBALS
#define FDRS_BAND GLOBAL_LORA_BAND
#define FDRS_SF GLOBAL_LORA_SF
#else
// enable to get detailed info from where single configuration macros have been taken
//#define DEBUG_NODE_CONFIG
#ifdef USE_LORA
// select LoRa band configuration
#if defined(LORA_BAND)
#define FDRS_BAND LORA_BAND
#elif defined (GLOBAL_LORA_BAND)
#define FDRS_BAND GLOBAL_LORA_BAND
#else
// ASSERT("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_BAND
// select LoRa SF configuration
#if defined(LORA_SF)
#define FDRS_SF LORA_SF
#endif
#elif defined (GLOBAL_LORA_SF)
#define FDRS_SF GLOBAL_LORA_SF
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_SF
#endif //USE_LORA
#ifdef FDRS_DEBUG
#define DBG(a) (Serial.println(a))
@ -49,6 +66,37 @@ uint32_t wait_time = 0;
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);
@ -92,8 +140,6 @@ void beginFDRS() {
#endif
#ifdef USE_LORA
DBG("Initializing LoRa!");
DBG(FDRS_BAND);
DBG(FDRS_SF);
#ifdef ESP32
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
#endif
@ -104,8 +150,15 @@ void beginFDRS() {
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa Initialized.");
#endif
#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
}
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
#ifdef USE_LORA
uint8_t pkt[5 + (len * sizeof(DataReading))];
@ -117,6 +170,7 @@ void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
LoRa.endPacket();
#endif
}
void sendFDRS() {
DBG("Sending FDRS Packet!");
#ifdef USE_ESPNOW
@ -130,8 +184,9 @@ void sendFDRS() {
#endif
data_count = 0;
}
void loadFDRS(float d, uint8_t t) {
DBG("Data loaded. Type: " + String(t));
DBG("Id: " + String(READING_ID) + " - Type: " + String(t) + " - Data loaded: " + String(d));
if (data_count > espnow_size) sendFDRS();
DataReading dr;
dr.id = READING_ID;
@ -140,6 +195,7 @@ void loadFDRS(float d, uint8_t t) {
fdrsData[data_count] = dr;
data_count++;
}
void sleepFDRS(int sleep_time) {
DBG("Sleepytime!");
#ifdef DEEP_SLEEP

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -29,5 +29,5 @@ float readTemp() {
}
float readHum() {
return (0,100);
return random(0,100);
}

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -29,5 +29,5 @@ float readTemp() {
}
float readHum() {
return (0,100);
return random(0,100);
}

View File

@ -57,8 +57,8 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7
// Buffer Delays - in milliseconds - Uncomment to enable any buffer
@ -77,14 +77,14 @@
#define NUM_LEDS 4
// WiFi and MQTT Credentials -- Needed for MQTT only if "fdrs_globals.h" is not included
#define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password"
#define MQTT_ADDR "192.168.0.8"
#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define WIFI_SSID "Your SSID"
//#define WIFI_PASS "Your Password"
//#define MQTT_ADDR "192.168.0.8"
//#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define MQTT_AUTH //Enable MQTT authentication
#define MQTT_USER "Your MQTT Username"
#define MQTT_PASS "Your MQTT Password"
//#define MQTT_USER "Your MQTT Username"
//#define MQTT_PASS "Your MQTT Password"
// MQTT Topics
#define TOPIC_DATA "fdrs/data"

View File

@ -57,8 +57,8 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7
// Buffer Delays - in milliseconds - Uncomment to enable any buffer
@ -77,14 +77,14 @@
#define NUM_LEDS 4
// WiFi and MQTT Credentials -- Needed for MQTT only if "fdrs_globals.h" is not included
#define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password"
#define MQTT_ADDR "192.168.0.8"
#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define WIFI_SSID "Your SSID"
//#define WIFI_PASS "Your Password"
//#define MQTT_ADDR "192.168.0.8"
//#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define MQTT_AUTH //Enable MQTT authentication
#define MQTT_USER "Your MQTT Username"
#define MQTT_PASS "Your MQTT Password"
//#define MQTT_USER "Your MQTT Username"
//#define MQTT_PASS "Your MQTT Password"
// MQTT Topics
#define TOPIC_DATA "fdrs/data"

View File

@ -57,8 +57,8 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7
// Buffer Delays - in milliseconds - Uncomment to enable any buffer
@ -77,14 +77,14 @@
#define NUM_LEDS 4
// WiFi and MQTT Credentials -- Needed for MQTT only if "fdrs_globals.h" is not included
#define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password"
#define MQTT_ADDR "192.168.0.8"
#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define WIFI_SSID "Your SSID"
//#define WIFI_PASS "Your Password"
//#define MQTT_ADDR "192.168.0.8"
//#define MQTT_PORT 1883 // Default MQTT port is 1883
//#define MQTT_AUTH //Enable MQTT authentication
#define MQTT_USER "Your MQTT Username"
#define MQTT_PASS "Your MQTT Password"
//#define MQTT_USER "Your MQTT Username"
//#define MQTT_PASS "Your MQTT Password"
// MQTT Topics
#define TOPIC_DATA "fdrs/data"

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -25,5 +25,5 @@
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define LORA_BAND 915E6
#define LORA_SF 7
//#define LORA_BAND 915E6
//#define LORA_SF 7

View File

@ -554,6 +554,8 @@ void LoRa_FDRSGateWay::init(uint8_t mac[6]){
}
LoRa.setSpreadingFactor(_sf);
DBG(" LoRa initialized.");
DBG("LoRa Band: " + String(_band));
DBG("LoRa SF : " + String(_sf));
}
void LoRa_FDRSGateWay::add_peer(uint8_t peer_mac[6]){

View File

@ -554,6 +554,8 @@ void LoRa_FDRSGateWay::init(uint8_t mac[6]){
}
LoRa.setSpreadingFactor(_sf);
DBG(" LoRa initialized.");
DBG("LoRa Band: " + String(_band));
DBG("LoRa SF : " + String(_sf));
}
void LoRa_FDRSGateWay::add_peer(uint8_t peer_mac[6]){

View File

@ -152,8 +152,6 @@ FDRSLoRa::FDRSLoRa(uint8_t gtwy_mac,
void FDRSLoRa::init(void){
DBG("Initializing LoRa!");
DBG("LoRa Band: " + String(_band));
DBG("LoRa SF : " + String(_sf));
#ifdef ESP32
SPI.begin(_sck, _miso, _mosi);
#endif
@ -164,6 +162,8 @@ void FDRSLoRa::init(void){
}
LoRa.setSpreadingFactor(_sf);
DBG("LoRa Initialized.");
DBG("LoRa Band: " + String(_band));
DBG("LoRa SF : " + String(_sf));
}
void FDRSLoRa::buildPacket(uint8_t* mac, DataReading_t * packet, uint8_t len) {

View File

@ -19,6 +19,7 @@ enum {
event_lora1,
event_lora2
};
#ifdef FDRS_DEBUG
#define DBG(a) (Serial.println(a))
#else
@ -31,25 +32,88 @@ enum {
#define UART_IF Serial
#endif
#ifdef FDRS_GLOBALS
#define FDRS_WIFI_SSID GLOBAL_SSID
#define FDRS_WIFI_PASS GLOBAL_PASS
#define FDRS_MQTT_ADDR GLOBAL_MQTT_ADDR
#define FDRS_MQTT_PORT GLOBAL_MQTT_PORT
#define FDRS_MQTT_USER GLOBAL_MQTT_USER
#define FDRS_MQTT_PASS GLOBAL_MQTT_PASS
#define FDRS_BAND GLOBAL_LORA_BAND
#define FDRS_SF GLOBAL_LORA_SF
#else
// enable to get detailed info from where single configuration macros have been taken
#define DEBUG_NODE_CONFIG
#ifdef USE_WIFI
// select WiFi SSID configuration
#if defined(WIFI_SSID)
#define FDRS_WIFI_SSID WIFI_SSID
#elif defined (GLOBAL_SSID)
#define FDRS_WIFI_SSID GLOBAL_SSID
#else
// ASSERT("NO WiFi SSID defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //WIFI_SSID
// select WiFi password
#if defined(WIFI_PASS)
#define FDRS_WIFI_PASS WIFI_PASS
#elif defined (GLOBAL_PASS)
#define FDRS_WIFI_PASS GLOBAL_PASS
#else
// ASSERT("NO WiFi password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //WIFI_PASS
// select MQTT server address
#if defined(MQTT_ADDR)
#define FDRS_MQTT_ADDR MQTT_ADDR
#elif defined (GLOBAL_MQTT_ADDR)
#define FDRS_MQTT_ADDR GLOBAL_MQTT_ADDR
#else
// ASSERT("NO MQTT address defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //MQTT_ADDR
// select MQTT server port
#if defined(MQTT_PORT)
#define FDRS_MQTT_PORT MQTT_PORT
#elif defined (GLOBAL_MQTT_PORT)
#define FDRS_MQTT_PORT GLOBAL_MQTT_PORT
#else
#define FDRS_MQTT_PORT 1883
#endif //MQTT_PORT
// select MQTT user name
#if defined(MQTT_USER)
#define FDRS_MQTT_USER MQTT_USER
#elif defined (GLOBAL_MQTT_USER)
#define FDRS_MQTT_USER GLOBAL_MQTT_USER
#else
// ASSERT("NO MQTT user defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //MQTT_USER
// select MQTT user password
#if defined(MQTT_PASS)
#define FDRS_MQTT_PASS MQTT_PASS
#elif defined (GLOBAL_MQTT_PASS)
#define FDRS_MQTT_PASS GLOBAL_MQTT_PASS
#else
// ASSERT("NO MQTT password defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //MQTT_PASS
#endif //USE_WIFI
#ifdef USE_LORA
// select LoRa band configuration
#if defined(LORA_BAND)
#define FDRS_BAND LORA_BAND
#elif defined (GLOBAL_LORA_BAND)
#define FDRS_BAND GLOBAL_LORA_BAND
#else
// ASSERT("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_BAND
// select LoRa SF configuration
#if defined(LORA_SF)
#define FDRS_SF LORA_SF
#endif
#elif defined (GLOBAL_LORA_SF)
#define FDRS_SF GLOBAL_LORA_SF
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_SF
#endif //USE_LORA
#if defined (MQTT_AUTH) || defined (GLOBAL_MQTT_AUTH)
#define FDRS_MQTT_AUTH
@ -147,6 +211,101 @@ 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
@ -173,6 +332,7 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
}
newData = event_espnowg;
}
void getSerial() {
String incomingString = UART_IF.readStringUntil('\n');
DynamicJsonDocument doc(24576);
@ -214,6 +374,7 @@ void releaseLogBuffer()
logBufferPos = 0;
}
#endif
void sendLog()
{
#if defined (USE_SD_LOG) || defined (USE_FS_LOG)
@ -232,6 +393,7 @@ void sendLog()
}
#endif
}
void reconnect(short int attempts, bool silent) {
#ifdef USE_WIFI
@ -259,9 +421,11 @@ void reconnect(short int attempts, bool silent) {
if (!silent) DBG(" Connecting MQTT failed.");
#endif
}
void reconnect(int attempts) {
reconnect(attempts, false);
}
void mqtt_callback(char* topic, byte * message, unsigned int length) {
String incomingString;
DBG(topic);
@ -288,6 +452,7 @@ void mqtt_callback(char* topic, byte * message, unsigned int length) {
}
}
void mqtt_publish(const char* payload) {
#ifdef USE_WIFI
if (!client.publish(TOPIC_DATA, payload)) {
@ -429,6 +594,7 @@ void bufferMQTT() {
// }
// lenLORA += ln;
//}
void bufferLoRa(uint8_t interface) {
DBG("Buffering LoRa.");
switch (interface) {
@ -506,6 +672,7 @@ void releaseESPNOW(uint8_t interface) {
}
}
}
#ifdef USE_LORA
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
DBG("Transmitting LoRa.");
@ -578,6 +745,7 @@ void releaseLoRa(uint8_t interface) {
}
#endif //USE_LORA
}
void releaseSerial() {
DBG("Releasing Serial.");
DynamicJsonDocument doc(24576);
@ -590,6 +758,7 @@ void releaseSerial() {
UART_IF.println();
lenSERIAL = 0;
}
void releaseMQTT() {
#ifdef USE_WIFI
DBG("Releasing MQTT.");
@ -605,6 +774,7 @@ void releaseMQTT() {
lenMQTT = 0;
#endif
}
void begin_espnow() {
DBG("Initializing ESP-NOW!");
WiFi.mode(WIFI_STA);
@ -660,6 +830,7 @@ void begin_espnow() {
#endif //ESP8266
DBG(" ESP-NOW Initialized.");
}
void begin_lora() {
#ifdef USE_LORA
DBG("Initializing LoRa!");
@ -672,9 +843,15 @@ void begin_lora() {
while (1);
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa initialized.");
#endif //USE_LORA
#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
}
void begin_SD() {
#ifdef USE_SD_LOG
DBG("Initializing SD card...");
@ -689,6 +866,7 @@ void begin_SD() {
}
#endif //USE_SD_LOG
}
void begin_FS() {
#ifdef USE_FS_LOG
DBG("Initializing LittleFS...");

View File

@ -7,8 +7,10 @@
#ifndef FDRS_GLOBALS
#define FDRS_GLOBALS
#define GLOBAL_SSID "Your SSID"
#define GLOBAL_PASS "Password"
#define GLOBAL_MQTT_ADDR "192.168.0.8"
#define GLOBAL_MQTT_PORT 1883

View File

@ -17,13 +17,30 @@
#include <LoRa.h>
#endif
#ifdef FDRS_GLOBALS
#define FDRS_BAND GLOBAL_LORA_BAND
#define FDRS_SF GLOBAL_LORA_SF
#else
// enable to get detailed info from where single configuration macros have been taken
//#define DEBUG_NODE_CONFIG
#ifdef USE_LORA
// select LoRa band configuration
#if defined(LORA_BAND)
#define FDRS_BAND LORA_BAND
#elif defined (GLOBAL_LORA_BAND)
#define FDRS_BAND GLOBAL_LORA_BAND
#else
// ASSERT("NO LORA-BAND defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_BAND
// select LoRa SF configuration
#if defined(LORA_SF)
#define FDRS_SF LORA_SF
#endif
#elif defined (GLOBAL_LORA_SF)
#define FDRS_SF GLOBAL_LORA_SF
#else
// ASSERT("NO LORA-SF defined! Please define in fdrs_globals.h (recommended) or in fdrs_sensor_config.h");
#endif //LORA_SF
#endif //USE_LORA
#ifdef FDRS_DEBUG
#define DBG(a) (Serial.println(a))
@ -49,6 +66,37 @@ uint32_t wait_time = 0;
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);
@ -92,8 +140,6 @@ void beginFDRS() {
#endif
#ifdef USE_LORA
DBG("Initializing LoRa!");
DBG(FDRS_BAND);
DBG(FDRS_SF);
#ifdef ESP32
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
#endif
@ -104,8 +150,15 @@ void beginFDRS() {
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa Initialized.");
#endif
#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
}
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
#ifdef USE_LORA
uint8_t pkt[5 + (len * sizeof(DataReading))];
@ -117,6 +170,7 @@ void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
LoRa.endPacket();
#endif
}
void sendFDRS() {
DBG("Sending FDRS Packet!");
#ifdef USE_ESPNOW
@ -130,8 +184,9 @@ void sendFDRS() {
#endif
data_count = 0;
}
void loadFDRS(float d, uint8_t t) {
DBG("Data loaded. Type: " + String(t));
DBG("Id: " + String(READING_ID) + " - Type: " + String(t) + " - Data loaded: " + String(d));
if (data_count > espnow_size) sendFDRS();
DataReading dr;
dr.id = READING_ID;
@ -140,6 +195,7 @@ void loadFDRS(float d, uint8_t t) {
fdrsData[data_count] = dr;
data_count++;
}
void sleepFDRS(int sleep_time) {
DBG("Sleepytime!");
#ifdef DEEP_SLEEP