diff --git a/Examples/Universal_Gateway/Universal_Gateway.ino b/Examples/Universal_Gateway/Universal_Gateway.ino index ac433d3..32dc8dd 100644 --- a/Examples/Universal_Gateway/Universal_Gateway.ino +++ b/Examples/Universal_Gateway/Universal_Gateway.ino @@ -126,8 +126,16 @@ void loop() { #endif #if defined(ESP_SEND) +#ifdef ESPNOW_ALL ESPNow.release(); #endif +#ifdef ESPNOW_PEER_1 + ESPNow.release(ESPNOW1); +#endif +#ifdef ESPNOW_PEER_2 + ESPNow.release(ESPNOW2); +#endif +#endif #if defined(MQTT_SEND) MQTT.release(); diff --git a/Examples/Universal_Gateway/fdrs_config.h b/Examples/Universal_Gateway/fdrs_config.h index 13d0cf9..c72f5a9 100644 --- a/Examples/Universal_Gateway/fdrs_config.h +++ b/Examples/Universal_Gateway/fdrs_config.h @@ -29,6 +29,7 @@ #define LORA_PEER_1 0x0E // LoRa1 Address #define LORA_PEER_2 0x0F // LoRa2 Address +#define ESPNOW_ALL //send to all know and unknow peers #define ESPNOW_PEER_1 0x0C // ESPNOW1 Address #define ESPNOW_PEER_2 0x0D // ESPNOW2 Address diff --git a/fdrs_gateway.cpp b/fdrs_gateway.cpp index 4895098..adb2ebb 100644 --- a/fdrs_gateway.cpp +++ b/fdrs_gateway.cpp @@ -63,10 +63,16 @@ FDRSGateWayBase::FDRSGateWayBase(){ FDRSGateWayBase::~FDRSGateWayBase(){ } -void FDRSGateWayBase::release(void){ - send(_data); + +void FDRSGateWayBase::release(uint8_t *peer_mac){ + if(peer_mac == NULL){ + send(_data); + } + forward(peer_mac ,_data); + } + void FDRSGateWayBase::flush(void){ _data.clear(); } @@ -75,6 +81,10 @@ void FDRSGateWayBase::add_data(DataReading_t *data){ _data.push_back(*data); } +std::vector *FDRSGateWayBase::get_data(){ + return &_data; +} + ESP_FDRSGateWay::ESP_FDRSGateWay(void) { @@ -232,6 +242,24 @@ void ESP_FDRSGateWay::send(std::vector data){ } +void ESP_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector data){ + + const uint8_t espnow_size = 250 / sizeof(DataReading_t); + + uint32_t i = 0; + + + uint8_t d = data.size() / espnow_size; + + DataReading_t buffer1[d]; + for(i = 0; i < d; i++){ + buffer1[i] = data[i]; + } + + esp_now_send(peer_mac, (uint8_t *) buffer1, d * sizeof(DataReading_t)); + +} + MQTT_FDRSGateWay::MQTT_FDRSGateWay(const char *ssid, const char *password, const char *server,int port): _ssid(ssid), _password(password), @@ -334,6 +362,9 @@ void MQTT_FDRSGateWay::send(std::vector data) { } +void MQTT_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector data){ + //does nothing. just here implement the pure virtule from the base class. +} Serial_FDRSGateWay::Serial_FDRSGateWay(HardwareSerial *serial, uint32_t baud): _serial(serial), @@ -399,6 +430,10 @@ void Serial_FDRSGateWay::send(std::vector data){ _serial->println(); } +void Serial_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector data){ + //does nothing. just here implement the pure virtule from the base class. +} + LoRa_FDRSGateWay::LoRa_FDRSGateWay(uint8_t miso,uint8_t mosi,uint8_t sck, uint8_t ss,uint8_t rst,uint8_t dio0,double band,uint8_t sf): _miso(miso), _mosi(mosi), @@ -517,6 +552,10 @@ void LoRa_FDRSGateWay::send(std::vector data){ } +void LoRa_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector data){ + //TODO: add peer forwading. +} + void LoRa_FDRSGateWay::transmit(DataReading_t *packet, uint8_t len) { DBG("Transmitting LoRa."); uint8_t pkt[5 + (len * sizeof(DataReading_t))]; diff --git a/fdrs_gateway.h b/fdrs_gateway.h index 10704eb..e07536c 100644 --- a/fdrs_gateway.h +++ b/fdrs_gateway.h @@ -39,13 +39,18 @@ public: static void add_data(DataReading_t *data); - void release(void); + void release(uint8_t *peer_mac = NULL); + void flush(void); +protected: + std::vector *get_data(); + private: static uint32_t peer_id; static std::vector _data; virtual void send(std::vector data) = 0; + virtual void forward(uint8_t *peer_mac ,std::vector data) = 0; }; class ESP_FDRSGateWay: public FDRSGateWayBase{ @@ -69,6 +74,7 @@ private: static void setup(void); void send(std::vector data) override; + void forward(uint8_t *peer_mac ,std::vector data) override; void list_peer(uint8_t peer_mac[6]); void unlist_peer(uint8_t peer_mac[6]); @@ -101,6 +107,7 @@ private: void reconnect(); void send(std::vector data) override; + void forward(uint8_t *peer_mac ,std::vector data) override; }; @@ -122,6 +129,7 @@ private: static void setup(void); void pull(void); void send(std::vector data) override; + void forward(uint8_t *peer_mac ,std::vector data) override; }; @@ -152,8 +160,8 @@ private: void transmit(DataReading_t *packet, uint8_t len); - void send(std::vector data) override; + void forward(uint8_t *peer_mac ,std::vector data) override; };