From 52b74afba6f12f2462645189a6cdb6fee35677a4 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Tue, 9 Jun 2026 03:23:30 +0300 Subject: [PATCH] Bring back espnow tx buffering keeping resends disabled Buffering is needed for sending large prints, otherwise the espnow internal buffer overflows. Make onSent always think there was success send, so there won't be any resends. Print lost espnow packets count on wifi console command. --- flix/util.h | 9 +++++---- flix/wifi.ino | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flix/util.h b/flix/util.h index 5440848..aa9e705 100644 --- a/flix/util.h +++ b/flix/util.h @@ -47,13 +47,14 @@ void splitString(String& str, String& token0, String& token1, String& token2) { if (token2.c_str() == NULL) token2 = ""; } -// Simplified ESP-NOW Serial without tx buffering and resends +// Simplified ESP-NOW Serial without resends class ESPNOWSerial : public ESP_NOW_Serial_Class { public: + int lost = 0; using ESP_NOW_Serial_Class::ESP_NOW_Serial_Class; - void onSent(bool success) override {} // disable resends - size_t write(const uint8_t *data, size_t len) override { - return ESP_NOW_Peer::send(data, len); // pure send without buffering + void onSent(bool success) override { + if (!success) lost++; + ESP_NOW_Serial_Class::onSent(true); // always report success to avoid resends } }; diff --git a/flix/wifi.ino b/flix/wifi.ino index 8d45ca2..eea9d8a 100644 --- a/flix/wifi.ino +++ b/flix/wifi.ino @@ -90,6 +90,7 @@ void printWiFiInfo() { print("Peer MAC: %s\n", MacAddress(espnow.addr()).toString().c_str()); print("Encrypted: %d\n", espnow.isEncrypted()); print("Channel: %d\n", espnow.getChannel()); + print("Lost packets: %d\n", espnow.lost); } else if (WiFi.getMode() == WIFI_MODE_AP) { print("Mode: Access Point (AP)\n"); print("MAC: %s\n", WiFi.softAPmacAddress().c_str());