-
Notifications
You must be signed in to change notification settings - Fork 218
ESP-Now Protocol #197
Comments
The API is subject to change but I've made a start at https://github.com/nickzoic/micropython-esp32/tree/esp32-espnow |
It seems the protocol can be used on both ESP8266 + ESP32. I wonder if an Arduino+nrf24l01 could be modified to send esp-now packets |
Yeah, I'd like to get around to implementing it on
MicroPython/ESP8266 as well.
Don't tell anyone, but the unencrypted form is pretty easy to send and
receive from a Linux "monitor" device as well :-)The encrypted version may take a little more reverse engineering.
|
Is there somewhere a working example? Without AP connection, espnow.send throws RuntimeError: ESP-Now Unknown Error 0x306c.. There is an example in the espressif docs (https://github.com/espressif/esp-idf/tree/master/examples/wifi/espnow)... but I thought I'd ask here first. |
I assume you mean from the micropython espnow branch?
I'll have to rewrite some of this stuff, and provide a better example, but here's an example of broadcast based on http://nick.zoic.org/art/rocket-surgery-airborne-iot-telemetry-buzzconf/
```
import network
w = network.WLAN(network.STA_IF)
w.active(True)
w.config(protocol=network.MODE_LR)
from esp import espnow
espnow.init()
espnow_bcast = b'\xFF' * 6
espnow.add_peer(w, espnow_bcast)
seq = 0
while True:
msg = "Hello World %d" % seq
espnow.send(espnow_bcast, msg)
time.sleep(0.004)
seq += 1
```
Receiving is even simpler:
```
import network
w = network.WLAN()
w.active(True)
w.config(protocol=network.MODE_LR)
from esp import espnow
espnow.init()
while True:
msg = espnow.recv()
if msg: print(msg[1])
```
The important bits are:
* the interfaces have to be on the same mode and channel
* the interfaces have to be active
* try broadcast first
* once you have a mac address for the peer you can add them and
unicast to them.
I'm going to rewrite it so that espnow.recv() is easier to use asynchronously or as a socket ... it is just a proof-of-concept at the moment.
|
Hey am new to micropython can you tell me how to get the esp-now working on my esp8266..that is how to install it and some few examples on it.. thanks |
@Mbonea-Mjema it's not yet implemented for the esp8266. |
Any hope of the pr that was closed a couple of days ago being merged soonish? Would love to avoid lora as another complication. |
@nickzoic This is exactly what I want to do! Do you have a working example? What library do you use to send raw wifi vendor specific action frame? |
I built MP from the esp-now repository and flashed to a couple of chips. The send program seems to be OK, but the receiver gets an error that espnow.recv() doesn't exist. Indeed if I do: |
I believe the receive example leaves a bit of tweaking. First, there is no espnow.recv function, only a espnow.set_recv_cb(callback function); secondly, I don't think the order of the statements is very helpful. I tweaked it a bit to come up with: def receivecb(msg): espnow.set_recv_cb(receivecb(msg)) while True: msg = espnow.recv()Problem is: I'm not getting anything printed out! |
OK, fixed my received problem; here is the final send code (had an error) and receive code: def receivecb(*dobj): espnow.set_recv_cb(receivecb) while True: msg = espnow.recv()----------------------------------------- end of receive code ----------------------------- in recv (b'0\xae\xa4\xfe\x92\x18', b'Hello World 90') in recv (b'0\xae\xa4\xfe\x92\x18', b'Hello World 91') in recv (b'0\xae\xa4\xfe\x92\x18', b'Hello World 92') in recv (b'0\xae\xa4\xfe\x92\x18', b'Hello World 93') As you can see, the first member of the tuple is the mac address and the next part is the text send by the sender. Since the sender is using a "broadcast" address ( = 6 bytes of 0x'ff') every device on the network would produce the same output. A specific address can be used to send only to a specific machine. But I haven't figured that out yet. |
Hello. Your script is very helpful. When I run a script similar to your script for a long time, "core panic" is occured on the receiving side. Such a phenomenon was not happening? Thank you. |
Sorry I can't help you; I didn't write the underlying espnow.c module, I just made changes to the originally posted script (which didn't work for me). How long did it take before it fails? Did you make your own firmware from the esp-now branch of the repository? I only let my program run for a couple of minutes and it continued to work that long. I believe the question would probably be best answered by the original author. Remember, this is not officially released code; therefore, there may be (and probably are) bugs somewhere that will only surface with exhaustive testing. |
Hello, Thank you for your reply. I was using shawwwn's repository because I thought it was the newest esp now module, but now I see it's not your module, sorry about that. commit 21e3426f7dec96c46d921fa16bb8e5db06572771 It took some time for the core panic to occur, but I don't remember exactly how long. When I tried after changing the sending side interval to 10msec, the core panic occurred after a couple minutes had passed. I also tried again using gc.mem_free on the receiving side. The timing of the core panic seems to be based on gc's collection timing. The sending and receiving sides my original script were the same, which made it hard for me to tell where the core panic was occurring, but with your script I could see it was on the receiving side. Thank you so much for your time. |
Discussion of this is now over at micropython/micropython#4115 and I'll make a new issue and/or pull request for on-going changes soon. The problem you've described with panics is quite possibly caused by the memory allocation issue raised here: micropython/micropython#4115 (comment) In the meantime I'm closing this issue as the micropython-esp32 repo is closed now. |
ESP-Now offers a low-level adhoc network over 802.11 frames ... make this available from a nice MicroPython API.
Refs:
http://espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf
http://esp-idf.readthedocs.io/en/latest/api-reference/wifi/esp_now.html
http://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf chapter 3.8
This is related to #176 (mesh networking) and #188 (generalized packet objects)
The text was updated successfully, but these errors were encountered: