ESP-Now support for ESP32 (and ESP8266)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 06, 2022 4:28 am

Intermittent response to broadcast messages.
BetterAutomations wrote:
Fri Apr 01, 2022 1:25 am
BetterAutomations wrote:
Thu Mar 31, 2022 7:54 pm
Anyone have a problem with intermittent firing of on_recv callbacks? Mine intermittently work, even with a bare minimum implementation. I'm working on dynamic pairing with an unencrypted peer.
Hmm. Not just callbacks. Central is intermittently not responding at all.
(My answer here includes some speculation (based on experience and reading various docs).)

I believe that receiving broadcasts is inherently more unreliable than sending messages to specific MAC addresses. When sending a message to a non-broadcast address, the underlying espressif code repeats the transmission up to 5 times till it is acknowledged as recieved.

I believe that this is not the case for messages sent to broadcast.

There are many reasons why an individual wifi (or espnow) packet may not be received by the receiving module.

In any case, I think of espnow messages like UDP messages (rather than TCP). If you want absolute reliability you need a protocol to ensure reliable transmission and ack of receipt.

For example, I use broadcasts only to register new devices to my cluster, but I repeat those broadcasts until they are acknowledged. Once I have registered a device, the cluster manager replies and the new client sends further messages to that address.

Also, note my comments in the documentation on "ESPNow and Wifi Operation" on how connecting to a wifi access point can reduce reliability of receipt of messages (just in case you are also connecitng to a wifi access point).

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 06, 2022 4:31 am

davef wrote:
Wed Apr 06, 2022 4:15 am
Welcome back! Did the RSSI functionality work its way into the code? I would test it myself if the units were more accessible.
Thanks,
Dave
That is an excellent question :D . I will try to take stock of where I was at and get back to you. I'll start by rebasing against the current release, run some tests and post updated images (hopefully with the RSSI patch merged in).

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Fri Apr 08, 2022 11:33 am

New ESPNow images for Micropython v1.18 release

I have uploaded two new sets of ESP32 and ESP8266 images to https://github.com/glenn20/micropython-espnow-images.

The first set of images are based on the espnow-g20 branch rebased against the v1.18 release of Micropython.

The second set of images are based on the espnow-g20-rssi-v1.18 branch (which is also rebased against the v1.18 release of Micropython). These images include experimental support for monitoring RSSI values of received messages. Testers are welcome. Documentation at https://micropython-glenn20.readthedocs ... ength-rssi

Please report any issues and let me know if you have any comments on the design of the RSSI interface.

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Re: ESP-Now support for ESP32 (and ESP8266)

Post by BetterAutomations » Fri Apr 08, 2022 7:20 pm

Looks like the "bricking" (killing Wi-Fi radio) I was experiencing wasn't related to your ESP-Now code. When I tried my original firmware on a brand-new out of the package ESP32, it also showed the wifi:esf_buf error messages.

I think for now please disregard for now my report of bricking.
glenn20 wrote:
Wed Apr 06, 2022 4:28 am
I believe that receiving broadcasts is inherently more unreliable than sending messages to specific MAC addresses. When sending a message to a non-broadcast address, the underlying espressif code repeats the transmission up to 5 times till it is acknowledged as recieved.
When I said "intermittent," what I was saying is it worked for a short while then stopped entirely. After it stopped, I could broadcast for an hour but it would not receive. I could reset the receiver and it would begin to work again. So it was not a matter of inherent broadcast unreliability.

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Re: ESP-Now support for ESP32 (and ESP8266)

Post by BetterAutomations » Mon Apr 11, 2022 12:18 pm

FYI, it appears that the cause of even the factory firmware .bins "bricking" is they must be compiled to ESP-IDF 4.2+. It was just a strange coincidence that I happened to trip across that particular bug just as I was testing ESP-Now for the first time, and the fact that even the factory bins were showing the same behavior really threw me for a loop. I'm excited to return to try the ESP-Now code again soon. I've submitted a bug report for the factory bins:
https://github.com/micropython/micropython/issues/8517

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 13, 2022 1:23 am

Thanks for the update. Such a difficult bug. Good luck with the rest of your espnow adventures ;)
BetterAutomations wrote:
Mon Apr 11, 2022 12:18 pm
FYI, it appears that the cause of even the factory firmware .bins "bricking" is they must be compiled to ESP-IDF 4.2+. It was just a strange coincidence that I happened to trip across that particular bug just as I was testing ESP-Now for the first time, and the fact that even the factory bins were showing the same behavior really threw me for a loop. I'm excited to return to try the ESP-Now code again soon. I've submitted a bug report for the factory bins:
https://github.com/micropython/micropython/issues/8517

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 13, 2022 1:42 am

New asyncio interface and Buffer Protocol/StreamIO support deprecated.

I have commited some important changes to the espnow-g20 branch. These include:
  • aioespnow: A new module to provide improved async io support
  • Deprecate Buffer Protocol support:
    • This means that the read(), read1(), readinto(), readinto1(), write() methods are no longer available.
    • Please let me know if you have been relying on this interface. With the new, cleaner asyncio interface, I judge that the Buffer Protocol support is not worth the code space (but feel free to convince me otherwise :D ).
  • Also deprecated the version() method as it seems to add little value.
This PR may soon be reviewed prior to merging so comments and advice are welcome I will build and push new images today.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP-Now support for ESP32 (and ESP8266)

Post by davef » Wed Apr 13, 2022 1:51 am

Deprecate Buffer Protocol support:
Fortunately I don't use these. Thought for a moment I was going to be pushed into using uasyncio :)

Probably have another link built in the next week and will test RSSI.

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 13, 2022 4:53 am

Hehe. I am not aware of anyone who was using the buffer protocol methods, but they may be out there.
davef wrote:
Wed Apr 13, 2022 1:51 am
Deprecate Buffer Protocol support:
Fortunately I don't use these. Thought for a moment I was going to be pushed into using uasyncio :)

Probably have another link built in the next week and will test RSSI.

User avatar
glenn20
Posts: 132
Joined: Mon Jun 04, 2018 10:09 am

Re: ESP-Now support for ESP32 (and ESP8266)

Post by glenn20 » Wed Apr 13, 2022 12:23 pm

I have pushed new v1.18 images with RSSI and the new asyncio support to:
glenn20 wrote:
Wed Apr 13, 2022 1:42 am
New asyncio interface and Buffer Protocol/StreamIO support deprecated.
...
I will build and push new images today.

Post Reply