From e901a2f16ab7eff4c42163330661e1b041ac7fc6 Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 18:24:34 -0600 Subject: [PATCH 1/6] Tweaks to pingFDRS --- src/fdrs_gateway.h | 1 - src/fdrs_gateway_lora.h | 4 ++-- src/fdrs_node.h | 24 +++++------------------- src/fdrs_node_espnow.h | 27 ++++++++++++++++++++++++++- src/fdrs_node_lora.h | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/fdrs_gateway.h b/src/fdrs_gateway.h index e5ec9b5..efc0390 100644 --- a/src/fdrs_gateway.h +++ b/src/fdrs_gateway.h @@ -41,7 +41,6 @@ DataReading theData[256]; uint8_t ln; uint8_t newData = event_clear; uint8_t newCmd = cmd_clear; -bool is_ping = false; DataReading fdrsData[256]; // buffer for loadFDRS() uint8_t data_count = 0; diff --git a/src/fdrs_gateway_lora.h b/src/fdrs_gateway_lora.h index 3caffd2..c6c07cc 100644 --- a/src/fdrs_gateway_lora.h +++ b/src/fdrs_gateway_lora.h @@ -381,7 +381,7 @@ crcResult getLoRa() { // We have received a ping request or reply?? if (receiveData[0].param == 1) { // This is a reply to our ping request - is_ping = true; + pingFlag = true; DBG("We have received a ping reply via LoRa from address " + String(sourceMAC, HEX)); } else if (receiveData[0].param == 0) @@ -410,7 +410,7 @@ crcResult getLoRa() { // We have received a ping request or reply?? if (receiveData[0].param == 1) { // This is a reply to our ping request - is_ping = true; + pingFlag = true; DBG("We have received a ping reply via LoRa from address " + String(sourceMAC, HEX)); } else if (receiveData[0].param == 0) diff --git a/src/fdrs_node.h b/src/fdrs_node.h index de9cd76..e46312b 100644 --- a/src/fdrs_node.h +++ b/src/fdrs_node.h @@ -58,7 +58,6 @@ DataReading fdrsData[espnow_size]; DataReading incData[espnow_size]; uint8_t data_count = 0; -bool is_ping = false; uint32_t last_refresh; void (*callback_ptr)(DataReading); @@ -341,27 +340,14 @@ bool addFDRS(int timeout, void (*new_cb_ptr)(DataReading)) return true; } -uint32_t pingFDRS(int timeout) +uint32_t pingFDRS(uint32 timeout) { - SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0}; #ifdef USE_ESPNOW - esp_now_send(gatewayAddress, (uint8_t *)&sys_packet, sizeof(SystemPacket)); - DBG(" ESP-NOW ping sent."); - uint32_t ping_start = millis(); - is_ping = false; - while ((millis() - ping_start) <= timeout) - { - yield(); // do I need to yield or does it automatically? - if (is_ping) - { - DBG("Ping Returned:" + String(millis() - ping_start) + " from " + String(incMAC[5])); - return millis() - ping_start; - } - } + uint32_t pingResponseMs = pingFDRSEspNow(gatewayAddress, timeout); + return pingResponseMs; #endif #ifdef USE_LORA - // transmitLoRa(gtwyAddress, sys_packet, data_count); // TODO: Make this congruent to esp_now_send() - DBG(" LoRa ping not sent because it isn't implemented."); + uint32_t pingResponseMs = pingFDRSLoRa(>wyAddress, timeout); + return pingResponseMs; #endif - return 0; } diff --git a/src/fdrs_node_espnow.h b/src/fdrs_node_espnow.h index a7bc395..4db4176 100644 --- a/src/fdrs_node_espnow.h +++ b/src/fdrs_node_espnow.h @@ -10,6 +10,7 @@ uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; crcResult esp_now_ack_flag; bool is_added = false; +bool pingFlag = false; #ifdef USE_ESPNOW // Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32 @@ -49,7 +50,7 @@ void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) switch (command.cmd) { case cmd_ping: - is_ping = true; + pingFlag = true; break; case cmd_add: is_added = true; @@ -64,4 +65,28 @@ void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) newData = true; } } + +// FDRS node pings gateway and listens for a defined amount of time for a reply +// Blocking function for timeout amount of time (up to timeout time waiting for reply)(IE no callback) +// Returns the amount of time in ms that the ping takes or predefined value if ping fails within timeout +uint32_t pingFDRSEspNow(uint16_t *address, uint32_t timeout) { + SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0}; + + esp_now_send(gatewayAddress, (uint8_t *)&sys_packet, sizeof(SystemPacket)); + DBG(" ESP-NOW ping sent."); + uint32_t ping_start = millis(); + pingFlag = false; + while ((millis() - ping_start) <= timeout) + { + yield(); // do I need to yield or does it automatically? + if (pingFlag) + { + DBG("Ping Returned:" + String(millis() - ping_start) + " from " + String(incMAC[5])); + return (millis() - ping_start); + } + } + DBG("No ESP-NOW ping returned within " + String(timeout) + "ms."); + return UINT32_MAX; +} + #endif // USE_ESPNOW diff --git a/src/fdrs_node_lora.h b/src/fdrs_node_lora.h index 8f8bc74..bb3891f 100644 --- a/src/fdrs_node_lora.h +++ b/src/fdrs_node_lora.h @@ -80,6 +80,8 @@ RADIOLIB_MODULE radio = new Module(LORA_SS, LORA_DIO, LORA_RST, -1, LORA_SPI); #else RADIOLIB_MODULE radio = new Module(LORA_SS, LORA_DIO, LORA_RST, -1); #endif // CUSTOM_SPI + +bool pingFlag = false; bool transmitFlag = false; // flag to indicate transmission or reception state volatile bool enableInterrupt = true; // disable interrupt when it's not needed volatile bool operationDone = false; // flag to indicate that a packet was sent or received @@ -381,7 +383,7 @@ crcResult getLoRa() { // We have received a ping request or reply?? if (receiveData[0].param == 1) { // This is a reply to our ping request - is_ping = true; + pingFlag = true; DBG("We have received a ping reply via LoRa from address " + String(sourceMAC, HEX)); } else if (receiveData[0].param == 0) @@ -410,7 +412,7 @@ crcResult getLoRa() { // We have received a ping request or reply?? if (receiveData[0].param == 1) { // This is a reply to our ping request - is_ping = true; + pingFlag = true; DBG("We have received a ping reply via LoRa from address " + String(sourceMAC, HEX)); } else if (receiveData[0].param == 0) @@ -456,6 +458,34 @@ crcResult getLoRa() #endif // USE_LORA return CRC_NULL; } + +// FDRS Sensor pings gateway and listens for a defined amount of time for a reply +// Blocking function for timeout amount of time (up to timeout time waiting for reply)(IE no callback) +// Returns the amount of time in ms that the ping takes or predefined value if ping fails within timeout +uint32_t pingFDRSLoRa(uint16_t *address, uint32_t timeout) +{ + SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0}; + + transmitLoRa(address, &sys_packet, 1); + DBG("LoRa ping sent to address: 0x" + String(*address, HEX)); + uint32_t ping_start = millis(); + pingFlag = false; + while ((millis() - ping_start) <= timeout) + { + handleLoRa(); + yield(); //do I need to yield or does it automatically? + if (pingFlag) + { + DBG("LoRa Ping Returned: " + String(millis() - ping_start) + "ms."); + pingFlag = false; + return (millis() - ping_start); + } + } + DBG("No LoRa ping returned within " + String(timeout) + "ms."); + return UINT32_MAX; +} + + void printLoraPacket(uint8_t *p, int size) { printf("Printing packet of size %d.", size); From cc218456fefedd88df7f7c407165f4affa75fef9 Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 18:34:04 -0600 Subject: [PATCH 2/6] minor debug message change to sleepFDRS() --- src/fdrs_node.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fdrs_node.h b/src/fdrs_node.h index e46312b..4f890d3 100644 --- a/src/fdrs_node.h +++ b/src/fdrs_node.h @@ -190,7 +190,6 @@ bool sendFDRS() #endif #ifdef USE_LORA transmitLoRa(>wyAddress, fdrsData, data_count); - DBG(" LoRa sent."); data_count = 0; returnCRC = CRC_NULL; #endif @@ -223,7 +222,6 @@ void loadFDRS(float d, uint8_t t, uint16_t id) } void sleepFDRS(int sleep_time) { - DBG("Sleepytime!"); #ifdef DEEP_SLEEP DBG(" Deep sleeping."); #ifdef ESP32 From c6fa4f35a6bbcf03dc2af765ffd406c222515e65 Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 18:45:31 -0600 Subject: [PATCH 3/6] transmitLoRa for node returns crcResult and cascade changes to sendFDRS() --- src/fdrs_node.h | 21 +++++++++++++++++-- src/fdrs_node_lora.h | 49 +++++++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/fdrs_node.h b/src/fdrs_node.h index 4f890d3..08be8ee 100644 --- a/src/fdrs_node.h +++ b/src/fdrs_node.h @@ -169,6 +169,9 @@ void handleIncoming() bool sendFDRS() { + if(data_count == 0) { + return false; + } DBG("Sending FDRS Packet!"); #ifdef USE_ESPNOW esp_now_send(gatewayAddress, (uint8_t *)&fdrsData, data_count * sizeof(DataReading)); @@ -189,12 +192,26 @@ bool sendFDRS() } #endif #ifdef USE_LORA - transmitLoRa(>wyAddress, fdrsData, data_count); + crcReturned = transmitLoRa(>wyAddress, fdrsData, data_count); + // DBG(" LoRa sent."); +#ifdef LORA_ACK + if(crcReturned == CRC_OK) { data_count = 0; - returnCRC = CRC_NULL; + return true; + } #endif +#ifndef LORA_ACK + if(crcReturned == CRC_OK || crcReturned == CRC_NULL) { + data_count = 0; return true; } +#endif + else { + data_count = 0; + return false; + } +#endif +} void loadFDRS(float d, uint8_t t) { diff --git a/src/fdrs_node_lora.h b/src/fdrs_node_lora.h index bb3891f..de5e6d4 100644 --- a/src/fdrs_node_lora.h +++ b/src/fdrs_node_lora.h @@ -96,6 +96,8 @@ unsigned long msgOkLoRa = 0; // Number of total LoRa packets with vali void printLoraPacket(uint8_t *p, int size); uint16_t gtwyAddress = ((gatewayAddress[4] << 8) | GTWY_MAC); + +// Function prototypes crcResult getLoRa(); #if defined(ESP8266) || defined(ESP32) @@ -111,11 +113,13 @@ void setFlag(void) } #endif // USE_LORA -void handleLoRa() +crcResult handleLoRa() { #ifdef USE_LORA + crcResult crcReturned = CRC_NULL; if (operationDone) { // the interrupt was triggered + // DBG("Interrupt Triggered."); enableInterrupt = false; operationDone = false; if (transmitFlag) @@ -126,7 +130,7 @@ void handleLoRa() } else { // the previous operation was reception - returnCRC = getLoRa(); + crcReturned = getLoRa(); if (!transmitFlag) // return to listen if no transmission was begun { radio.startReceive(); @@ -134,6 +138,7 @@ void handleLoRa() enableInterrupt = true; } } + return crcReturned; #endif // USE_LORA } @@ -167,6 +172,7 @@ void begin_lora() #endif radio.setCRC(false); LoRaAddress = ((radio.randomByte() << 8) | radio.randomByte()); + DBG("LoRa node address is " + String(LoRaAddress, HEX) + " (hex)."); state = radio.startReceive(); // start listening for LoRa packets if (state == RADIOLIB_ERR_NONE) { @@ -180,9 +186,13 @@ void begin_lora() #endif // USE_LORA } -void transmitLoRa(uint16_t *destMAC, DataReading *packet, uint8_t len) +// Transmits Lora data by calling RadioLib library function +// Returns the CRC result if ACKs are enabled otherwise returns CRC_NULL + +crcResult transmitLoRa(uint16_t *destMAC, DataReading *packet, uint8_t len) { #ifdef USE_LORA + crcResult crcReturned = CRC_NULL; uint8_t pkt[6 + (len * sizeof(DataReading))]; uint16_t calcCRC = 0x0000; @@ -225,17 +235,17 @@ void transmitLoRa(uint16_t *destMAC, DataReading *packet, uint8_t len) unsigned long loraAckTimeout = millis() + FDRS_ACK_TIMEOUT; retries--; delay(10); - while (returnCRC == CRC_NULL && (millis() < loraAckTimeout)) + while (crcReturned == CRC_NULL && (millis() < loraAckTimeout)) { - handleLoRa(); + crcReturned = handleLoRa(); } - if (returnCRC == CRC_OK) + if (crcReturned == CRC_OK) { // DBG("LoRa ACK Received! CRC OK"); msgOkLoRa++; - return; // we're done + return CRC_OK; // we're done } - else if (returnCRC == CRC_BAD) + else if (crcReturned == CRC_BAD) { // DBG("LoRa ACK Received! CRC BAD"); // Resend original packet again if retries are available @@ -262,29 +272,38 @@ void transmitLoRa(uint16_t *destMAC, DataReading *packet, uint8_t len) } transmitLoRaMsgwAck++; #endif // LORA_ACK + return crcReturned; #endif // USE_LORA } // For now SystemPackets will not use ACK but will calculate CRC -void transmitLoRa(uint16_t *destMAC, SystemPacket *packet, uint8_t len) +// Returns CRC_NULL ask SystemPackets do not use ACKS at current time +crcResult transmitLoRa(uint16_t *destMAC, SystemPacket *packet, uint8_t len) { #ifdef USE_LORA + crcResult crcReturned = CRC_NULL; uint8_t pkt[6 + (len * sizeof(SystemPacket))]; uint16_t calcCRC = 0x0000; + // Building packet -- address portion - first 4 bytes pkt[0] = (*destMAC >> 8); pkt[1] = (*destMAC & 0x00FF); pkt[2] = (LoRaAddress >> 8); pkt[3] = (LoRaAddress & 0x00FF); + // Building packet -- data portion - 5 bytes memcpy(&pkt[4], packet, len * sizeof(SystemPacket)); + // Calculate CRC of address and data portion of the packet + // Last 2 bytes are CRC so do not include them in the calculation itself for (int i = 0; i < (sizeof(pkt) - 2); i++) - { // Last 2 bytes are CRC so do not include them in the calculation itself + { // printf("CRC: %02X : %d\n",calcCRC, i); calcCRC = crc16_update(calcCRC, pkt[i]); } calcCRC = crc16_update(calcCRC, 0xA1); // Recalculate CRC for No ACK + // Building packet -- adding CRC - last 2 bytes pkt[len * sizeof(SystemPacket) + 4] = (calcCRC >> 8); pkt[len * sizeof(SystemPacket) + 5] = (calcCRC & 0x00FF); + // Packet is constructed now transmit the packet DBG("Transmitting LoRa message of size " + String(sizeof(pkt)) + " bytes with CRC 0x" + String(calcCRC, HEX) + " to destination 0x" + String(*destMAC, HEX)); // printLoraPacket(pkt,sizeof(pkt)); int state = radio.startTransmit(pkt, sizeof(pkt)); @@ -298,9 +317,11 @@ void transmitLoRa(uint16_t *destMAC, SystemPacket *packet, uint8_t len) while (true) ; } + return crcReturned; #endif // USE_LORA } +// ****DO NOT CALL getLoRa() directly! ***** Call handleLoRa() instead! // getLoRa for Sensors // USED to get ACKs (SystemPacket type) from LoRa gateway at this point. May be used in the future to get other data // Return type is crcResult struct - CRC_OK, CRC_BAD, CRC_NULL. CRC_NULL used for non-ack data @@ -322,7 +343,7 @@ crcResult getLoRa() destMAC = (packet[0] << 8) | packet[1]; sourceMAC = (packet[2] << 8) | packet[3]; packetCRC = ((packet[packetSize - 2] << 8) | packet[packetSize - 1]); - // DBG("Packet Address: 0x" + String(packet[0], HEX) + String(packet[1], HEX) + " Self Address: 0x" + String(selfAddress[4], HEX) + String(selfAddress[5], HEX)); + // DBG("Source Address: 0x" + String(packet[2], HEX) + String(packet[3], HEX) + " Destination Address: 0x" + String(packet[0], HEX) + String(packet[1], HEX)); if ((destMAC == LoRaAddress) || (destMAC == 0xFFFF)) { // Check if addressed to this device or broadcast // printLoraPacket(packet,sizeof(packet)); @@ -439,8 +460,8 @@ crcResult getLoRa() } else { - // DBG("Incoming LoRa packet of " + String(packetSize) + " bytes received from address 0x" + String(sourceMAC, HEX) + " destined for node address 0x" + String(destMAC, HEX)); - // printLoraPacket(packet,sizeof(packet)); + DBG("Incoming LoRa packet of " + String(packetSize) + " bytes received from address 0x" + String(sourceMAC, HEX) + " destined for node address 0x" + String(destMAC, HEX)); + // printLoraPacket(packet,sizeof(packet)); return CRC_NULL; } } @@ -455,8 +476,8 @@ crcResult getLoRa() return CRC_NULL; } } -#endif // USE_LORA return CRC_NULL; +#endif // USE_LORA } // FDRS Sensor pings gateway and listens for a defined amount of time for a reply From 209eb396a7982705cae412117b89fa4d27432031 Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 19:02:13 -0600 Subject: [PATCH 4/6] transmitLoRa for gateway returns crcResult similar to same for nodes --- src/fdrs_gateway_lora.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/fdrs_gateway_lora.h b/src/fdrs_gateway_lora.h index c6c07cc..9b78043 100644 --- a/src/fdrs_gateway_lora.h +++ b/src/fdrs_gateway_lora.h @@ -120,8 +120,8 @@ bool tx_time_set = false; #endif // USE_LORA // Function prototypes -void transmitLoRa(uint16_t *, DataReading *, uint8_t); -void transmitLoRa(uint16_t *, SystemPacket *, uint8_t); +crcResult transmitLoRa(uint16_t *, DataReading *, uint8_t); +crcResult transmitLoRa(uint16_t *, SystemPacket *, uint8_t); static uint16_t crc16_update(uint16_t, uint8_t); // CRC16 from https://github.com/4-20ma/ModbusMaster/blob/3a05ff87677a9bdd8e027d6906dc05ca15ca8ade/src/util/crc16.h#L71 @@ -167,8 +167,9 @@ void setFlag(void) operationDone = true; } -void transmitLoRa(uint16_t *destMac, DataReading *packet, uint8_t len) +crcResult transmitLoRa(uint16_t *destMac, DataReading *packet, uint8_t len) { + crcResult crcReturned = CRC_NULL; uint16_t calcCRC = 0x0000; uint8_t pkt[6 + (len * sizeof(DataReading))]; @@ -201,9 +202,12 @@ void transmitLoRa(uint16_t *destMac, DataReading *packet, uint8_t len) while (true) ; } + return crcReturned; } -void transmitLoRa(uint16_t *destMac, SystemPacket *packet, uint8_t len) + +crcResult transmitLoRa(uint16_t *destMac, SystemPacket *packet, uint8_t len) { + crcResult crcReturned = CRC_NULL; uint16_t calcCRC = 0x0000; uint8_t pkt[6 + (len * sizeof(SystemPacket))]; @@ -234,6 +238,7 @@ void transmitLoRa(uint16_t *destMac, SystemPacket *packet, uint8_t len) while (true) ; } + return crcReturned; } #endif // USE_LORA @@ -591,8 +596,9 @@ void asyncReleaseLoRaFirst() asyncReleaseLoRa(true); } -void handleLoRa() +crcResult handleLoRa() { + crcResult crcReturned = CRC_NULL; if (operationDone) // the interrupt was triggered { enableInterrupt = false; @@ -618,7 +624,7 @@ void handleLoRa() } else // the previous operation was reception { - returnCRC = getLoRa(); + crcReturned = getLoRa(); if (!transmitFlag) // return to listen if no transmission was begun { radio.startReceive(); @@ -626,5 +632,6 @@ void handleLoRa() enableInterrupt = true; } } + return crcReturned; } #endif // USE_LORA From 8410f398e225c87c7de6d06f822841e6789b0180 Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 20:16:36 -0600 Subject: [PATCH 5/6] Fix Arduino compile issues --- src/fdrs_gateway_lora.h | 1 + src/fdrs_node.h | 3 ++- src/fdrs_node_espnow.h | 8 +++++--- src/fdrs_node_lora.h | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fdrs_gateway_lora.h b/src/fdrs_gateway_lora.h index 9b78043..a73092c 100644 --- a/src/fdrs_gateway_lora.h +++ b/src/fdrs_gateway_lora.h @@ -84,6 +84,7 @@ RADIOLIB_MODULE radio = new Module(LORA_SS, LORA_DIO, LORA_RST, -1, LORA_SPI); RADIOLIB_MODULE radio = new Module(LORA_SS, LORA_DIO, LORA_RST, -1); #endif // CUSTOM_SPI +bool pingFlag = false; bool transmitFlag = false; // flag to indicate transmission or reception state volatile bool enableInterrupt = true; // disable interrupt when it's not needed volatile bool operationDone = false; // flag to indicate that a packet was sent or received diff --git a/src/fdrs_node.h b/src/fdrs_node.h index 08be8ee..064e022 100644 --- a/src/fdrs_node.h +++ b/src/fdrs_node.h @@ -51,6 +51,7 @@ uint8_t ln; bool newData; uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC}; const uint16_t espnow_size = 250 / sizeof(DataReading); +crcResult crcReturned = CRC_NULL; uint32_t gtwy_timeout = 0; uint8_t incMAC[6]; @@ -355,7 +356,7 @@ bool addFDRS(int timeout, void (*new_cb_ptr)(DataReading)) return true; } -uint32_t pingFDRS(uint32 timeout) +uint32_t pingFDRS(uint32_t timeout) { #ifdef USE_ESPNOW uint32_t pingResponseMs = pingFDRSEspNow(gatewayAddress, timeout); diff --git a/src/fdrs_node_espnow.h b/src/fdrs_node_espnow.h index 4db4176..ef5f71d 100644 --- a/src/fdrs_node_espnow.h +++ b/src/fdrs_node_espnow.h @@ -10,9 +10,11 @@ uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; crcResult esp_now_ack_flag; bool is_added = false; -bool pingFlag = false; + #ifdef USE_ESPNOW +bool pingFlag = false; + // Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32 #if defined(ESP8266) void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) @@ -69,10 +71,10 @@ void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) // FDRS node pings gateway and listens for a defined amount of time for a reply // Blocking function for timeout amount of time (up to timeout time waiting for reply)(IE no callback) // Returns the amount of time in ms that the ping takes or predefined value if ping fails within timeout -uint32_t pingFDRSEspNow(uint16_t *address, uint32_t timeout) { +uint32_t pingFDRSEspNow(uint8_t *address, uint32_t timeout) { SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0}; - esp_now_send(gatewayAddress, (uint8_t *)&sys_packet, sizeof(SystemPacket)); + esp_now_send(address, (uint8_t *)&sys_packet, sizeof(SystemPacket)); DBG(" ESP-NOW ping sent."); uint32_t ping_start = millis(); pingFlag = false; diff --git a/src/fdrs_node_lora.h b/src/fdrs_node_lora.h index de5e6d4..9ab4ef3 100644 --- a/src/fdrs_node_lora.h +++ b/src/fdrs_node_lora.h @@ -485,6 +485,7 @@ crcResult getLoRa() // Returns the amount of time in ms that the ping takes or predefined value if ping fails within timeout uint32_t pingFDRSLoRa(uint16_t *address, uint32_t timeout) { +#ifdef USE_LORA SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0}; transmitLoRa(address, &sys_packet, 1); @@ -504,6 +505,7 @@ uint32_t pingFDRSLoRa(uint16_t *address, uint32_t timeout) } DBG("No LoRa ping returned within " + String(timeout) + "ms."); return UINT32_MAX; +#endif // USE_LORA } From 94166a89318b6510c69390b5c401a44aae09994b Mon Sep 17 00:00:00 2001 From: Jeff Lehman Date: Sat, 25 Feb 2023 20:46:59 -0600 Subject: [PATCH 6/6] Modify ESP-NOW FDRS Ping debug message --- src/fdrs_node_espnow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fdrs_node_espnow.h b/src/fdrs_node_espnow.h index ef5f71d..3feac92 100644 --- a/src/fdrs_node_espnow.h +++ b/src/fdrs_node_espnow.h @@ -83,7 +83,7 @@ uint32_t pingFDRSEspNow(uint8_t *address, uint32_t timeout) { yield(); // do I need to yield or does it automatically? if (pingFlag) { - DBG("Ping Returned:" + String(millis() - ping_start) + " from " + String(incMAC[5])); + DBG("ESP-NOW Ping Reply in " + String(millis() - ping_start) + "ms from " + String(address[0], HEX) + ":" + String(address[1], HEX) + ":" + String(address[2], HEX) + ":" + String(address[3], HEX) + ":" + String(address[4], HEX) + ":" + String(address[5], HEX)); return (millis() - ping_start); } }