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 » Fri Jul 08, 2022 3:00 am

glenn20 wrote:
Fri Jul 08, 2022 1:35 am
That is odd. The image should be tagged with the output of the "git describe" command. You could try running that command in your clone of the espnow-g20-v1.19.1 branch. It should identify the HEAD with respect to the most recent git tag.
I add my own annotated tag (v1.19.1-espnow) on the first commit of the espnow-g20-v1.19.1 branch. However, I had not pushed that tag to github. I have done that now. So, after updating your clone/fork, git describe should return v1.19.1-espnow-4-g537248958 (unless I have misunderstood how tags work when pushed upstream :D ).

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

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

Post by mekanixms » Fri Jul 08, 2022 5:36 am

glenn20 wrote:
Fri Jul 08, 2022 1:15 am
I have encountered similar issues in the past myself. Sometimes it is due to a bug I have introduced or some incompatibility with the IDF version I am using (most common).

A good starting point is to compile a vanilla micropython image without the espnow patches applied and check success with that.
Most likely I have done something wrong - I have compiled the vanilla hundreds of times before without any issues

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

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

Post by mekanixms » Fri Jul 08, 2022 5:38 am

glenn20 wrote:
Fri Jul 08, 2022 1:35 am

Also - check you have flashed the correct image into the device and you are talking to the right device (rookie mistakes - but I've made them before :-).

BTW. I have released compiled images based on v1.19.1. You could try them as well.
I cloned your repository and switched to your branch before compiling and getting the 1.13.... tag

Code: Select all

git switch espnow-g20-v1.19.1

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

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

Post by mekanixms » Fri Jul 08, 2022 5:39 am

glenn20 wrote:
Fri Jul 08, 2022 3:00 am
I add my own annotated tag (v1.19.1-espnow) on the first commit of the espnow-g20-v1.19.1 branch. However, I had not pushed that tag to github. I have done that now.
Checking now and will come back

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

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

Post by mekanixms » Fri Jul 08, 2022 5:47 am

glenn20 wrote:
Fri Jul 08, 2022 3:00 am
I had not pushed that tag to github. I have done that now. So, after updating your clone/fork, git describe should return v1.19.1-espnow-4-g537248958
Better- it shows 1.19 as it should

Code: Select all

[mekanix@eb850 g20-1.19.1-07-07-2020]$ git describe
v1.13-1968-g537248958
[mekanix@eb850 micropython]$ git describe
v1.19.1-espnow-4-g537248958
and the result

Code: Select all

/home/mekanix> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.19.1-espnow-4-g537248958-dirty on 2022-07-08; ESP32 module with ESP32
Type "help()" for more information.
>>> 
>>>
Last edited by mekanixms on Fri Jul 08, 2022 6:01 am, edited 1 time in total.

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

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

Post by mekanixms » Fri Jul 08, 2022 5:52 am

glenn20 wrote:
Fri Jul 08, 2022 12:57 am
I have uploaded new espnow-enabled micropython images to: https://github.com/glenn20/micropython-espnow-images.
By the way, works like a charm :D
Hope to see it soon accepted into the main branch

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 Jul 08, 2022 6:00 am

mekanixms wrote:
Fri Jul 08, 2022 5:47 am
glenn20 wrote:
Fri Jul 08, 2022 3:00 am
I had not pushed that tag to github. I have done that now. So, after updating your clone/fork, git describe should return v1.19.1-espnow-4-g537248958
Better- it shows 1.19 as it should

Code: Select all

[mekanix@eb850 g20-1.19.1-07-07-2020]$ git describe
v1.13-1968-g537248958
[mekanix@eb850 micropython]$ git describe
v1.19.1-espnow-4-g537248958
Thanks for the feedback. I presumed that without my v1.19.1-espnow tag, "git describe" would find the v1.19.1 tag on the master branch. Odd that it didn't.

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

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

Post by mekanixms » Fri Jul 08, 2022 9:36 am

With that out of the way, I noticed yesterday that, while using irq, the ESPNow object, passed to the callback, does not expose the recv method to read the data.

How should I read the received data from inside the irq's callback??

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 Jul 08, 2022 10:02 am

mekanixms wrote:
Fri Jul 08, 2022 9:36 am
With that out of the way, I noticed yesterday that, while using irq, the ESPNow object, passed to the callback, does not expose the recv method to read the data.

How should I read the received data from inside the irq's callback??
Doh - that's an unfortunate regression. I forgot that since I switched to .recvinto() in _espnow, I had to undo the prior changes to the callback api. I had meant to fix that in the espnow.py wrapper module.

In the meantime, you can:

Code: Select all

import espnow

e = espnow.ESPNow()
...
def recv_cb(x):
    peer, msg = e.irecv(0)
    print(peer, msg)  # Replace with your own msg processing code.
e.irq(recv_cb)
Thanks for the bug report. Clearly I need to include some tests against the callback api in the test suite. I'll post a fix soon.

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

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

Post by mekanixms » 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
Many thanks

Post Reply