Skip to content

Commit e52709f

Browse files
Fix for delays on ESP32 & ESP8266 (#271)
* - Fix for delays on ESP32 & ESP8266 - Getting WDT resets on ESP8266 with RF24Ethernet + lwIP while using WiFi and OTA sketch - this should address that issue * Update RF24Network.h * Update RF24Network.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update RF24Network.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update RF24Network.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix defines --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 57b12f0 commit e52709f

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

RF24Network.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ uint8_t ESBNetwork<radio_t>::update(void)
213213
header->to_node = header->from_node;
214214
header->from_node = node_address;
215215
#ifdef SLOW_ADDR_POLL_RESPONSE
216-
delay(parent_pipe + SLOW_ADDR_POLL_RESPONSE);
216+
RF24NETWORK_DELAY(parent_pipe + SLOW_ADDR_POLL_RESPONSE);
217217
#else
218-
delay(parent_pipe);
218+
RF24NETWORK_DELAY(parent_pipe);
219219
#endif
220220
write(header->to_node, USER_TX_TO_PHYSICAL_ADDRESS);
221221
}
@@ -786,9 +786,7 @@ bool ESBNetwork<radio_t>::main_write(RF24NetworkHeader& header, const void* mess
786786
ok = _write(header, ((char*)message) + offset, fragmentLen, writeDirect);
787787

788788
if (!ok) {
789-
const uint32_t retry_delay_start = millis();
790-
while (millis() - retry_delay_start < 2) {
791-
}
789+
RF24NETWORK_DELAY(2);
792790
++retriesPerFrag;
793791
}
794792
else {
@@ -902,7 +900,7 @@ bool ESBNetwork<radio_t>::write(uint16_t to_node, uint8_t sendType)
902900
IF_RF24NETWORK_DEBUG(printf_P(PSTR("MAC Sending to 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe));
903901
/**Write it*/
904902
if (sendType == TX_ROUTED && conversion.send_node == to_node && isAckType) {
905-
delay(2);
903+
RF24NETWORK_DELAY(2);
906904
}
907905
ok = write_to_pipe(conversion.send_node, conversion.send_pipe, conversion.multicast);
908906

@@ -1266,6 +1264,16 @@ void ESBNetwork<radio_t>::pipe_address(uint16_t node, uint8_t pipe, uint8_t* add
12661264
IF_RF24NETWORK_DEBUG(uint32_t* top = reinterpret_cast<uint32_t*>(address + 1); printf_P(PSTR("NET Pipe %i on node 0%o has address %x%x\n\r"), pipe, node, *top, *address));
12671265
}
12681266

1267+
/******************************************************************/
1268+
#if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32
1269+
template<class radio_t>
1270+
void ESBNetwork<radio_t>::RF24NetworkDelay(uint32_t delay)
1271+
{
1272+
uint32_t timer = millis();
1273+
while (millis() - timer < delay) {
1274+
}
1275+
}
1276+
#endif
12691277
/************************ Sleep Mode ******************************************/
12701278

12711279
#if defined ENABLE_SLEEP_MODE

RF24Network.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,14 @@ class ESBNetwork
845845
*/
846846
uint8_t networkFlags;
847847

848+
#if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32
849+
/**
850+
* Use a regular delay for most devices, but on ESP32 and ESP8266, use a millis() based timeout.
851+
* See RF24NETWORK_DELAY in RF24Network_config.h
852+
*/
853+
void RF24NetworkDelay(uint32_t delay);
854+
#endif
855+
848856
protected:
849857
#if defined(RF24NetworkMulticast)
850858
/**

RF24Network_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
#define ENABLE_DYNAMIC_PAYLOADS
8989
#endif // DISABLE_DYNAMIC_PAYLOADS
9090

91+
#if defined ARDUINO_ARCH_ESP8266 || ARDUINO_ARCH_ESP32
92+
#define RF24NETWORK_DELAY(x) RF24NetworkDelay(x)
93+
#else
94+
#define RF24NETWORK_DELAY(x) delay(x)
95+
#endif
96+
9197
/* Debug Options */
9298
//#define RF24NETWORK_DEBUG
9399
//#define RF24NETWORK_DEBUG_MINIMAL

0 commit comments

Comments
 (0)