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 » Sat Jul 09, 2022 6:39 am

New ESPNow images uploaded: v1.19.1-espnow-6-g44f65965b

I've uploaded a new set of images with a fixup for the broken callback support in my latest images.
mekanixms wrote:
Fri Jul 08, 2022 10:06 am
Great, I wait for the fix. Need to use the ESPNow object passed to the callback as I do not have access to the global object, like you show in your code example
My espnow-g20-v1.19.1 branch is now updated with a fix for the callback api. Updated docs at: Callback Methods. I've also added tests for the callback apis so hopefully I won't overlook breaking these apis again :oops: .

Explanation: After migrating the recv() and irecv() methods from the C module (_espnow) to the python module (espnow.py) it was no longer possible to readily support the specific .irq() api requested by Damien in the C module. I have moved the .irq() method to the espnow.py module and renamed the low-level callback setting method in the C module to on_recv(). espnow.py:ESPNow.irq() creates a callback wrapper to match the requested api and invokes the low-level on_recv() method to set the callback (see espnow.py for the details).

In case it's not obvious, the incoming message is read out of the buffers before invoking the .irq() callbacks and the message is passed as an argument. For on_recv() callbacks, the incoming message is NOT automatically read out of the buffers before invoking the callback. This is useful if you just want to use the callback to signal your app that data is available or if you want more control over how the msg is read.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

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

Post by mekanixms » Sun Jul 10, 2022 7:55 pm

Good stuff, I will test tomorrow!! :D

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

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

Post by mekanixms » Mon Jul 11, 2022 7:12 am

glenn20 wrote:
Sat Jul 09, 2022 6:39 am
New ESPNow images uploaded: v1.19.1-espnow-6-g44f65965b
I've uploaded a new set of images with a fixup for the broken callback support in my latest images.
Works great, just tested!

Will come back if I notice anything to report

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 Jul 11, 2022 11:10 pm

ESP-Now and WiFi

I noticed that in your latest 1.19 docs that calls to e.init() and e.deinit() appear to have gone away. Are they included in the e.active(True) and e.active(False) calls now?

Thanks,
Dave
Last edited by davef on Wed Jul 13, 2022 9:23 am, edited 1 time in total.

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 » Tue Jul 12, 2022 3:06 am

ESP-Now and Wifi

Latest 19.1 firmware-esp32-GENERIC.bin and example 2

Code: Select all

e.add_peer(peer, None, None, network.AP_IF) #  register peer on AP_IF
TypeError: can't convert NoneType to int
Had to do:

Code: Select all

e.add_peer(peer, ifidx=network.AP_IF) #  register peer on AP_IF
Also, it chokes on:

Code: Select all

#w1.config(hidden=True)              # AP_IF operates on same channel as STA_
with the error:

Code: Select all

OSError: Wifi Invalid Mode
Any hints on how to call my send_alarm() and send_csv() methods so that they go to the hotspot?

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 Jul 13, 2022 9:57 am

davef wrote:
Mon Jul 11, 2022 11:10 pm
ESP-Now and WiFi

I noticed that in your latest 1.19 docs that calls to e.init() and e.deinit() appear to have gone away. Are they included in the e.active(True) and e.active(False) calls now?

Thanks,
Dave
Hi Dave,

Yes - this was part of the api changes requested in the initial review of the PR on github by @dpgeorge. Note that there is currently an init() and deinit() method in the espnow.py wrapper module to support backward compatbility for existing users.

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 Jul 13, 2022 10:27 am

Thank you.

Ignore the question at the end of my last post. I previously made a ESP-Now/WiFi setup where I completely shut-down ESP-Now and fired-up a WiFi connect. This crude approach left me thinking that somehow I had to direct my data to w0. I will just trying sending that data as I do on a normal WiFi connection.

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 Jul 14, 2022 4:51 am

Hi Glenn,

Using Example 1 as a basis I found that when you send something via uMail is just works.

Thanks for all the effort you put in, improving and maintaining this useful feature.

Dave

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 » Sat Jul 16, 2022 2:39 am

I have a working link on ESPNow/WiFi but would like to verify the behaviour I see. The local unit is as per Example 1.

I noticed that the remote unit needs to be connected to the WiFi network even though the traffic only goes over the e0 interface.

Is the remote really connected to the my hotspot/router to enable traffic over the e0 interface? Seems to suggest that I can't run a bunch of ESP32s ESPNow-only sensors and interface them to a ESPNow/WiFi gateway.

I must be missing something important.

Thanks,
Dave

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 Jul 16, 2022 5:08 am

Hi Dave,

I must have lost track of some of your messages. Which is Example 1? Can you point me to some code?

I can confirm however that you should NOT need to be connected to an access point to send espnow messges from that interface. You just have to set the network STA interface to network.WLAN(network.STA_IF).active(True) and also set the espnow object to e.active(True) (or e.init() as per the original api).

I can confirm that I am running a bunch of espnow-only sensor devices and interface them through an espnow-wifi bridge to an mqtt service.
davef wrote:
Sat Jul 16, 2022 2:39 am
I have a working link on ESPNow/WiFi but would like to verify the behaviour I see. The local unit is as per Example 1.

I noticed that the remote unit needs to be connected to the WiFi network even though the traffic only goes over the e0 interface.

Is the remote really connected to the my hotspot/router to enable traffic over the e0 interface? Seems to suggest that I can't run a bunch of ESP32s ESPNow-only sensors and interface them to a ESPNow/WiFi gateway.

I must be missing something important.

Thanks,
Dave

Post Reply