glenn20 / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
38 stars 9 forks source link

add_peer() has no effect on ESP8285 #18

Closed inovatorius closed 1 year ago

inovatorius commented 1 year ago

Hey!

I am developing ESP-NOW event system around uasyncio and finally got my hands to report this issue (or more like convenient feature).

On ESP8285 add_peer() has no effect. I can send messages to a peer STA/AP MAC address without using add_peer(). I used the example according the https://github.com/glenn20/micropython/blob/espnow-g20/docs/library/espnow.rst

I am using custom build of espnow-g20-v1.20.0 branch. Maybe there are some differences in ESP8285 SDK or something?

import network
import espnow

# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)  # Or network.AP_IF
sta.active(True)
sta.disconnect()      # For ESP8266 (and also for ESP8285)

e = espnow.ESPNow()
e.active(True)
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'   # MAC address of peer's wifi interface
e.add_peer(peer)      # Must add_peer() before send() <- This line has no effect

e.send(peer, "Starting...")
for i in range(100):
    e.send(peer, str(i)*20, True)
e.send(peer, b'end')
glenn20 commented 1 year ago

Thanks for noting this. It is a known issue that the esp8266 SDK does not enforce registering peer devices before send(). I have read ambiguous docs about this for the esp8266, and it is enforced in the IDF (ESP32 and variants).

I will update the micropython docs to clarify.