mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Applied changes to FDRS_Sensor and FDRS_Gateway folders
This commit is contained in:
parent
ae85886e65
commit
62c247275a
@ -45,12 +45,26 @@ void setup() {
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DBG("Address:" + String (UNIT_MAC, HEX));
|
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
|
#ifdef USE_LED
|
||||||
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
||||||
leds[0] = CRGB::Blue;
|
leds[0] = CRGB::Blue;
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_LORA
|
||||||
|
begin_lora();
|
||||||
|
#endif
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
delay(10);
|
delay(10);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
@ -69,9 +83,7 @@ void setup() {
|
|||||||
#else
|
#else
|
||||||
begin_espnow();
|
begin_espnow();
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_LORA
|
|
||||||
begin_lora();
|
|
||||||
#endif
|
|
||||||
#ifdef USE_SD_LOG
|
#ifdef USE_SD_LOG
|
||||||
begin_SD();
|
begin_SD();
|
||||||
#endif
|
#endif
|
||||||
@ -152,7 +164,7 @@ void loop() {
|
|||||||
client.loop(); // for recieving incoming messages and maintaining connection
|
client.loop(); // for recieving incoming messages and maintaining connection
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (newData) {
|
if (newData != event_clear) {
|
||||||
switch (newData) {
|
switch (newData) {
|
||||||
case event_espnowg:
|
case event_espnowg:
|
||||||
ESPNOWG_ACT
|
ESPNOWG_ACT
|
||||||
|
@ -19,6 +19,7 @@ enum {
|
|||||||
event_lora1,
|
event_lora1,
|
||||||
event_lora2
|
event_lora2
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef FDRS_DEBUG
|
#ifdef FDRS_DEBUG
|
||||||
#define DBG(a) (Serial.println(a))
|
#define DBG(a) (Serial.println(a))
|
||||||
#else
|
#else
|
||||||
@ -31,32 +32,99 @@ enum {
|
|||||||
#define UART_IF Serial
|
#define UART_IF Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FDRS_GLOBALS
|
// enable to get detailed info from where single configuration macros have been taken
|
||||||
#define FDRS_WIFI_SSID GLOBAL_SSID
|
#define DEBUG_NODE_CONFIG
|
||||||
#define FDRS_WIFI_PASS GLOBAL_PASS
|
|
||||||
#define FDRS_MQTT_ADDR GLOBAL_MQTT_ADDR
|
#ifdef USE_WIFI
|
||||||
#define FDRS_MQTT_PORT GLOBAL_MQTT_PORT
|
|
||||||
#define FDRS_MQTT_USER GLOBAL_MQTT_USER
|
// select WiFi SSID configuration
|
||||||
#define FDRS_MQTT_PASS GLOBAL_MQTT_PASS
|
#if defined(WIFI_SSID)
|
||||||
#define FDRS_BAND GLOBAL_LORA_BAND
|
|
||||||
#define FDRS_SF GLOBAL_LORA_SF
|
|
||||||
#else
|
|
||||||
#define FDRS_WIFI_SSID 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
|
#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
|
#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
|
#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
|
#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
|
#define FDRS_MQTT_PASS MQTT_PASS
|
||||||
#define FDRS_BAND LORA_BAND
|
#elif defined (GLOBAL_MQTT_PASS)
|
||||||
#define FDRS_SF LORA_SF
|
#define FDRS_MQTT_PASS GLOBAL_MQTT_PASS
|
||||||
#endif
|
#else
|
||||||
|
// 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)
|
#if defined (MQTT_AUTH) || defined (GLOBAL_MQTT_AUTH)
|
||||||
#define FDRS_MQTT_AUTH
|
#define FDRS_MQTT_AUTH
|
||||||
#endif
|
#endif //MQTT_AUTH
|
||||||
|
|
||||||
|
#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
|
||||||
|
#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
|
||||||
|
|
||||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
|
#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 {
|
typedef struct __attribute__((packed)) DataReading {
|
||||||
float d;
|
float d;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
@ -103,6 +171,7 @@ DataReading theData[256];
|
|||||||
uint8_t ln;
|
uint8_t ln;
|
||||||
uint8_t newData = event_clear;
|
uint8_t newData = event_clear;
|
||||||
|
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
DataReading ESPNOW1buffer[256];
|
DataReading ESPNOW1buffer[256];
|
||||||
uint8_t lenESPNOW1 = 0;
|
uint8_t lenESPNOW1 = 0;
|
||||||
uint32_t timeESPNOW1 = 0;
|
uint32_t timeESPNOW1 = 0;
|
||||||
@ -112,12 +181,16 @@ uint32_t timeESPNOW2 = 0;
|
|||||||
DataReading ESPNOWGbuffer[256];
|
DataReading ESPNOWGbuffer[256];
|
||||||
uint8_t lenESPNOWG = 0;
|
uint8_t lenESPNOWG = 0;
|
||||||
uint32_t timeESPNOWG = 0;
|
uint32_t timeESPNOWG = 0;
|
||||||
|
#endif //USE_ESPNOW
|
||||||
|
|
||||||
DataReading SERIALbuffer[256];
|
DataReading SERIALbuffer[256];
|
||||||
uint8_t lenSERIAL = 0;
|
uint8_t lenSERIAL = 0;
|
||||||
uint32_t timeSERIAL = 0;
|
uint32_t timeSERIAL = 0;
|
||||||
DataReading MQTTbuffer[256];
|
DataReading MQTTbuffer[256];
|
||||||
uint8_t lenMQTT = 0;
|
uint8_t lenMQTT = 0;
|
||||||
uint32_t timeMQTT = 0;
|
uint32_t timeMQTT = 0;
|
||||||
|
|
||||||
|
#ifdef USE_LORA
|
||||||
DataReading LORAGbuffer[256];
|
DataReading LORAGbuffer[256];
|
||||||
uint8_t lenLORAG = 0;
|
uint8_t lenLORAG = 0;
|
||||||
uint32_t timeLORAG = 0;
|
uint32_t timeLORAG = 0;
|
||||||
@ -127,28 +200,31 @@ uint32_t timeLORA1 = 0;
|
|||||||
DataReading LORA2buffer[256];
|
DataReading LORA2buffer[256];
|
||||||
uint8_t lenLORA2 = 0;
|
uint8_t lenLORA2 = 0;
|
||||||
uint32_t timeLORA2 = 0;
|
uint32_t timeLORA2 = 0;
|
||||||
|
#endif //USE_LORA
|
||||||
|
|
||||||
WiFiClient espClient;
|
|
||||||
#ifdef USE_LED
|
#ifdef USE_LED
|
||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
#endif
|
#endif //USE_LED
|
||||||
|
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
const char* ssid = FDRS_WIFI_SSID;
|
const char* ssid = FDRS_WIFI_SSID;
|
||||||
const char* password = FDRS_WIFI_PASS;
|
const char* password = FDRS_WIFI_PASS;
|
||||||
const char* mqtt_server = FDRS_MQTT_ADDR;
|
const char* mqtt_server = FDRS_MQTT_ADDR;
|
||||||
const int mqtt_port = FDRS_MQTT_PORT;
|
const int mqtt_port = FDRS_MQTT_PORT;
|
||||||
#endif
|
|
||||||
#ifdef FDRS_MQTT_AUTH
|
#ifdef FDRS_MQTT_AUTH
|
||||||
const char* mqtt_user = FDRS_MQTT_USER;
|
const char* mqtt_user = FDRS_MQTT_USER;
|
||||||
const char* mqtt_pass = FDRS_MQTT_PASS;
|
const char* mqtt_pass = FDRS_MQTT_PASS;
|
||||||
#else
|
#else
|
||||||
const char* mqtt_user = NULL;
|
const char* mqtt_user = NULL;
|
||||||
const char* mqtt_pass = NULL;
|
const char* mqtt_pass = NULL;
|
||||||
#endif
|
#endif //FDRS_MQTT_AUTH
|
||||||
|
|
||||||
|
|
||||||
|
#endif //USE_WIFI
|
||||||
|
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
// Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32
|
// Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||||
@ -173,6 +249,8 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
|
|||||||
}
|
}
|
||||||
newData = event_espnowg;
|
newData = event_espnowg;
|
||||||
}
|
}
|
||||||
|
#endif //USE_ESPNOW
|
||||||
|
|
||||||
void getSerial() {
|
void getSerial() {
|
||||||
String incomingString = UART_IF.readStringUntil('\n');
|
String incomingString = UART_IF.readStringUntil('\n');
|
||||||
DynamicJsonDocument doc(24576);
|
DynamicJsonDocument doc(24576);
|
||||||
@ -195,6 +273,7 @@ void getSerial() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (USE_SD_LOG) || defined (USE_FS_LOG)
|
#if defined (USE_SD_LOG) || defined (USE_FS_LOG)
|
||||||
void releaseLogBuffer()
|
void releaseLogBuffer()
|
||||||
{
|
{
|
||||||
@ -214,6 +293,7 @@ void releaseLogBuffer()
|
|||||||
logBufferPos = 0;
|
logBufferPos = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void sendLog()
|
void sendLog()
|
||||||
{
|
{
|
||||||
#if defined (USE_SD_LOG) || defined (USE_FS_LOG)
|
#if defined (USE_SD_LOG) || defined (USE_FS_LOG)
|
||||||
@ -230,8 +310,9 @@ void sendLog()
|
|||||||
memcpy(&logBuffer[logBufferPos], linebuf, strlen(linebuf)); //append line to buffer
|
memcpy(&logBuffer[logBufferPos], linebuf, strlen(linebuf)); //append line to buffer
|
||||||
logBufferPos+=strlen(linebuf);
|
logBufferPos+=strlen(linebuf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif //USE_xx_LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect(short int attempts, bool silent) {
|
void reconnect(short int attempts, bool silent) {
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
|
|
||||||
@ -257,11 +338,13 @@ void reconnect(short int attempts, bool silent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!silent) DBG(" Connecting MQTT failed.");
|
if (!silent) DBG(" Connecting MQTT failed.");
|
||||||
#endif
|
#endif //USE_WIFI
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect(int attempts) {
|
void reconnect(int attempts) {
|
||||||
reconnect(attempts, false);
|
reconnect(attempts, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_callback(char* topic, byte * message, unsigned int length) {
|
void mqtt_callback(char* topic, byte * message, unsigned int length) {
|
||||||
String incomingString;
|
String incomingString;
|
||||||
DBG(topic);
|
DBG(topic);
|
||||||
@ -288,13 +371,14 @@ void mqtt_callback(char* topic, byte * message, unsigned int length) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_publish(const char* payload) {
|
void mqtt_publish(const char* payload) {
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
if (!client.publish(TOPIC_DATA, payload)) {
|
if (!client.publish(TOPIC_DATA, payload)) {
|
||||||
DBG(" Error on sending MQTT");
|
DBG(" Error on sending MQTT");
|
||||||
sendLog();
|
sendLog();
|
||||||
}
|
}
|
||||||
#endif
|
#endif //USE_WIFI
|
||||||
}
|
}
|
||||||
|
|
||||||
void getLoRa() {
|
void getLoRa() {
|
||||||
@ -320,10 +404,11 @@ void getLoRa() {
|
|||||||
newData = event_lorag;
|
newData = event_lorag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif //USE_LORA
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendESPNOW(uint8_t address) {
|
void sendESPNOW(uint8_t address) {
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
DBG("Sending ESP-NOW.");
|
DBG("Sending ESP-NOW.");
|
||||||
uint8_t NEWPEER[] = {MAC_PREFIX, address};
|
uint8_t NEWPEER[] = {MAC_PREFIX, address};
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
@ -350,6 +435,7 @@ void sendESPNOW(uint8_t address) {
|
|||||||
}
|
}
|
||||||
esp_now_send(NEWPEER, (uint8_t *) &thePacket, j * sizeof(DataReading));
|
esp_now_send(NEWPEER, (uint8_t *) &thePacket, j * sizeof(DataReading));
|
||||||
esp_now_del_peer(NEWPEER);
|
esp_now_del_peer(NEWPEER);
|
||||||
|
#endif //USE_ESPNOW
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendSerial() {
|
void sendSerial() {
|
||||||
@ -381,10 +467,11 @@ void sendMQTT() {
|
|||||||
String outgoingString;
|
String outgoingString;
|
||||||
serializeJson(doc, outgoingString);
|
serializeJson(doc, outgoingString);
|
||||||
mqtt_publish((char*) outgoingString.c_str());
|
mqtt_publish((char*) outgoingString.c_str());
|
||||||
#endif
|
#endif //USE_WIFI
|
||||||
}
|
}
|
||||||
|
|
||||||
void bufferESPNOW(uint8_t interface) {
|
void bufferESPNOW(uint8_t interface) {
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
DBG("Buffering ESP-NOW.");
|
DBG("Buffering ESP-NOW.");
|
||||||
|
|
||||||
switch (interface) {
|
switch (interface) {
|
||||||
@ -407,7 +494,9 @@ void bufferESPNOW(uint8_t interface) {
|
|||||||
lenESPNOW2 += ln;
|
lenESPNOW2 += ln;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif USE_ESPNOW
|
||||||
}
|
}
|
||||||
|
|
||||||
void bufferSerial() {
|
void bufferSerial() {
|
||||||
DBG("Buffering Serial.");
|
DBG("Buffering Serial.");
|
||||||
for (int i = 0; i < ln; i++) {
|
for (int i = 0; i < ln; i++) {
|
||||||
@ -416,6 +505,7 @@ void bufferSerial() {
|
|||||||
lenSERIAL += ln;
|
lenSERIAL += ln;
|
||||||
//UART_IF.println("SENDSERIAL:" + String(lenSERIAL) + " ");
|
//UART_IF.println("SENDSERIAL:" + String(lenSERIAL) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void bufferMQTT() {
|
void bufferMQTT() {
|
||||||
DBG("Buffering MQTT.");
|
DBG("Buffering MQTT.");
|
||||||
for (int i = 0; i < ln; i++) {
|
for (int i = 0; i < ln; i++) {
|
||||||
@ -423,13 +513,16 @@ void bufferMQTT() {
|
|||||||
}
|
}
|
||||||
lenMQTT += ln;
|
lenMQTT += ln;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void bufferLoRa() {
|
//void bufferLoRa() {
|
||||||
// for (int i = 0; i < ln; i++) {
|
// for (int i = 0; i < ln; i++) {
|
||||||
// LORAbuffer[lenLORA + i] = theData[i];
|
// LORAbuffer[lenLORA + i] = theData[i];
|
||||||
// }
|
// }
|
||||||
// lenLORA += ln;
|
// lenLORA += ln;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void bufferLoRa(uint8_t interface) {
|
void bufferLoRa(uint8_t interface) {
|
||||||
|
#ifdef USE_LORA
|
||||||
DBG("Buffering LoRa.");
|
DBG("Buffering LoRa.");
|
||||||
switch (interface) {
|
switch (interface) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -451,9 +544,11 @@ void bufferLoRa(uint8_t interface) {
|
|||||||
lenLORA2 += ln;
|
lenLORA2 += ln;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif //USE_LORA
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseESPNOW(uint8_t interface) {
|
void releaseESPNOW(uint8_t interface) {
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
DBG("Releasing ESP-NOW.");
|
DBG("Releasing ESP-NOW.");
|
||||||
switch (interface) {
|
switch (interface) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -505,7 +600,9 @@ void releaseESPNOW(uint8_t interface) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif USE_ESPNOW
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||||
DBG("Transmitting LoRa.");
|
DBG("Transmitting LoRa.");
|
||||||
@ -578,6 +675,7 @@ void releaseLoRa(uint8_t interface) {
|
|||||||
}
|
}
|
||||||
#endif //USE_LORA
|
#endif //USE_LORA
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseSerial() {
|
void releaseSerial() {
|
||||||
DBG("Releasing Serial.");
|
DBG("Releasing Serial.");
|
||||||
DynamicJsonDocument doc(24576);
|
DynamicJsonDocument doc(24576);
|
||||||
@ -590,6 +688,7 @@ void releaseSerial() {
|
|||||||
UART_IF.println();
|
UART_IF.println();
|
||||||
lenSERIAL = 0;
|
lenSERIAL = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseMQTT() {
|
void releaseMQTT() {
|
||||||
#ifdef USE_WIFI
|
#ifdef USE_WIFI
|
||||||
DBG("Releasing MQTT.");
|
DBG("Releasing MQTT.");
|
||||||
@ -603,9 +702,11 @@ void releaseMQTT() {
|
|||||||
serializeJson(doc, outgoingString);
|
serializeJson(doc, outgoingString);
|
||||||
mqtt_publish((char*) outgoingString.c_str());
|
mqtt_publish((char*) outgoingString.c_str());
|
||||||
lenMQTT = 0;
|
lenMQTT = 0;
|
||||||
#endif
|
#endif //USE_WIFI
|
||||||
}
|
}
|
||||||
|
|
||||||
void begin_espnow() {
|
void begin_espnow() {
|
||||||
|
#ifdef USE_ESPNOW
|
||||||
DBG("Initializing ESP-NOW!");
|
DBG("Initializing ESP-NOW!");
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
@ -659,6 +760,7 @@ void begin_espnow() {
|
|||||||
#endif
|
#endif
|
||||||
#endif //ESP8266
|
#endif //ESP8266
|
||||||
DBG(" ESP-NOW Initialized.");
|
DBG(" ESP-NOW Initialized.");
|
||||||
|
#endif //USE_ESPNOW
|
||||||
}
|
}
|
||||||
|
|
||||||
void begin_lora() {
|
void begin_lora() {
|
||||||
@ -673,10 +775,9 @@ void begin_lora() {
|
|||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
LoRa.setSpreadingFactor(FDRS_SF);
|
||||||
DBG(" LoRa initialized.");
|
|
||||||
DBG("LoRa Band: " + String(FDRS_BAND));
|
DBG("LoRa Band: " + String(FDRS_BAND));
|
||||||
DBG("LoRa SF : " + String(FDRS_SF));
|
DBG("LoRa SF : " + String(FDRS_SF));
|
||||||
#endif //USE_LORA
|
#endif // USE_LORA
|
||||||
}
|
}
|
||||||
|
|
||||||
void begin_SD() {
|
void begin_SD() {
|
||||||
@ -707,7 +808,7 @@ void begin_FS() {
|
|||||||
{
|
{
|
||||||
DBG(" LittleFS initialized");
|
DBG(" LittleFS initialized");
|
||||||
}
|
}
|
||||||
#endif
|
#endif // USE_FS_LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__FDRS_FUNCTIONS_H__
|
#endif //__FDRS_FUNCTIONS_H__
|
||||||
|
@ -16,8 +16,11 @@
|
|||||||
#define MQTT_ACT
|
#define MQTT_ACT
|
||||||
#define LORAG_ACT sendSerial();
|
#define LORAG_ACT sendSerial();
|
||||||
|
|
||||||
|
// protocols -- Define which protocols the gateways should handle.
|
||||||
|
// Warning: ESP-NOW and WiFi are mutual exclusive!
|
||||||
//#define USE_LORA
|
//#define USE_LORA
|
||||||
//#define USE_WIFI //Used only for MQTT gateway
|
#define USE_ESPNOW
|
||||||
|
//#define USE_WIFI //Used only for MQTT gateway
|
||||||
|
|
||||||
// Peer addresses
|
// Peer addresses
|
||||||
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
#define ESPNOW1_PEER 0x0E // ESPNOW1 Address
|
||||||
@ -77,14 +80,14 @@
|
|||||||
#define NUM_LEDS 4
|
#define NUM_LEDS 4
|
||||||
|
|
||||||
// WiFi and MQTT Credentials -- Needed for MQTT only if "fdrs_globals.h" is not included
|
// WiFi and MQTT Credentials -- Needed for MQTT only if "fdrs_globals.h" is not included
|
||||||
#define WIFI_SSID "Your SSID"
|
//#define WIFI_SSID "Your SSID"
|
||||||
#define WIFI_PASS "Your Password"
|
//#define WIFI_PASS "Your Password"
|
||||||
#define MQTT_ADDR "192.168.0.8"
|
//#define MQTT_ADDR "192.168.0.8"
|
||||||
#define MQTT_PORT 1883 // Default MQTT port is 1883
|
//#define MQTT_PORT 1883 // Default MQTT port is 1883
|
||||||
|
|
||||||
//#define MQTT_AUTH //Enable MQTT authentication
|
//#define MQTT_AUTH //Enable MQTT authentication
|
||||||
#define MQTT_USER "Your MQTT Username"
|
//#define MQTT_USER "Your MQTT Username"
|
||||||
#define MQTT_PASS "Your MQTT Password"
|
//#define MQTT_PASS "Your MQTT Password"
|
||||||
|
|
||||||
// MQTT Topics
|
// MQTT Topics
|
||||||
#define TOPIC_DATA "fdrs/data"
|
#define TOPIC_DATA "fdrs/data"
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||||
// An example of how to send data using "fdrs_sensor.h".
|
// An example of how to send data using "fdrs_sensor.h".
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "fdrs_sensor_config.h"
|
#include "fdrs_sensor_config.h"
|
||||||
|
|
||||||
//#include <fdrs_sensor.h> //Use global functions file
|
//#include <fdrs_sensor.h> //Use global functions file
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// enable to get detailed info from where single configuration macros have been taken
|
// enable to get detailed info from where single configuration macros have been taken
|
||||||
//#define DEBUG_NODE_CONFIG
|
#define DEBUG_NODE_CONFIG
|
||||||
|
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
|
|
||||||
@ -50,6 +50,10 @@
|
|||||||
|
|
||||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.
|
#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 {
|
typedef struct __attribute__((packed)) DataReading {
|
||||||
float d;
|
float d;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
@ -67,39 +71,12 @@ DataReading fdrsData[espnow_size];
|
|||||||
uint8_t data_count = 0;
|
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() {
|
void beginFDRS() {
|
||||||
#ifdef FDRS_DEBUG
|
#ifdef FDRS_DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
// find out the reset reason
|
||||||
|
esp_reset_reason_t resetReason;
|
||||||
|
resetReason = esp_reset_reason();
|
||||||
#endif
|
#endif
|
||||||
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
|
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
|
||||||
DBG(" Gateway: " + String (GTWY_MAC, HEX));
|
DBG(" Gateway: " + String (GTWY_MAC, HEX));
|
||||||
@ -137,7 +114,7 @@ void beginFDRS() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
DBG(" ESP-NOW Initialized.");
|
DBG(" ESP-NOW Initialized.");
|
||||||
#endif
|
#endif //USE_ESPNOW
|
||||||
#ifdef USE_LORA
|
#ifdef USE_LORA
|
||||||
DBG("Initializing LoRa!");
|
DBG("Initializing LoRa!");
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@ -150,13 +127,16 @@ void beginFDRS() {
|
|||||||
}
|
}
|
||||||
LoRa.setSpreadingFactor(FDRS_SF);
|
LoRa.setSpreadingFactor(FDRS_SF);
|
||||||
DBG(" LoRa Initialized.");
|
DBG(" LoRa Initialized.");
|
||||||
#ifdef DEBUG_NODE_CONFIG
|
|
||||||
debugConfig();
|
|
||||||
#else
|
|
||||||
DBG("LoRa Band: " + String(FDRS_BAND));
|
DBG("LoRa Band: " + String(FDRS_BAND));
|
||||||
DBG("LoRa SF : " + String(FDRS_SF));
|
DBG("LoRa SF : " + String(FDRS_SF));
|
||||||
#endif //DEBUG_NODE_CONFIG
|
|
||||||
#endif // USE_LORA
|
#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) {
|
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// Basic Sensor Example
|
// Basic Sensor Example
|
||||||
//
|
//
|
||||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||||
// An example of how to send data using "fdrs_sensor.h".
|
// An example of how to send data using "fdrs_sensor.h".
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -183,7 +183,6 @@ void sleepFDRS(int sleep_time) {
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
esp_sleep_enable_timer_wakeup(sleep_time * 1000000);
|
esp_sleep_enable_timer_wakeup(sleep_time * 1000000);
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
ESP.deepSleep(sleep_time * 1000000);
|
ESP.deepSleep(sleep_time * 1000000);
|
||||||
|
Loading…
Reference in New Issue
Block a user