1

I was recantly experimenting with espnow in micropython. Sudenly I rann Into A Problem wenn trying to run this code:

import network, espnow, time

wlan_sta = network.WLAN(network.STA_IF)
wlan_sta.active(True)

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

peer = b'\xff\xff\xff\xff\xff\xff'     # MAC
e.add_peer(peer)
while True:
    e.send(peer, "ESP")
    time.sleep(1.1)  # Sekunden

i get the Error OSError: -3

The Code worked on my Esp32 but not on the 8266 no clue why. I tried reflashing my esp but that did not help either.

Atschi37
  • 9
  • 3

2 Answers2

0

According to the documentation you need to call wla_sta.disconnect() after setting wlan_sta.active(True). This is the example from the docs:

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

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)

e.send("Starting...")       # Send to all peers
for i in range(100):
    e.send(peer, str(i)*20, True)
    e.send(peer, b'end')    # The example in the docs is missing the `peer` argument.

If I run that example as written (well, correcting the second call to e.send as shown in the above code) and the corresponding receiver code, it all works just fine on a pair of esp8266's running v1.19.1-espnow-6-g44f65965b.


Update I think your problem is that the esp8266 may not support the broadcast address. While the documentation suggests that the esp8266 should be able to send to the broadcast address:

All active ESP-Now clients will receive messages sent to their MAC address and all devices (except ESP8266 devices) will also receive messages sent to the broadcast MAC address (b'\xff\xff\xff\xff\xff\xff') or any multicast MAC address.

All ESP-Now devices (including ESP8266 devices) can also send messages to the broadcast MAC address or any multicast MAC address.

It appears that this isn't the case. I'm able to use the example code from the docs when operating in unicast mode, but attempting to call e.add_peer with the broadcast address results in the same error you've reported.

I've opened issue #11 with this problem.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks for the answer but it is still not working for me. I think there might be a problem with the build i have. A friend of mine made a flash of micropython with intigrated espnow for me because i have no clue how to do thath. Maybe that is the problem. What Library or build are you using? – Atschi37 Dec 07 '22 at 19:56
  • Hi, sorry that the first answer wasn't on target; I hadn't noticed at first that you were attempting to send to the broadcast address. See my update; it looks like that isn't possible right now with esp8266 devices. – larsks Dec 07 '22 at 20:32
-1

In Conclusion you can say that It IS posibille to use ESPnow on the esp 8266 in SingelCasting Mode but not in MultiCasting

Atschi37
  • 9
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 15 '22 at 19:57