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 13, 2022 12:38 pm

A note on reliable delivery of incoming espnow messages on ESP8266

I just wanted to clarify a potential cause of unreliable receiving of espnow messages on ESP8266 devices. As documented at https://micropython-glenn20.readthedocs ... -operation, the radio is automaticaly put to sleep periodically when the STA_IF interface is connected to an external Access Point (power saving mode). This is a function of the Espressif wifi libraries.

ESP8266 devices automatically remember and reconnect to their last Access Point once the STA_IF interface is set active after reboot, meaning your device may connect to an Access Point and enter the power-saving mode without you realising it. Inserting network.WLAN(network.STA_IF).disconnect() after you activate the STA_IF interface will help prevent this.

Eg. I had to add this to the tests in tests/multi-espnow/*.py to make my tests work reliably on my ESP8266 test modules.

(I will put a note in the docs, but wanted to highlight it here, as it may explain some issues users have been reporting.)

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 20, 2022 6:46 am

With the RSSI capability in the v1.18 versions of the ESP32 I have posted at:
https://github.com/davefes/ESPNow-Range-Testing
a sender and receiver application using a display OLED to give 5 second updates of RSSI.

User avatar
Lucje
Posts: 17
Joined: Sat May 14, 2022 4:08 pm
Location: Belgium

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

Post by Lucje » Sat May 14, 2022 4:24 pm

Good evening,

MycroPython is new for me, I only have some experience with C (Arduino IDE).
For school a school project I need to let 2 ESP32 communicate with each other and I have to do it with MicroPython.
So I did find EspNow, but I,' stuck at the very beginning.

I get the 'ImportError: cannot import name espnow' frase over and over again.
I read al the stuff about the error, modules en function...
But I can't find how this all supose to work...
Can someone tell me how to solve this?

Oh, before I forget: I'm using 2 vroom esp32's, I'm using uPyCraft V1.1 and the script I'm trying is one with the sender and receiver.

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

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

Post by glenn20 » Sat May 14, 2022 5:41 pm

Lucje wrote:
Sat May 14, 2022 4:24 pm
Good evening,

MycroPython is new for me, I only have some experience with C (Arduino IDE).
For school a school project I need to let 2 ESP32 communicate with each other and I have to do it with MicroPython.
So I did find EspNow, but I,' stuck at the very beginning.
Good Morning Lucje and welcome to micropython.

It is a hard to tell from your message exactly what you have tried, but I will make a guess. Do your get this error message when you type in the command

Code: Select all

from esp import espnow
If so, then I suspect you are running a micropython image on your esp32 which does not have espnow support. The micropython firmware images from micropython.org do not include espnow support.

You can get micropython images with espnow support at:

https://github.com/glenn20/micropython-espnow-images

Hopefully that will fix your problem.... Untill the next one ;).

Cheers and good luck.

User avatar
Lucje
Posts: 17
Joined: Sat May 14, 2022 4:08 pm
Location: Belgium

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

Post by Lucje » Sun May 15, 2022 11:04 am

Thanks for your message Yeti,
(I'm not able yet to aswer messages.)

I'm aware about the fact that the EspNow isn't standard yet.
My setup is for the school subject is 'prototyping and programming', and we are encouraged to think out of the box.
So, that's why I'm try this path.

Have a nice Sunday :D

User avatar
Lucje
Posts: 17
Joined: Sat May 14, 2022 4:08 pm
Location: Belgium

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

Post by Lucje » Mon May 16, 2022 4:37 am

glenn20 wrote:
Sat May 14, 2022 5:41 pm

Good Morning Lucje and welcome to micropython.

It is a hard to tell from your message exactly what you have tried, but I will make a guess. Do your get this error message when you type in the command

Code: Select all

from esp import espnow
If so, then I suspect you are running a micropython image on your esp32 which does not have espnow support. The micropython firmware images from micropython.org do not include espnow support.

You can get micropython images with espnow support at:

https://github.com/glenn20/micropython-espnow-images

Hopefully that will fix your problem.... Untill the next one ;).

Cheers and good luck.
Thanks Glenn,

Your answer did help.
I had to try all the firmwares because mine wasn't listed.
I'm using a EspVroom32 devkit1 and the one with Atom in the name seems to work with my board.

I still have a little question though, I do have oneway communication now, is twoway also possible?
Example: One board asks and the other answers.

Greetings Lucje

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 » Mon May 16, 2022 4:49 am

I only use ESP32 Wroom-32U and https://github.com/glenn20/micropython- ... ENERIC.binworks for me. Did you try that one?

Maybe, post a link to your specific hardware.

Study the docs at https://micropython-glenn20.readthedocs ... spnow.htmlspecifically the https://micropython-glenn20.readthedocs ... iving-datapart. For an example go here:
https://github.com/davefes/ESP-Now-repe ... water_tank and look at the repeater code.

Have fun!

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

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

Post by glenn20 » Mon May 16, 2022 5:05 am

Lucje wrote:
Mon May 16, 2022 4:37 am
Your answer did help.
I had to try all the firmwares because mine wasn't listed.
I'm using a EspVroom32 devkit1 and the one with Atom in the name seems to work with my board.
Ah - as suggested by Dave, the firmware-esp32-GENERIC.bin file should be the right one for your device. The M5STACK_ATOM image is compatible though - it just includes some extra pre-configured code for the M5Stack board. I recommend using the GENERIC image though so you can be sure.
I still have a little question though, I do have oneway communication now, is twoway also possible?
Example: One board asks and the other answers.
Yes - two way communication is possible. I use it all the time. Remember that on each device you have to use add_peer() to add the MAC address of the other device before you can send it a message (see https://micropython-glenn20.readthedocs ... w.add_peer).

User avatar
Lucje
Posts: 17
Joined: Sat May 14, 2022 4:08 pm
Location: Belgium

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

Post by Lucje » Wed May 18, 2022 5:34 pm

Good evening,
(Here in Belgium it's evening and hot at the moment :D )

Thx for your help Dave and Glenn most of the things are working find now.
I did try the Generic first but it didn't work at that moment. Now it does (I might have a faulty board in my pile).

The only problem I'm having at this moment is: when I boot the little board, and it loads the program with the espnow in it, it crashes.
Is this a normal thing at this moment?

Greetings Luc

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 May 18, 2022 7:24 pm

No.

Paste the minimum code that causes the problem. I suggest that you leave boot.py as is and in main.py just import my_program.py

Also a utime.sleep(5) at the beginning of my_program.py gives you a chance to break into the program before it starts running.

Post Reply