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 <90197375+P-R-O-C-H-Y@users.noreply.github.com>
This commit is contained in:
parent
e989445b62
commit
c55f5aa506
2 changed files with 12 additions and 4 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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) {
|
: ESP_NOW_Peer(mac_addr, channel, iface, lmk) {
|
||||||
tx_ring_buf = NULL;
|
tx_ring_buf = NULL;
|
||||||
rx_queue = NULL;
|
rx_queue = NULL;
|
||||||
|
|
@ -19,6 +19,7 @@ ESP_NOW_Serial_Class::ESP_NOW_Serial_Class(const uint8_t *mac_addr, uint8_t chan
|
||||||
queued_size = 0;
|
queued_size = 0;
|
||||||
queued_buff = NULL;
|
queued_buff = NULL;
|
||||||
resend_count = 0;
|
resend_count = 0;
|
||||||
|
_remove_on_fail = remove_on_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() {
|
ESP_NOW_Serial_Class::~ESP_NOW_Serial_Class() {
|
||||||
|
|
@ -264,9 +265,15 @@ void ESP_NOW_Serial_Class::onSent(bool success) {
|
||||||
//the data is lost in this case
|
//the data is lost in this case
|
||||||
vRingbufferReturnItem(tx_ring_buf, queued_buff);
|
vRingbufferReturnItem(tx_ring_buf, queued_buff);
|
||||||
queued_buff = NULL;
|
queued_buff = NULL;
|
||||||
xSemaphoreGive(tx_sem);
|
|
||||||
end();
|
|
||||||
log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count);
|
log_e(MACSTR " : RE-SEND_MAX[%u]", MAC2STR(addr()), resend_count);
|
||||||
|
//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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@ private:
|
||||||
size_t queued_size;
|
size_t queued_size;
|
||||||
uint8_t *queued_buff;
|
uint8_t *queued_buff;
|
||||||
size_t resend_count;
|
size_t resend_count;
|
||||||
|
bool _remove_on_fail;
|
||||||
|
|
||||||
bool checkForTxData();
|
bool checkForTxData();
|
||||||
size_t tryToSend();
|
size_t tryToSend();
|
||||||
|
|
||||||
public:
|
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 = false);
|
||||||
~ESP_NOW_Serial_Class();
|
~ESP_NOW_Serial_Class();
|
||||||
size_t setRxBufferSize(size_t);
|
size_t setRxBufferSize(size_t);
|
||||||
size_t setTxBufferSize(size_t);
|
size_t setTxBufferSize(size_t);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue