Reputation: 7
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.
Upvotes: 1
Views: 567
Reputation: 7
In Conclusion you can say that It IS posibille to use ESPnow on the esp 8266 in SingelCasting Mode but not in MultiCasting
Upvotes: -2
Reputation: 312213
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.
Upvotes: 0