Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESPnow long range mode selection fails #9790

Open
stanelie opened this issue Nov 4, 2024 · 10 comments
Open

ESPnow long range mode selection fails #9790

stanelie opened this issue Nov 4, 2024 · 10 comments
Labels
Milestone

Comments

@stanelie
Copy link

stanelie commented Nov 4, 2024

CircuitPython version

Adafruit CircuitPython 9.1.4 on 2024-09-17; Waveshare ESP32-S3-Zero with ESP32S3

Code/REPL

e = espnow.ESPNow(250,31)

Behavior

When selecting integer 31 upon creation of the ESPNow object (which should be selecting line 626 here https://github.com/espressif/esp-idf/blob/a9d0f22193acdf47a5a4db36832ae7068818962b/components/esp_wifi/include/esp_wifi_types.h#L626), communication fails between 2 Waveshare ESP32-S3-zero devices. In fact, selecting any mode between 16 and 32 fails.

Description

No response

Additional information

No response

Edit : typo

@stanelie stanelie added the bug label Nov 4, 2024
@stanelie
Copy link
Author

stanelie commented Nov 4, 2024

In arduino, I think the correct method to set long range mode is this :
esp_wifi_set_protocol( ESP_IF_WIFI_STA, WIFI_PROTOCOL_LR));

Is this exposed method in Circuitpython?

@anecdata
Copy link
Member

anecdata commented Nov 4, 2024

I don't find esp_wifi_set_protocol in the current core implementation, and it's not exposed to Python code as a CircuitPython API, so default of b/g/n is used. For now, I would think 1Mbps would be best for range.

I think the rates 0x10-0x1F require 802.11ax, which is only supported so far in the WiFi-6 ESP32 variants: C5, C6.

(in the absence of any Python exceptions... if you custom build with DEBUG=1, there may be relevant messages in the debug serial console)

@stanelie
Copy link
Author

stanelie commented Nov 4, 2024

I would not know where to start to build it myself.
For now, it looks like this has not been implemented in CircuitPython. I've switched to Micropython and was able to make it work there.

Micropython code for reference, with initialization sequence as per the Micropython documentation :

import network
import espnow

sta = network.WLAN(network.STA_IF)
network.phy_mode(network.MODE_LR)
sta.active(True)
sta.disconnect()

e = espnow.ESPNow()
e.active(True)

Not sure if this actually works, my range test is inconclusive, but at least, I don't get any error messages from the IDE.
Maybe this can be useful for the CircuitPython people in implementing this feature?

@jepler jepler added this to the Long term milestone Nov 5, 2024
@stanelie
Copy link
Author

stanelie commented Nov 5, 2024

Here is un updated Micropython version that looks more correct (in how it behaves on my hardware at least) :

import network
import espnow

sta = network.WLAN(network.STA_IF)
sta.active(True) # needed BEFORE options are set
sta.config(protocol=network.MODE_LR)
sta.config(pm=sta.PM_NONE)
sta.disconnect() # prevents ESP32 from trying to connect to wifi it was previously connected to

e = espnow.ESPNow()
e.active(True)

@stanelie
Copy link
Author

stanelie commented Nov 7, 2024

Well,
After further testing, the micropython implementation is also broken, it doesn't work. I've tried all manner of permutation, setting sta.config(protocol=network.MODE_LR) before or after sta.active(True), using network.phy_mode(network.MODE_LR) instead...

In all my testing, I was able to set the LR mode once, but I can't figure out how. I was not able to get out of it without re-flashing the ESP32. It looks like this setting "sticks" in the firmware.

I leave this here for reference, in case someone else is fighting with this issue.

@anecdata
Copy link
Member

anecdata commented Nov 7, 2024

I'd suggest asking on the MicroPython Discord server, and if that doesn't pan out, file an issue on the MicroPython Gituhb repo.

@stanelie
Copy link
Author

stanelie commented Nov 7, 2024

Done : micropython#16179

@stanelie
Copy link
Author

stanelie commented Nov 7, 2024

Well,
After further testing, it looks like even if the LR mode cannot be selected, the default mode used with Circuitpython is still better then what I get with Micropython. I get about twice the range. So, I'll stick with Circuitpython for now, and hope the long range mode can be enabled soon.

@anecdata
Copy link
Member

anecdata commented Nov 7, 2024

The ESP-NOW feature was added by a community member, so there's no guarantee it will get an enhancement any time soon. If you are inclined to develop the enhancement yourself, you can get help on Adafruit's Discord server. You could even prove it out first using Espressif's esp-idf environment, with their example.

@stanelie
Copy link
Author

stanelie commented Nov 7, 2024

Sorry, I won't be able to do it, I'm just a simple user trying to make a device do what I want it to do, I'm not a developer. I was trying to avoid using Arduino and having to wait for a build everytime I change a coma, because I don't really know how to write code. Circuitpython or micropython looked attractive to me because of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants