mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
commit
bf54b7c7b1
@ -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();
|
||||
|
@ -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
|
||||
|
||||
|
@ -63,9 +63,15 @@ FDRSGateWayBase::FDRSGateWayBase(){
|
||||
FDRSGateWayBase::~FDRSGateWayBase(){
|
||||
}
|
||||
|
||||
void FDRSGateWayBase::release(void){
|
||||
|
||||
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<DataReading_t> *FDRSGateWayBase::get_data(){
|
||||
return &_data;
|
||||
}
|
||||
|
||||
ESP_FDRSGateWay::ESP_FDRSGateWay(void)
|
||||
{
|
||||
|
||||
@ -232,6 +242,24 @@ void ESP_FDRSGateWay::send(std::vector<DataReading_t> data){
|
||||
|
||||
}
|
||||
|
||||
void ESP_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> 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<DataReading_t> data) {
|
||||
|
||||
}
|
||||
|
||||
void MQTT_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> 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<DataReading_t> data){
|
||||
_serial->println();
|
||||
}
|
||||
|
||||
void Serial_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> 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<DataReading_t> data){
|
||||
|
||||
}
|
||||
|
||||
void LoRa_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> 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))];
|
||||
|
@ -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<DataReading_t> *get_data();
|
||||
|
||||
private:
|
||||
static uint32_t peer_id;
|
||||
static std::vector<DataReading_t> _data;
|
||||
virtual void send(std::vector<DataReading_t> data) = 0;
|
||||
virtual void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) = 0;
|
||||
};
|
||||
|
||||
class ESP_FDRSGateWay: public FDRSGateWayBase{
|
||||
@ -69,6 +74,7 @@ private:
|
||||
static void setup(void);
|
||||
|
||||
void send(std::vector<DataReading_t> data) override;
|
||||
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> 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<DataReading_t> data) override;
|
||||
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
|
||||
|
||||
};
|
||||
|
||||
@ -122,6 +129,7 @@ private:
|
||||
static void setup(void);
|
||||
void pull(void);
|
||||
void send(std::vector<DataReading_t> data) override;
|
||||
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
|
||||
|
||||
};
|
||||
|
||||
@ -152,8 +160,8 @@ private:
|
||||
|
||||
void transmit(DataReading_t *packet, uint8_t len);
|
||||
|
||||
|
||||
void send(std::vector<DataReading_t> data) override;
|
||||
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user