Cool! I am happy to see that helped
This explains a lot. I will do some testings in this way. But I have one point - When sender uses STA_IF with e.add_peer(peer, None, 11, network.STA_IF) and receiver AP_IF (STA_IF is not used!), w1.config(channel=11) with e.add_peer(peer, None, 11, network.STA_IF) - message is not received, when remove w1.config(channel=11), it works:TL/DR: When using AP and STA together, the AP will always change channel to that of the STA (See "Attention" note 3 at https://docs.espressif.com/projects/esp ... i_config_t). That is, your AP is running on channel 4, not channel 11 as you expect. You can verify this with w0.scan() on your sender node.
w1.config('channel') will also report the incorrect channel - adding to the confusion (I have fixed that in forthcoming commit - see below).
- Sender (broadcasting messages, better if receiver is changing):
Code: Select all
message='Hello dear peer' e = espnow.ESPNow() e.init() w0 = network.WLAN(network.STA_IF) w0.active(True) reciever = b'\xFF\xFF\xFF\xFF\xFF\xFF' e.add_peer(reciever, None, 11, network.STA_IF) e.send(reciever, message.encode())
- Receiver:
Code: Select all
w1 = network.WLAN(network.AP_IF) w1.active(True) w1.config(hidden=True) # w1.config(channel=11) <-- this breaks receiving messages peers = ["fc:f5:c4:56:09:68", "a0:20:a6:16:59:15", "5c:cf:7f:0e:6c:61", "84:0d:8e:3b:87:38"] for peer in peers: peer = bytes([int(x, 16) for x in peer.split(':')]) e.add_peer(peer, None, 11, network.AP_IF) print('Receiving A...') while True: msg = e.irecv() if msg: print(msg) if msg[1] == b'end': break
OK, I will read documentation again, I don't need encrypted messages for now... I probably forgot some details...
- Setting the pmk on it's own does nothing...
It is possible, this previous posted code is simplified and I probably forgot something. New posted code is working... For example, original code uses MAC in "normal" form and convert them to bytecode, various options are in dict for easier configuration of multiple senders etc, as you can see in receiver code...Interestingly, your "Sender" code did not work for me at all. (It does contain typos, so it seems to be an almost copy of the actual code you are running):
Hohoho! This is story like from some CIA file, thanks for your work. I was looking for your latest commit earlier today, I will build FW with them and try... Btw, I am building micropython with latest esp-idf, so this can cause some problems too (I use git repo and forgot switch to some stable release). If you are using 4.0.2, I will switch to this version....
- On e.send(), I would get an ESP_ERR_ESPNOW_ARG exception and the Espressif stack would print:
It seems that at some point Espressif started enforcing this restriction in an update to the IDF (since I originally tested this behaviour last year with IDF3).Code: Select all
E (6613) ESPNOW: Peer channel is not equal to the home channel, send fail!
You are welcomeOnce again - thanks for uncovering this changed and very inconvenient behaviour!!!!