Skip to content

Commit

Permalink
feat(espnow): Add remove on fail parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
P-R-O-C-H-Y committed Sep 17, 2024
1 parent a9cf4b4 commit d0ae1cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
*
*/

ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk)
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)
: ESP_NOW_Peer(mac_addr, channel, iface, lmk) {
tx_ring_buf = NULL;
rx_queue = NULL;
tx_sem = NULL;
queued_size = 0;
queued_buff = NULL;
resend_count = 0;
_remove_on_fail = remove_on_fail;
}

ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() {
Expand Down Expand Up @@ -265,7 +266,12 @@ void ESP_NOW_Serial_Class::onSent(bool success) {
vRingbufferReturnItem(tx_ring_buf, queued_buff);
queued_buff = NULL;
log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count);
//send next packet?
//if we are not able to send the data and remove_on_fail is set, remove the peer
if (_remove_on_fail) {
xSemaphoreGive(tx_sem);
end();
return;
}
//log_d(MACSTR ": NEXT", MAC2STR(addr()));
checkForTxData();
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/ESP_NOW/src/ESP32_NOW_Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class ESP_NOW_Serial_Class : public Stream, public ESP_NOW_Peer {
size_t queued_size;
uint8_t *queued_buff;
size_t resend_count;
bool _remove_on_fail;

bool checkForTxData();
size_t tryToSend();

public:
ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface = WIFI_IF_AP, const uint8_t *lmk = NULL);
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);
~ESP_NOW_Serial_Class();
size_t setRxBufferSize(size_t);
size_t setTxBufferSize(size_t);
Expand Down

0 comments on commit d0ae1cd

Please sign in to comment.