From c2a640a1a6994cdd97665ec81564582cbb578192 Mon Sep 17 00:00:00 2001 From: Timm Bogner <64260873+timmbogner@users.noreply.github.com> Date: Fri, 18 Feb 2022 19:47:40 -0600 Subject: [PATCH] Add files via upload --- FDRS_Gateway2000/DataReading.h | 2 +- FDRS_Gateway2000/FDRS_Gateway2000.ino | 5 ++++- FDRS_Gateway2000/defaults.h | 8 ++++---- FDRS_Gateway2000/fdrs_config.h | 6 +++--- FDRS_Gateway2000/fdrs_functions.h | 19 +++++++++++-------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/FDRS_Gateway2000/DataReading.h b/FDRS_Gateway2000/DataReading.h index 9796491..8cb4a33 100644 --- a/FDRS_Gateway2000/DataReading.h +++ b/FDRS_Gateway2000/DataReading.h @@ -1,5 +1,5 @@ -typedef struct DataReading { +typedef struct __attribute__((packed)) DataReading { float d; uint16_t id; uint8_t t; diff --git a/FDRS_Gateway2000/FDRS_Gateway2000.ino b/FDRS_Gateway2000/FDRS_Gateway2000.ino index 44cf17d..c602d7c 100644 --- a/FDRS_Gateway2000/FDRS_Gateway2000.ino +++ b/FDRS_Gateway2000/FDRS_Gateway2000.ino @@ -32,6 +32,7 @@ void setup() { Serial.begin(115200); #endif #endif + begin_espnow(); #ifdef USE_WIFI delay(10); @@ -48,7 +49,9 @@ void setup() { if (!LoRa.begin(BAND)) { while (1); } -#endif +#endif +Serial.println(sizeof(DataReading)); + } void loop() { diff --git a/FDRS_Gateway2000/defaults.h b/FDRS_Gateway2000/defaults.h index 09d6757..0a3d9ed 100644 --- a/FDRS_Gateway2000/defaults.h +++ b/FDRS_Gateway2000/defaults.h @@ -1,8 +1,8 @@ #define UNIT_MAC 0xFD // THIS UNIT -#define ESPNOW1_MAC 0xFE // ESPNOW1 Address -#define ESPNOW2_MAC 0xFF // ESPNOW2 Address -#define LORA1_MAC 0xFE // LoRa1 Address -#define LORA2_MAC 0xFF // LoRa2 Address +#define ESPNOW1_PEER 0xFE // ESPNOW1 Address +#define ESPNOW2_PEER 0xFF // ESPNOW2 Address +#define LORA1_PEER 0xFE // LoRa1 Address +#define LORA2_PEER 0xFF // LoRa2 Address #define ESPNOW1_DELAY 0 #define ESPNOW2_DELAY 0 diff --git a/FDRS_Gateway2000/fdrs_config.h b/FDRS_Gateway2000/fdrs_config.h index 33bd18a..3722525 100644 --- a/FDRS_Gateway2000/fdrs_config.h +++ b/FDRS_Gateway2000/fdrs_config.h @@ -4,15 +4,15 @@ #include "defaults.h" -#define UNIT_MAC 0x01 // THIS UNIT +#define UNIT_MAC 0x00 // THIS UNIT //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). #define ESPNOWG_ACT sendSerial(); #define SERIAL_ACT -#define MQTT_ACT sendSerial(); -#define LORAG_ACT sendSerial(); +#define MQTT_ACT +#define LORAG_ACT //ESP32 Only diff --git a/FDRS_Gateway2000/fdrs_functions.h b/FDRS_Gateway2000/fdrs_functions.h index 4b4e110..0a380ed 100644 --- a/FDRS_Gateway2000/fdrs_functions.h +++ b/FDRS_Gateway2000/fdrs_functions.h @@ -4,11 +4,11 @@ const uint8_t mac_prefix[] = {MAC_PREFIX}; uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC}; -uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW1_MAC}; -uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW2_MAC}; +uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW1_PEER}; +uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW2_PEER}; uint8_t incMAC[6]; -uint8_t LoRa1[] = {mac_prefix[4], LORA1_MAC}; -uint8_t LoRa2[] = {mac_prefix[4], LORA2_MAC}; +uint8_t LoRa1[] = {mac_prefix[3], mac_prefix[4], LORA1_PEER}; +uint8_t LoRa2[] = {mac_prefix[3], mac_prefix[4], LORA2_PEER}; DataReading theData[256]; uint8_t ln; @@ -117,8 +117,11 @@ void getLoRa() { uint8_t packet[packetSize]; uint8_t incLORAMAC[2]; LoRa.readBytes((uint8_t *)&packet, packetSize); - if (memcmp(&packet, &selfAddress[4], 2) == 0) { //Check if addressed to this device - memcpy(&incLORAMAC, &packet[2], 2); //Split off address portion of packet + // for (int i = 0; i < packetSize; i++) { + // Serial.println(packet[i], HEX); + // } + if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device + memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet memcpy(&theData, &packet[5], packetSize - 5); //Split off data portion of packet if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) newData = 7; //Check if it is from a registered sender else if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) newData = 8; @@ -301,8 +304,8 @@ void releaseESPNOW(uint8_t interface) { #ifdef USE_LORA void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) { uint8_t pkt[5 + (len * sizeof(DataReading))]; - memcpy(&pkt, mac, 2); - memcpy(&pkt[2], &selfAddress[4], 2); + memcpy(&pkt, mac, 3); + memcpy(&pkt[3], &selfAddress[4], 2); memcpy(&pkt[5], packet, len * sizeof(DataReading)); LoRa.beginPacket(); LoRa.write((uint8_t*)&pkt, sizeof(pkt));