← index #18055Issue #18224
Related · high · value 2.268
QUERY · ISSUE

ESPNow doesn't recover from buffer error

openby mrichar1opened 2025-09-10updated 2026-03-23
bugport-esp32

Port, board and/or hardware

ESP32_GENERIC_C3-20250809-v1.26.0; ESP32 C3 Supermini

MicroPython version

MicroPython v1.26.0 on 2025-08-09; ESP32C3 module with ESP32C3

Reproduction

From the sender, send a too-large message via ESP32 (>250 bytes), followed by more 'correct' messages:

e.send(peer, "a" * 10)
e.send(peer, "a" * 10)
e.send(peer, "a" * 10)
e.send(peer, "a" * 251)
e.send(peer, "a" * 10)
e.send(peer, "a" * 10)
e.send(peer, "a" * 10)

Receive the messages, catching errors:

while True:
    try:
        print(e.recv())
    except Exception as err:
        print(err)

Expected behaviour

The first too-large message should raise an exception. Subsequent 'correct' messages should then continue as normal.

Observed behaviour

The first messages appear as expected - once the long message is received, the exception is printed repeatedly and no further messages are seen:

[b' n\xf1h\x98\x90', b'bbbbbbbbbb']
[b' n\xf1h\x98\x90', b'bbbbbbbbbb']
[b' n\xf1h\x98\x90', b'bbbbbbbbbb']
ValueError: ESPNow.recv(): buffer error
ValueError: ESPNow.recv(): buffer error
ValueError: ESPNow.recv(): buffer error
ValueError: ESPNow.recv(): buffer error
ValueError: ESPNow.recv(): buffer error
<repeats forever>

Additional Information

A workaround for this issue is to deinit on ValueError, i.e.:

try:
    e.recv()
except ValueError:
    e.active(False)
    e.active(True)

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

espnow.irecv() fails silently in some low memory situation

openby QuirkyCortopened 2025-10-08updated 2025-10-08
bug

Port, board and/or hardware

ESP32

MicroPython version

MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32

Reproduction

Sender code

import network
import espnow
import time

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
esp_now = espnow.ESPNow()
esp_now.active(True)
esp_now.add_peer(b'\xff\xff\xff\xff\xff\xff')

while True:
    esp_now.send(b'\xff\xff\xff\xff\xff\xff', b'hello')
    time.sleep(1)

Receiver code

import network
import espnow
import json

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
esp_now = espnow.ESPNow()
esp_now.active(True)

# Allocate some memory
a = [0] * 8000  # Bug goes away if this is reduce to say 5000
b = json.dumps(a)
c = json.loads(b)

while True:
    print(esp_now.irecv(-1))

Expected behaviour

Expect the receiver to either print out the received message continuously, or throw an error (...if it is out of memory).

Observed behaviour

esp_now.irecv(-1) does not return. Nothing is printed out. No error messages. On some occasions, the first received message is printed, but nothing after that.

If a = [0] * 8000 is changed to a = [0] * 5000, the problem goes away.

Additional Information

I am unable to replicate the problem without using json.dumps/loads, so maybe a memory fragmentation issue?

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied