-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESPNow recovery from "invalid buffer" #9816
Comments
@stanelie you can try deinit (or as a workaround reload or reset if that doesn't work): |
deinit works perfectly for my purpose. Thanks @anecdata ! |
Inspecting the C source, I do believe there's an implementation error. 68 // Callback triggered when an ESP-NOW packet is received.
69 // Write the peer MAC address and the message into the recv_buffer as an ESPNow packet.
70 // If the buffer is full, drop the message and increment the dropped count.
71 static void recv_cb(const esp_now_recv_info_t *esp_now_info, const uint8_t *msg, int msg_len) {
72 espnow_obj_t *self = MP_STATE_PORT(espnow_singleton);
73 ringbuf_t *buf = self->recv_buffer;
74
75 if (sizeof(espnow_packet_t) + msg_len > ringbuf_num_empty(buf)) {
76 self->read_failure++;
77 return;
78 }
79
80 espnow_header_t header;
81 header.magic = ESPNOW_MAGIC;
82 header.msg_len = msg_len;
83 header.rssi = esp_now_info->rx_ctrl->rssi;
84 header.time_ms = mp_hal_ticks_ms();
85
86 ringbuf_put_n(buf, (uint8_t *)&header, sizeof(header));
87 ringbuf_put_n(buf, esp_now_info->src_addr, ESP_NOW_ETH_ALEN);
88 ringbuf_put_n(buf, msg, msg_len);
89
90 self->read_success++;
91 } At line 75, the code intends to check thatall the Consequently, the subsequent calls to The fix may be as simple as adding ESP_NOW_ETH_ALEN to the calculation in line 75. Another potential problem source—and I don't know if this can occur in practice—is if Actually, now that I think about it |
However, I'm glad you were able to work around the problem with the use of |
I think the original, original ringbuf may have been atomically safe, but once we went to two-byte entries, I think that went out the window. That's why I made the implementation more straightforward; there were many latent bugs having to do with the requested size vs needed size of the buffer (one entry more). My current expectation is that ringbuf operations will be done in a critical section. |
This high level discussion is way above my level, but if you do implement a fix, I will be ready to check if it works. |
CircuitPython version
Code/REPL
Behavior
Hello.
This is more a support question then a bug report. I cannot find anywhere in the documentation how to purge the ESPNow buffer, or how to destroy the ESPNow object so that I can recreate it (to recover from errors).
I run this code where a ESP32 is receiving packets from 2 different senders, and I guess the packets interfere when they arrive at the same time? When that happens, I receive an Invalid buffer error and I cannot recover from this. I can catch the error so the code keeps going, but the buffer keeps saying it is invalid.
Description
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: