Skip to content

Commit ac97fa4

Browse files
committed
feat(espnow): Add remove on fail parameter
1 parent a9cf4b4 commit ac97fa4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp

+7-2
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() {
@@ -265,7 +266,11 @@ void ESP_NOW_Serial_Class::onSent(bool success) {
265266
vRingbufferReturnItem(tx_ring_buf, queued_buff);
266267
queued_buff = NULL;
267268
log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count);
268-
//send next packet?
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+
}
269274
//log_d(MACSTR ": NEXT", MAC2STR(addr()));
270275
checkForTxData();
271276
}

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 = true);
2627
~ESP_NOW_Serial_Class();
2728
size_t setRxBufferSize(size_t);
2829
size_t setTxBufferSize(size_t);

0 commit comments

Comments
 (0)