translation macros

This commit is contained in:
DevilBinder 2022-06-24 18:05:43 +02:00
parent b7c4c4a7e7
commit c6b59167dd
2 changed files with 79 additions and 51 deletions

View File

@ -7,31 +7,12 @@
#include "fdrs_config.h"
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <espnow.h>
#elif defined(ESP32)
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>
#endif
#include <ArduinoJson.h>
#ifdef USE_WIFI
#include <PubSubClient.h>
#endif
#ifdef USE_LORA
#include <LoRa.h>
#endif
#ifdef USE_LED
#include <FastLED.h>
#endif
#include "fdrs_gateway.h"
#include "fdrs_config.h"
#define USE_WIFI
#ifdef USE_LED
CRGB leds[NUM_LEDS];
#endif
@ -39,18 +20,20 @@ CRGB leds[NUM_LEDS];
uint8_t selfAddress[6] = {MAC_PREFIX, UNIT_MAC};
#if defined(ESP_GET) || defined(ESP_SEND)
#ifdef ESPNOW_PEER_1
uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW_PEER_1};
#else
uint8_t ESPNOW1[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
#ifdef ESPNOW_PEER_2
uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW_PEER_2};
#else
uint8_t ESPNOW2[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
#ifdef ESPNOW_PEER_2
uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW_PEER_2};
#endif
#endif
#if defined(LORA_GET) || defined(LORA_SEND)
#ifdef LORA_PEER_1
uint8_t LoRa1[6] = {MAC_PREFIX, LORA_PEER_1};
@ -60,10 +43,20 @@ uint8_t LoRa1[6] = {MAC_PREFIX, LORA_PEER_1};
uint8_t LoRa2[6] = {MAC_PREFIX, LORA_PEER_2};
#endif
#endif
#if defined(MQTT_GET) || defined(MQTT_SEND)
MQTT_FDRSGateWay MQTT(WIFI_SSID,WIFI_PASS,MQTT_ADDR,MQTT_PORT);
#endif
#if defined(ESP_GET) || defined(ESP_SEND)
ESP_FDRSGateWay ESPNow;
#endif
#if defined(SER_GET) || defined(SER_SEND)
#if defined(ESP32)
Serial_FDRSGateWay SerialGW(&Serial1,115200);
@ -71,8 +64,15 @@ Serial_FDRSGateWay SerialGW(&Serial1,115200);
Serial_FDRSGateWay SerialGW(&Serial,115200);
#endif
#endif
#if defined(LORA_GET) || defined(LORA_SEND)
LoRa_FDRSGateWay LoRaGW(MISO,MOSI,SCK,SS,RST,DIO0,BAND,SF);
#endif
void setup() {
#ifdef USE_LED
@ -81,8 +81,11 @@ void setup() {
FastLED.show();
#endif
#if defined(MQTT_GET) || defined(MQTT_SEND)
MQTT.init();
#endif
#if defined(ESP_GET) || defined(ESP_SEND)
ESPNow.init(selfAddress);
#ifdef ESPNOW_PEER_1
@ -93,41 +96,67 @@ void setup() {
ESPNow.add_peer(ESPNOW2);
#endif
#endif
#if defined(SER_GET) || defined(SER_SEND)
#if defined(ESP32)
SerialGW.init(SERIAL_8N1,RXD2,TXD2);
#else
SerialGW.init();
#endif
#ifdef USE_LORA
#endif
#if defined(LORA_GET) || defined(LORA_SEND)
LoRaGW.init(selfAddress);
#endif
#ifdef ESPNOW_PEER_1
ESPNow.add_peer(ESPNOW1);
#endif
#ifdef ESPNOW_PEER_2
ESPNow.add_peer(ESPNOW2);
#endif
}
void loop() {
#if defined(LORA_GET)
LoRaGW.get();
SerialGW.get();
#endif
#if defined(SER_GET)
SerialGW.get();
#endif
#if defined(ESP_SEND)
ESPNow.release();
#endif
#if defined(MQTT_SEND)
MQTT.release();
#endif
#if defined(SER_SEND)
SerialGW.release();
#endif
#if defined(LORA_SEND)
LoRaGW.release();
#endif
//It does not matter witch one you call.
//it will clear all the data that has been received.
#if defined(ESP_SEND)
ESPNow.flush();
#endif
#if defined(MQTT_SEND)
MQTT.flush();
#endif
#if defined(SER_SEND)
SerialGW.flush();
#endif
#if defined(LORA_SEND)
LoRaGW.flush();
#endif
}

View File

@ -9,12 +9,17 @@
#define UNIT_MAC 0x03 // 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).
//Where we get the data from
#define LORA_GET
#define MQTT_GET
#define ESP_GET
#define SER_GET
#define SERIAL_ACT
#define MQTT_ACT
#define LORAG_ACT
//Where we send the data to
#define LORA_SEND
#define MQTT_SEND
#define ESP_SEND
#define SER_SEND
//#define USE_LORA
//#define USE_WIFI //Used only for MQTT gateway
@ -27,12 +32,6 @@
#define ESPNOW_PEER_1 0x0C // ESPNOW1 Address
#define ESPNOW_PEER_2 0x0D // ESPNOW2 Address
// Peer Actions
#define ESPNOW1_ACT
#define ESPNOW2_ACT
#define LORA1_ACT
#define LORA2_ACT
//WiFi and MQTT Credentials -- Needed only for MQTT gateway
#define WIFI_SSID "Your SSID"
#define WIFI_PASS "Your Password"