Skip to content

Commit c55f5aa

Browse files
change(esp_now_serial): No teardown on retry limit (#10293)
* change(ESP_NOW_Serial): No teardown on retry limit After max retries is met once the ESP_NOW_Serial_Class performs "end()". This removes the peer from ESP_NOW. Further messages to and from ESP_NOW_Serial are not received or sent. Peer should stay in ESP_NOW to re-establish connection even with data loss. This change will "retry and drop" the data piece by piece instead of aborting the connection. * feat(espnow): Add remove on fail parameter * feat(espnow): By default keep the peer when sending fails --------- Co-authored-by: Jan Prochazka <[email protected]>
1 parent e989445 commit c55f5aa

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
*
1212
*/
1313

14-
ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk)
14+
ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk, bool remove_on_fail)
1515
: ESP_NOW_Peer(mac_addr, channel, iface, lmk) {
1616
tx_ring_buf = NULL;
1717
rx_queue = NULL;
1818
tx_sem = NULL;
1919
queued_size = 0;
2020
queued_buff = NULL;
2121
resend_count = 0;
22+
_remove_on_fail = remove_on_fail;
2223
}
2324

2425
ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() {
@@ -264,9 +265,15 @@ void ESP_NOW_Serial_Class::onSent(bool success) {
264265
//the data is lost in this case
265266
vRingbufferReturnItem(tx_ring_buf, queued_buff);
266267
queued_buff = NULL;
267-
xSemaphoreGive(tx_sem);
268-
end();
269268
log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count);
269+
//if we are not able to send the data and remove_on_fail is set, remove the peer
270+
if (_remove_on_fail) {
271+
xSemaphoreGive(tx_sem);
272+
end();
273+
return;
274+
}
275+
//log_d(MACSTR ": NEXT", MAC2STR(addr()));
276+
checkForTxData();
270277
}
271278
}
272279
}

libraries/ESP_NOW/src/ESP32_NOW_Serial.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer {
1717
size_t queued_size;
1818
uint8_t *queued_buff;
1919
size_t resend_count;
20+
bool _remove_on_fail;
2021

2122
bool checkForTxData();
2223
size_t tryToSend();
2324

2425
public:
25-
ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL);
26+
ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL, bool remove_on_fail = false);
2627
~ESP_NOW_Serial_Class();
2728
size_t setRxBufferSize(size_t);
2829
size_t setTxBufferSize(size_t);

0 commit comments

Comments
 (0)