ESP-Now support for ESP32 (and ESP8266)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
sonnybalut
Posts: 11
Joined: Tue Dec 22, 2020 7:19 pm

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

Post by sonnybalut » Thu Jan 13, 2022 11:47 pm

Hi,

Thank you @glenn20 for the espnow image. I have two youtubes demo link below and source in the description for espnow demo (one with known mac address, one with unknown mac address). Then a bunch of code snippets on my website.

youtube links:
https://www.youtube.com/watch?v=AyNRB0HplFU known mac addresses, code in the description

https://www.youtube.com/watch?v=PwydB6aoZAE unknown mac addresses, code in the description

website snippets link:
http://www.crus.in/codes.html website link code snippets

Hope it helps somebody.

automate1717
Posts: 10
Joined: Sat Jan 08, 2022 1:02 am

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

Post by automate1717 » Sat Jan 15, 2022 3:42 pm

glenn20 wrote:
Sat Nov 13, 2021 12:57 am
OK - yet another round of images uploaded. I am now building for all the newly available ESP32 S2/S3/C3 targets in micropython main branch (except GENERIC_D2WD which fails due to image size limitations).

These are all untested except for GENERIC, GENERIC_S2, UM_FEATHERS2 and UM_TINYS2 (those are the boards I have). Note that I can not vouch for the stability of any of the untested targets.

Let me know if there are any issues with these boards. NOTE - these are NOT based on a micropython release, so there may be non-espnow related instabilities. Non-espnow images for many of these targets are also available in the micropython daily builds.

Latest ESP32 images at: micropython-espnow-images.
Hello, for the esp32-s3, I am getting invalid header invalid header: 0xffffffff

I used the image
GENERIC_S3-20220115-unstable-v1.17-333-gcf258c898.bin

The web page on micropython where I downloaded the image, the instructions referenced a plain esp32 and I got an error and had to change it to esp32s3 and it did flash my board. possibly the header needs to be updated as well? thank you so much.

Niklas
Posts: 3
Joined: Fri Feb 18, 2022 11:27 am

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

Post by Niklas » Fri Feb 18, 2022 11:48 am

Hi Glenn,

Thanks for your work on the ESP-Now functionality.

We're a group of students (around 40 students) who are currently working on a Rover project where we need to communicate between 2 ESP32 (one has to work as the controller for the rover (sender), the second one for the Rover(reciever)).

We want to use the ESP-Now functionality to send Joystick-inputs from one ESP to the other, but we cant seem to add.peer with the mac adress we get from this command:

import network
import ubinascii
mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
print(mac)

However when we use the Mac adress we get from the command, we get the error message "ValueError: Wrong length".

What are we doing wrong?

I hope my post makes sense to you, we're 2. semester students, which gives us a total of 8 months programming in Micropython, so bear with me, for the lack of understanding everything in your ESP-Now support.

Kind Regards
Niklas and 39 other students in Denmark :)

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 » Fri Feb 18, 2022 7:17 pm

Is your MAC address of the following format:

Code: Select all

repeater_mac = b'\x08:\xf2\xab^\x04'

Niklas
Posts: 3
Joined: Fri Feb 18, 2022 11:27 am

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

Post by Niklas » Mon Feb 21, 2022 9:43 am

Hey Dave,

Thanks for the quick reply.

We've just succesfully passed the "ValueError" message, with your MAC-adress.

How you do translate "40:91:51:ab:56:b4 into your "type" of MAC adress. At the moment we've tried to just type in our MAC address into your format, but it doesnt work.

Kind regards.
Niklas

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 Feb 21, 2022 10:12 am

Another way to get the mac address is:

Code: Select all

mac = w0.config('mac')
print (mac)
I always see 4 forward slashes.

Niklas
Posts: 3
Joined: Fri Feb 18, 2022 11:27 am

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

Post by Niklas » Mon Feb 21, 2022 11:01 am

That did the trick!

Thanks alot Dave!

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

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

Post by MMliam » Sun Feb 27, 2022 5:41 pm

Hi Glenn,

Some how I missed your post; getting a bit confused between GitHub and microPython boards.
I'll try the your suggestion below.
I've never seen this construct before: w0, w1 = (network.WLAN(i) for i in (0, 1)). Is it documented some where that indicates the STA is the first one designated "0" and the AP is the second, designated "1"? Probably has to do with the fact that I don't actually understand what [network.STA_IF] is doing in the instruction [netObj = network.WLAN(network.STA_IF)]

Thanks again, sorry for the late Reply - Mike

glenn20 wrote:
Sun Jan 02, 2022 2:01 pm
MMliam wrote:
Tue Dec 21, 2021 1:51 pm
Hi Glenn,

I've been discussing an issue with davef; that being setting a fixed channel in station-mode for an ESP8266. Dave suggested that I try your build the includes ESPNow, as there was an example posted demonstrating that it was indeed possible:
...
The error indicating that the set-channel requires Access-Point-mode, not Station-mode.

dave tried this with an ESP32 and had success; is there some limitation with the build for the ESP8266?
Thanks for the bug report. This looks interesting. I confess that most of the work I have done on the intricacies of using wifi with espnow has been on the esp32 platforms. The message OSError: AP required indicates this is an error/requirement of the underlying Espressif SDK for the esp8266. They use a completely different sdk for the 8266 to the 32* chipsets. The earlier versions of the ESP32 SDK refused to let you set the station on the STA_IF and Espressif fixed that. However, they have declared that they are not providing updates to the 8266 SDK (though they declare an intention to release a future version of the ESP32 SDK which will also support the 8266).

So.... this is unlikely to be fixed any time soon.

However, the following workaround should work (I tested it today):

Code: Select all

w0, w1 = (network.WLAN(i) for i in (0, 1))
w0.active(False); w1.active(False)
w1.active(True) # Set channel will fail unless Active
w1.config(channel=6)  # Now the AP_IF will be operating on channel 6 - and so will the STA_IF
w0.active(True)
w1.active(False)

# Now the STA_IF is ON and set to channel 6 and the AP_IF is OFF
# You can now use the espnow code to send to a device listening on channel 6.

Serby
Posts: 1
Joined: Thu Mar 03, 2022 5:07 pm

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

Post by Serby » Thu Mar 03, 2022 5:19 pm

I have downloaded and have been running the espnow version of the firmware in main.py file and unchanged boot.py file. When I boot the espnow firmware from power off state the main.py file doesn’t load, is anyone else having this issue on the 1.17 version of espnow? I am using the spiram* version, not sure if I should change that the board is esp32 from TTGO called T-PCIe with 16 mb flash and 4mb spiram I think from the documentation of espressif esp32 wrover-E .
Once board is loaded from power off state no main.py code is ran, if I soft restart ir or push the button on the board then all the main.py code is loaded. I was told something about adding a try except into the code, I assume it is into the boot.py file, due to a loading error. Any information on what try except I need to run would be helpful, or if there is another workaround like an “on start , start main.py” or something of the sort, would be helpful. My main.py with espnow works, just doesn’t load from cold start, I am remote deploying this so I won’t have access to the board when finished.

Thank you.

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 » Thu Mar 03, 2022 6:45 pm

I have only run ESP-Now on the non-SPIRAM variant. When you say "soft restart" do you mean a CTRL-D from repl?

I wonder if you put a machine.reset() in boot.py. Something else to try I usually give my "main" an name and then in main.py after some init stuff import my_program. Maybe, try importing your re-named "main" program it in boot.py.

Post Reply