Debugging enhanced

Definition of DEBUG in the main sketch (easy to change)
DBG definition
Use Serial2 instead of Serial1 for the ESP32
Changed the concept of UART.IF in the -5 sketch: Debug is always Serial and the ESP32 gets an additional Serial2 for communication

esp_now_peer_info_t peerInfo; seems not needed anymore

added a ROLE definition. With this definition it should be possible to have the same directory for all roles. We can discuss this in Skype if you want
This commit is contained in:
sensorsiot 2022-05-21 23:50:45 +02:00
parent 27bcaf16cc
commit aee0ada35e
15 changed files with 78 additions and 63 deletions

View File

@ -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"

View File

@ -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;

View File

@ -12,7 +12,6 @@
#define DEEP_SLEEP
//#define POWER_CTRL 14
#define DEBUG
//#define CREDENTIALS
#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 <credentials.h>
#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 <LoRa.h>
#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);

View File

@ -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

View File

@ -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

View File

@ -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 <credentials.h>
#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 <credentials.h>
#endif

View File

@ -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};

View File

@ -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

View File

@ -42,4 +42,3 @@
#define NUM_LEDS 4
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
#define UART_IF Serial1

View File

@ -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

View File

@ -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);

View File

@ -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 <ESP8266WiFi.h>
#include <espnow.h>
@ -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<WS2812B, LED_PIN, GRB>(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() {

View File

@ -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

View File

@ -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 <credentials.h>
@ -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

View File

@ -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];
}