final adjustments

pull/12/head
Timm Bogner 2 years ago
parent 2d58380f83
commit 2008d0fb53

@ -8,7 +8,6 @@
#define DEBUG
#define CREDENTIALS
#include <fdrs_defaults.h>
#include "fdrs_config.h"
#ifdef ESP8266
@ -49,6 +48,8 @@ void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
DBG("Connecting to WiFi...");
DBG(FDRS_WIFI_SSID);
delay(500);
}
DBG("WiFi Connected");
@ -66,9 +67,10 @@ void setup() {
DBG("Initializing LoRa!");
SPI.begin(SCK, MISO, MOSI, SS);
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(BAND)) {
if (!LoRa.begin(FDRS_BAND)) {
while (1);
}
LoRa.setSpreadingFactor(FDRS_SF);
DBG(" LoRa initialized.");
#endif
@ -78,38 +80,54 @@ void setup() {
}
void loop() {
#ifdef ESPNOWG_DELAY
if (millis() > timeESPNOWG) {
timeESPNOWG += ESPNOWG_DELAY;
if (lenESPNOWG > 0) releaseESPNOW(0);
}
#endif
#ifdef ESPNOW1_DELAY
if (millis() > timeESPNOW1) {
timeESPNOW1 += ESPNOW1_DELAY;
if (lenESPNOW1 > 0) releaseESPNOW(1);
}
#endif
#ifdef ESPNOW2_DELAY
if (millis() > timeESPNOW2) {
timeESPNOW2 += ESPNOW2_DELAY;
if (lenESPNOW2 > 0) releaseESPNOW(2);
}
#endif
#ifdef SERIAL_DELAY
if (millis() > timeSERIAL) {
timeSERIAL += SERIAL_DELAY;
if (lenSERIAL > 0) releaseSerial();
}
#endif
#ifdef MQTT_DELAY
if (millis() > timeMQTT) {
timeMQTT += MQTT_DELAY;
if (lenMQTT > 0) releaseMQTT();
}
#endif
#ifdef LORAG_DELAY
if (millis() > timeLORAG) {
timeLORAG += LORAG_DELAY;
if (lenLORAG > 0) releaseLoRa(0);
}
#endif
#ifdef LORA1_DELAY
if (millis() > timeLORA1) {
timeLORA1 += LORA1_DELAY;
if (lenLORA1 > 0) releaseLoRa(1);
}
#endif
#ifdef LORA2_DELAY
if (millis() > timeLORA2) {
timeLORA2 += LORA2_DELAY;
if (lenLORA2 > 0) releaseLoRa(2);
}
#endif
while (UART_IF.available()) {
getSerial();

@ -2,11 +2,10 @@
//
// GATEWAY 2.000 Configuration
#define UNIT_MAC 0x05 // The address of this gateway
#define ESPNOW1_PEER 0xFD // ESPNOW1 Address
#define ESPNOW2_PEER 0xFE // ESPNOW2 Address
#define LORA1_PEER 0xFD // LoRa1 Address
#define LORA2_PEER 0xFE // LoRa2 Address
#include <fdrs_globals.h> //Uncomment if you install the globals file
#define DEBUG
#define UNIT_MAC 0x00 // The address of this gateway
//Actions -- Define what happens when a packet arrives at each interface:
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
@ -15,26 +14,68 @@
#define SERIAL_ACT sendMQTT();
#define MQTT_ACT
#define LORAG_ACT
#define USE_LORA
#define USE_WIFI //Used only for MQTT gateway
#define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password"
#define MQTT_ADDR "192.168.0.8"
// Peer Actions
#define ESPNOW1_ACT
#define ESPNOW2_ACT
#define LORA1_ACT
#define LORA2_ACT
//#define USE_LORA
#define USE_WIFI //Used only for MQTT gateway
// Peer addresses
#define ESPNOW1_PEER 0x04 // ESPNOW1 Address
#define ESPNOW2_PEER 0x05 // ESPNOW2 Address
#define LORA1_PEER 0x04 // LoRa1 Address
#define LORA2_PEER 0x05 // LoRa2 Address
// Buffer Delays - in milliseconds
//#define ESPNOW1_DELAY 0
//#define ESPNOW2_DELAY 0
//#define ESPNOWG_DELAY 0
//#define SERIAL_DELAY 0
//#define MQTT_DELAY 0
//#define LORAG_DELAY 1000
//#define LORA1_DELAY 1000
//#define LORA2_DELAY 1000
#if defined (ESP32)
//#define USE_LORA
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
//Pins for UART data interface (ESP32 only)
#define RXD2 14
#define TXD2 15
#define UART_IF Serial1
#else
#define UART_IF Serial
#endif
////LoRa Configuration -- Needed only if using LoRa
//LoRa Configuration -- Needed only if using LoRa
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 915E6
#define SF 7
//#define USE_LED //Not yet fully implemented
#define LED_PIN 32
#define NUM_LEDS 4
// MQTT Topics
#define TOPIC_DATA "FDRS/DATA"
#define TOPIC_STATUS "FDRS/STATUS"
#define TOPIC_COMMAND "FDRS/COMMAND"
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // Should only be changed if implementing multiple FDRS systems.

@ -3,6 +3,24 @@
#else
#define DBG(a)
#endif
#if defined (ESP32)
#define UART_IF Serial1
#else
#define UART_IF Serial
#endif
#ifdef GLOBALS
#define FDRS_WIFI_SSID GLOBAL_SSID
#define FDRS_WIFI_PASS GLOBAL_PASS
#define FDRS_MQTT_ADDR GLOBAL_MQTT_ADDR
#define FDRS_BAND GLOBAL_BAND
#define FDRS_SF GLOBAL_SF
#else
#define FDRS_WIFI_SSID WIFI_SSID
#define FDRS_WIFI_PASS WIFI_PASS
#define FDRS_MQTT_ADDR MQTT_ADDR
#define FDRS_BAND BAND
#define FDRS_SF SF
#endif
typedef struct __attribute__((packed)) DataReading {
float d;
@ -14,15 +32,31 @@ typedef struct __attribute__((packed)) DataReading {
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;
#ifdef ESP32
esp_now_peer_info_t peerInfo;
#endif
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
uint8_t incMAC[6];
#ifdef ESPNOW1_PEER
uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW1_PEER};
#else
uint8_t ESPNOW1[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
#ifdef ESPNOW2_PEER
uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW2_PEER};
uint8_t incMAC[6];
#else
uint8_t ESPNOW2[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
#ifdef USE_LORA
uint8_t LoRa1[] = {mac_prefix[3], mac_prefix[4], LORA1_PEER};
uint8_t LoRa2[] = {mac_prefix[3], mac_prefix[4], LORA2_PEER};
//uint8_t LoRaAddress[] = {0x42, 0x00};
#endif
DataReading theData[256];
uint8_t ln;
@ -59,9 +93,9 @@ CRGB leds[NUM_LEDS];
#endif
#ifdef USE_WIFI
PubSubClient client(espClient);
const char* ssid = WIFI_NET;
const char* password = WIFI_PASS;
const char* mqtt_server = MQTT_ADDR;
const char* ssid = FDRS_WIFI_SSID;
const char* password = FDRS_WIFI_PASS;
const char* mqtt_server = FDRS_MQTT_ADDR;
#endif
@ -456,7 +490,6 @@ void reconnect() {
}
void begin_espnow() {
DBG("Initializing ESP-NOW!");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
// Init ESP-NOW for either ESP8266 or ESP32 and set MAC address
@ -469,8 +502,12 @@ void begin_espnow() {
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
// Register peers
#ifdef ESPNOW1_PEER
esp_now_add_peer(ESPNOW1, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
#endif
#ifdef ESPNOW2_PEER
esp_now_add_peer(ESPNOW2, ESP_NOW_ROLE_COMBO, 0, NULL, 0);
#endif
#elif defined(ESP32)
esp_wifi_set_mac(WIFI_IF_STA, &selfAddress[0]);
if (esp_now_init() != ESP_OK) {
@ -479,7 +516,7 @@ void begin_espnow() {
}
esp_now_register_send_cb(OnDataSent);
esp_now_register_recv_cb(OnDataRecv);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Register first peer
@ -489,18 +526,20 @@ void begin_espnow() {
DBG("Failed to add peer bcast");
return;
}
memcpy(peerInfo.peer_addr, ESPNOW1, 6);
#ifdef ESPNOW1_PEER
memcpy(peerInfo.peer_addr, ESPNOW1, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
DBG("Failed to add peer 1");
return;
}
#endif
#ifdef ESPNOW2_PEER
memcpy(peerInfo.peer_addr, ESPNOW2, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
DBG("Failed to add peer 2");
return;
}
#endif
#endif
DBG(" ESP-NOW Initialized.");
DBG(WIFI_NET);
}

@ -1,3 +1,3 @@
Please copy this directory into your Arduino "libraries" directory.
Edit the files in your libraries folder according to your needs with your WiFi info, LoRa band, etc.
!!Never edit them here!!!
Never edit them here!!!

@ -1,2 +0,0 @@
#define my_SSID ""
#define my_PASSWORD ""

@ -1,79 +0,0 @@
#ifdef DEBUG
#define DBG(a) (Serial.println(a))
#else
#define DBG(a)
#endif
#define my_BAND 433.2E6
#define my_SF 7
#define my_MQTT_BROKER "192.168.0.203"
#define ESPNOW1_DELAY 0
#define ESPNOW2_DELAY 0
#define ESPNOWG_DELAY 0
#define SERIAL_DELAY 0
#define MQTT_DELAY 0
#define LORAG_DELAY 1000
#define LORA1_DELAY 1000
#define LORA2_DELAY 1000
//#define USE_LORA
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
uint8_t LoRaAddress[] = {0x42, 0x00}; //Do not touch!!!
//#define USE_LED
#define LED_PIN 32
#define NUM_LEDS 4
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE // do not touch!
#ifdef CREDENTIALS
#include <fdrs_credentials.h>
#define WIFI_NET my_SSID // ssid of your accesspoint
#define WIFI_PASS my_PASSWORD // password of access point
#define MQTT_ADDR my_MQTT_BROKER
#define BAND my_BAND
#define SF my_SF
#else
#define WIFI_NET "Your SSID"
#define WIFI_PASS "Password"
#define MQTT_ADDR "192.168.0.8"
#define BAND 915E6
#define SF 7
#endif
#define STATUS_T 0 // Status
#define TEMP_T 1 // Temperature
#define TEMP2_T 2 // Temperature #2
#define HUMIDITY_T 3 // Relative Humidity
#define PRESSURE_T 4 // Atmospheric Pressure
#define LIGHT_T 5 // Light (lux)
#define SOIL_T 6 // Soil Moisture
#define SOIL2_T 7 // Soil Moisture #2
#define SOILR_T 8 // Soil Resistance
#define SOILR2_T 9 // Soil Resistance #2
#define OXYGEN_T 10 // Oxygen
#define CO2_T 11 // Carbon Dioxide
#define WINDSPD_T 12 // Wind Speed
#define WINDHDG_T 13 // Wind Direction
#define RAINFALL_T 14 // Rainfall
#define MOTION_T 15 // Motion
#define VOLTAGE_T 16 // Voltage
#define VOLTAGE2_T 17 // Voltage #2
#define CURRENT_T 18 // Current
#define CURRENT2_T 19 // Current #2
#define IT_T 20 // Iterations
#define TOPIC_DATA "FDRS/DATA"
#define TOPIC_STATUS "FDRS/STATUS"
#define TOPIC_COMMAND "FDRS/COMMAND"

@ -0,0 +1,8 @@
#define GLOBAL_SSID "Your SSID"
#define GLOBAL_PASS "Password"
#define GLOBAL_MQTT_ADDR "192.168.0.8"
#define GLOBAL_BAND 915E6 //LoRa Frequency Band
#define GLOBAL_SF 7 //LoRa Spreading Factor
#define GLOBALS
Loading…
Cancel
Save