-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32/esp8266: add support for ESP-NOW #4115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
(cherry picked from commit 00b709d2c0846b76d2b8614df39ff160e1044011)
(cherry picked from commit 6177511a5a4c5cd0ea25e7bd6999fa8c7353372e)
(cherry picked from commit 0918f0516f6906d167c3deed101cff9c993db2a8)
(cherry picked from commit 3036a8bcacca75300010e0e1ceec9f20c3880023)
workarounds: * esp_now_send() will send from whatever IF that is active/available * esp_now_mod_peer() will not crash the system
Legend! I've been meaning to get back to that forever, thanks for
picking it up and running with it.
|
@nickzoic no problem & thank you for the initial contribution! |
Attaching a minimal example:
|
@shawwwn I think this is a nice addition, it just might need a little bit of tidying up before merging. What's the reason to close it? |
Any chance we could have this PR reopened and merged? |
Yeah, I'm getting around to looking at ESP-NOW and ESP-MESH in the
near future.
|
I'ld also like to play with ESP-NOW (in Python, not being forced to do C). I just need a simple broadcaster and an arbitrary amount of no-setup receivers. Encryption does not matter, info is public and broadcasted anyway. So, any chance to accelerate this and not let it rot for ages? I can help, but not much with C stuff. |
BTW, is there any way to receive this stuff without using an ESP, e.g. on a smartphone? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments, take them rather as questions (i have no experience with espnow nor with micropython C programming).
maybe the answers could make it directly into the sourcecode as comments?
STATIC mp_obj_t espnow_init() { | ||
if (!initialized) { | ||
ESPNOW_EXCEPTIONS(esp_now_init()); | ||
ESPNOW_EXCEPTIONS(esp_now_set_self_role(ESP_NOW_ROLE_COMBO)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it have any disadvantages to use the COMBO mode if I only want to send (or receive)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option is available only in esp8266 (always COMBO mode in esp32).
Just trying to be a bit more uniform :)
u8 *addr_buf; | ||
mp_uint_t msg_len; | ||
u8 *msg_buf = (u8 *)mp_obj_str_get_data(msg, &msg_len); | ||
if (msg_len > ESP_NOW_MAX_DATA_LEN) mp_raise_ValueError("msg too long"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about "msg too long (%d bytes, but maximum is %d bytes)"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine too me.
|
||
if (addr == mp_const_none) { | ||
// send to all | ||
ESPNOW_EXCEPTIONS(esp_now_send(NULL, msg_buf, msg_len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esp8266: this is a broadcast? to everybody, not just registered peers, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to every registered peer if first argument is NULL.
So far it is the same as in esp32, however in esp32 you have to take care of IF first.
Please see my comment above.
bool first = true; | ||
int new_if = -1; | ||
if (addr == mp_const_none) { | ||
// send to all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esp32: hmm, this does not look like a broadcast (in the sense of "everybody, not just registered peers"), right?
see also the esp8266 implementation, which seems different.
is this a esp32 limitation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found the answer:
first one needs to explicitly add the broadcast "peer" like a unicast peer (so it will be in the list of peers):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still the question somehow whether this is different between esp32 and esp8266 as the docs seem to describe the api as a unified thing for esp32 and esp8266, but this code deals differently with the "None/broadcast" case depending on the device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esp32: hmm, this does not look like a broadcast (in the sense of "everybody, not just registered peers"), right?
see also the esp8266 implementation, which seems different.
is this a esp32 limitation?
What you are looking at is actually a workaround for a bug(?) in the api.
esp32:
When registering a peer, that peer will automatically bind to an available IF.
If, for some reason, that IF is down at the time when sending messages, then message won't be sent.
These extra code just making sure that message will be sent through as long as one IF is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still the question somehow whether this is different between esp32 and esp8266 as the docs seem to describe the api as a unified thing for esp32 and esp8266, but this code deals differently with the "None/broadcast" case depending on the device.
Being a proprietary protocol, they differ drastically. I typically call the esp32 version of espnow a V2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA
u8 *addr_buf; | ||
mp_uint_t msg_len; | ||
u8 *msg_buf = (u8 *)mp_obj_str_get_data(msg, &msg_len); | ||
if (msg_len > ESP_NOW_MAX_DATA_LEN) mp_raise_ValueError("msg too long"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine too me.
STATIC mp_obj_t espnow_init() { | ||
if (!initialized) { | ||
ESPNOW_EXCEPTIONS(esp_now_init()); | ||
ESPNOW_EXCEPTIONS(esp_now_set_self_role(ESP_NOW_ROLE_COMBO)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option is available only in esp8266 (always COMBO mode in esp32).
Just trying to be a bit more uniform :)
|
||
if (addr == mp_const_none) { | ||
// send to all | ||
ESPNOW_EXCEPTIONS(esp_now_send(NULL, msg_buf, msg_len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to every registered peer if first argument is NULL.
So far it is the same as in esp32, however in esp32 you have to take care of IF first.
Please see my comment above.
bool first = true; | ||
int new_if = -1; | ||
if (addr == mp_const_none) { | ||
// send to all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esp32: hmm, this does not look like a broadcast (in the sense of "everybody, not just registered peers"), right?
see also the esp8266 implementation, which seems different.
is this a esp32 limitation?
What you are looking at is actually a workaround for a bug(?) in the api.
esp32:
When registering a peer, that peer will automatically bind to an available IF.
If, for some reason, that IF is down at the time when sending messages, then message won't be sent.
These extra code just making sure that message will be sent through as long as one IF is available.
bool first = true; | ||
int new_if = -1; | ||
if (addr == mp_const_none) { | ||
// send to all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still the question somehow whether this is different between esp32 and esp8266 as the docs seem to describe the api as a unified thing for esp32 and esp8266, but this code deals differently with the "None/broadcast" case depending on the device.
Being a proprietary protocol, they differ drastically. I typically call the esp32 version of espnow a V2.
Hello, Core panic occurred when run the following script on two ESP32. Example:
Result:
Please let me know if I was using espnow module incorrectly. Thanks for your time. |
Hello I confirmed that the same error appears in the following version. Thank you |
Hello I changed recv_cb function in esp_espnow.c as bellow.
It didn't stop in collection timing by garbage collector. After I tried some case, though I do not know if recv_cb is being called from an interrupt handler, Thank you very much for your time. |
@KKawase0104 I think you maybe onto something. There is no way to know for sure if the callback was indeed originated from an interrupt handler since espnow module is closed source. Again, I don't know how garbage collector functions in regard to objects created inside interrupt handlers. Summoning @dpgeorge |
- Micropython v1.13 - v1.19 compatible - Ring buffers in shared/runtime/ringbuffer.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers) - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class: - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. - Add note on automatic channel assignment on routers. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type. Extend py/ringbuf.c and use that instead of my own implementation.
- Micropython v1.13 - v1.19 compatible - Ring buffers in shared/runtime/ringbuffer.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers) - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class: - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. - Add note on automatic channel assignment on routers. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type. Extend py/ringbuf.c and use that instead of my own implementation.
- Micropython v1.13 - v1.19 compatible - Ring buffers in shared/runtime/ringbuffer.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers) - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class: - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. - Add note on automatic channel assignment on routers. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type. Extend py/ringbuf.c and use that instead of my own implementation.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
- Micropython v1.13 - v1.19 compatible - Ring buffers in shared/runtime/ringbuffer.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers) - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class: - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. - Add note on automatic channel assignment on routers. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type. Extend py/ringbuf.c and use that instead of my own implementation.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq()/on_recv() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the esp32 espnow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ESP_NOW_ETH_ALEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (eps8266 only) constants to the WLAN class.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (ESP8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (ESP8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (ESP8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. esp32/8266: WLAN(): add support for set/get wifi power saving mode. For esp32 and esp8266: adds: - 'pm' option to WLAN.config() to set/get the wifi power saving mode; and - PM_NONE, PM_MIN_MODEM, PM_MAX_MODEM and PM_LIGHT_SLEEP (ESP8266 only) constants to the WLAN class.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland.
- Micropython v1.13 - v1.19 compatible - Use (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring (see ESPNow.peers). - Core support in "_espnow" C module (extended by espnow.py module). - Asyncio support via aioespnow.py module. - Docs provided at docs/library/espnow.rst. - PR6515. Methods in espnow.ESPNow class (modules/espnow.py): - active(True/False) - config(): set rx buffer size, read timeout and tx rate. - recv()/irecv()/recvinto() to read incoming messages from peers. - send() to send messages to peer devices - any() to test if a message is ready to read. - irq() to set callback for received messages. - stats(): Returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts). - add_peer(mac, ...): register peer before sending messages. - get_peer(mac): Return peer info: (mac,lmk,channel,ifidx,encrypt) - mod_peer(mac, ...) to change peer info parameters. - get_peers(): to return all peer info tuples. - peers_table: to support RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} aioespnow.AIOESPNow class provides coroutines: - airecv(), arecv() and asend(). ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Add constants as attributes of the espnow module: - espnow.MAX_DATA_LEN (=ESP_NOW_MAX_DATA_LEN) (250) - espnow.KEY_LEN (=ESP_NOW_KEY_LEN) (16) - espnow.MAX_TOTAL_PEER_NUM (=ESP_NOW_MAX_TOTAL_PEER_NUM) (20) - espnow.MAX_ENCRYPT_PEER_NUM (=ESP_NOW_MAX_ENCRYPT_PEER_NUM) (6) - espnow.ADDR_LEN (=ESP_NOW_ETH_ALEN) (6) Test suite in tests/multi_espnow: - Tests basic espnow data transfer, multiple transfers various message sizes, encrypted messages (pmk and lmk), asyncio support. Initial PR at: micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland.
Progress on ESPNow from micropython#4115. Initial import of code from: https://github.com/nickzoic/micropython/tree/espnow-4115. Including contributions from @nickzoic @shawwwn and @zoland. espnow: Support peer wifi signal strength (RSSI). - Maintain a peer device table (espnow_singleton->peers_table): {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} where: peerX are bytes strings containing the mac address; rssi values of last msg received (dBm from -128 to 0); and time_ms is time message received (in milliseconds since boot) - User access to the peers table via attribute: ESPNow.peers. - The peer addresses returned by irecv() and recv() are now references to the keys in peers_dict (instead of new copies of the peer address). - Add RSSI docs to docs/library/espnow.rst. - MAC address values returned by irecv()/recv() are now refernces to the peerX byte strings in the peer device table. - Add tests for the rssi functions. - Also - fixes to make asyncio tests more robust. - Rename get_singleton() _get_singleton(). - Tests: Disconnect STA before running tests: ESP8266 devices automatically re-connect to previous Access Points when STA_IF is set active. This makes receipt of messages unreliable. esp/espnow: Add aioespnow.py module for asyncio. - Add aioespnow.py to support asyncio. - Provides class AIOESPNow which extends the ESPNow interface with methods: airecv(), arecv() and asend(). Also supports "async for" iteration. - Docs and tests updated for AIO support. - Buffer Protocol (Stream IO) support is deprecated with the new async interface. esp/espnow: Mv ring_buffer.[ch] to shared/runtime. De-duplicate the ring_buffer.[ch] code in esp32 and esp8266 by moving them to shared/runtime/. esp/espnow: Code rationalisation for esp32. - Remove espnow_print() and espnow_version(). - Fix espnow_ioctl signature. esp/espnow: Remove buffer protocol support code. esp/espnow: Fix docs: RSSI is only on ESP32. - Fix docs to clarify that the peers table (supporting RSSI monitoring is not availablle on the ESP8266. - Minor re-ordering of sections (more logical). - Add advice on call to w0.disconnect() after w0.active(True) for esp8266. - Minor fixes to example code. esp/espnow: aioespnow.py: Support user extensions. - Use self.irecv() instead of super().irecv() so derived classes can override irecv()/recv()/send(). - Bugfix: drop call to self.init() in __aiter__() method. - tests/multi_espnow/: Arg to echo_test should be a bytestring. - tests/multi_espnow/: Add new test for memory leaks. esp/espnow: esp_espnow.c: More code streamlining. - Add NEW_TUPLE macro as convenience 'function' for creating tuples. - Remove unnecessary dummy espnow_stream_read()/wite() functions. - Minor reorg of code for better logical grouping. esp/espnow: Reimplement RSSI support. Streamline the RSSI support. Do not update the device-table from recv_cb(). Instead, save the rssi and timestamp in the packet buffer and update the device-table when the packet is read from irecv()/recv(). Also simplifies the device-table handling code. Docs updated to reflect the changes: - RSSI values of first messages from peer are no longer lost - Device-table is only updated when irecv()/recv() read the message from the buffer. Also for IDF < 4.2.0, rssi needs to be offset by 100. esp/espnow: Disallow user changes to peer table. Set map->is_fixed=1 to prevent changes by user code. Unset it only when we are inserting new peers. Also clean out a small bit of cruft in esp_espnow.c. esp/espnow: Bugfix in get_peers() with multicast addresses. get_peers() would cause reboot if a multi-cast address was registered with add_peer() due to inconsistent use of peer_count. esp/espnow: Wait forever in irecv()/recv() if timeout_ms < 0. ring_buffer.c: Disable the timeout if timeout_ms < 0. irecv() and recv() will wait forever if timeout is < 0. esp/espnow: Set espnow TX rate with config(rate=). Use ESPNow.config(rate=n) to set the bit rate for espnow transmissions, where n is the numeric value of one of the rates defined in "enum wifi_phy_rate_t" (see espressif wifi docs). Supported for ESP IDF version >= v4.3.0. esp/espnow: Irecv() returns msg as byte string. Make msg returned from irecv() a byte string (instead of bytearray) for consistency with recv() and convenience of users. esp/espnow: Minor code reduction for espnow_ioctl(). Also tweaks to espnow_iternext() and espnow_attr(). esp/espnow: AIOEspnow: drop singleton decorator. We can let AIOESPNow be a regular class rather than a singleton since it holds no additional state (over the ESPNow base class singleton). Singleton by decorator function makes it difficult to derive child classes from AIOESPNow and micropython does not support common method for creating singletons (overriding __new__() method). esp/espnow: Code reduction on esp8266. Rationalisation of espnow_irecv() code for some minor code size savings. esp/espnow: Fix misleading comment. esp/espnow: ioctl() return 0 if not initialised. Previously, would throw a NOT_INIT exception if called before init() or after deinit(). Now returns 0 if not initialised - ie. not ready for read or write. espnow: API changes on ESP32 before merge with main branch. Significant overhaul to address API change requests before merge into main branch. This has required some significant rewrites to maintain as much compatibility with ESP8266 as possible (due to code space constraints on ESP8266). - Replace init()/deinit() with active(True/False). - Change .config(on_recv) to .irq(cb). - Change .poll() to .any(). Following existing practice in uart, stm32/usb and pyb_can. - Extend recv() method to support alloc-free reads by passing storage buffers as optional second argument (buffers) (following approach by pyb/can module). - Delete irecv() method. Alloc-free reads are now supported with the recv() method. - Add optional size argument to send() which specifies the number of bytes from `message` which will be sent. If not provided or set to None, all the bytes in `message` will be sent. - Change .peers attribute to .peers_table in attempt to reduce confusion with get_peers() method. - Remove iterator support as requested pre merge with main branch. - Add missing ESP_NOW_ETH_ALEN as module constant. Minor refactoring: - _get_singleton() functions for compatibility with changes for the esp8266. - Minor changes to rssi update functions. - Refactor for send() method to eliminate _do_espnow_send(). espnow: API changes on ESP8266 before merge with main branch. Significant overhaul to address API change requests. This has required some substantial rewrites to fit within the code space constraints of the ESP8266. - Change init()/deinit() to active(T/F) and config(). Replace init()/deinit() with active(True/False) and reintroduce the config() method. - recv(timeout) returns [peer, msg] where peer and msg are newly alloced byte strings. - recv(timeout, buffers) where buffers is a list of bytearrays which will be used to hold the peer and message data. - Remove irecv() method. Other changes to reduce text size to accommodate changes required above. espnow: Add espnowio python module. Defines ESPNowIO child class with irecv() method to support alloc-free recv() calls (backward compatible with pre-release irecv() method). Also includes: - init() and deinit() methods for backward compatibility with pre-release API, and - Iterator support: "for peer, msg in e: print(peer, msg)" espnow: Update tests to new API. Depends on aioespnow module for convenient alloc-free read API. espnow: Update docs for new API changes. espnow: Docs: note that size arg of send() is ESP32 only. espnow: Tests: Bugfix for rssi test. Use time.ticks_ms() instead of time.time() as sanity check on rssi timestamp. It seems that since v1.19.1 time.time() is not synched with time.ticks_ms()/mp_hal_ticks_ms(). espnow: Change recv() to recvinto() on ESP32/8266. Reduce code complexity by replacing recv() method with recvinto() so that buffers *must* be supplied to read messages: recvinto([peer, msg], timeout_ms) where peer and msg are bytearrays of length 6 and 250 respectively. Timeout_ms is an optional timeout. If the first arg to recvinto() is a list with at least 4 elements, the rssi and timestamp values will be inserted as the 3rd and 4th elements (after peer and masg). Use a convenience method in the espnow.py module for a convenient user interface: recv() and irecv(). Necessitates that we revert irq() method to simpler form. support for the callback form will be moved to espnow.py. Also, remove size argument for send(). Use MICROPY_ESPNOW_RSSI pre-processor directive to include/exclude code to compute and track rssi. Use MICROPY_ESPNOW_EXTRA_PEER_METHODS pre-processor macro to conditionally compile in the mod_peer(), get_peer() and peer_count() methods. espnow: Add asyncio support for ESP8266 GENERIC target. - esp_espnow.c: add stream ioctl() support (espnow_stream_ioctl()) for asyncio support. - Add aioespnow.py to ports/esp8266/modules espnow: Move espnow module to top-level and rename _espnow. Move the espnow module from esp.espnow to _espnow. As a submodule of the esp module we lost some flexibility. Also rename espnowio.py to espnow.py so that "import espnow" will import the python wrapper module, which will then import _espnow. espnow: Update tests and docs for recent changes. Document recvinto() method and methods exposed in espnow.py: - recv(), irecv(), ... Update tests for new API. espnow: Restore workable .irq() and .on_recv() apis. - Rename _espnow.irq() to _espnow.on_recv() as low-level callback api. - Add ESPNow.irq() method to espnow.py module which supports api requested by @dpgeorge. - For on_recv(): can supply argument to callback as optional second argument eg: def cb(e): print(e.irecv(0)) e.on_recv(cb, e) - Tests: 15_irq_test.py: add tests for .irq() and .on_recv(). - Docs: Add section for "Callback Methods". espnow: Tests: rename and resequence tests following recent changes. espnow: Drop get argument of config(). espnow: Restore None argument handling for add_peer(). add_peer() is documented to permit usage: - add_peer(mac, None, None, network.AP_IF) Restore the permitted use of None to indicate that the arg should be left as is. espnow: Docs: clarify section on Espnow and Wifi Operation. Clarify the issues associated with the power saving mode and channel settings when using ESPNow while also connected to a Wifi Access Point. espnow: Docs: Include advice about wifi AP disconnects. espnow: ESP8266 fix for changes to gc_pool_start/end. espnow: Docs: Document issue with receiving msgs from esp8266 devices. Add advice on receiving ESPNow messages from esp8266 devices while connected to a wifi network on STA_IF. espnow: ESP8266: Add wifi ps_mode support for esp8266. espnow: Change ps_mode to pm. espnow: Reduce code size on ESP8266. Minor code reduction on ESP8266 to accommodate recent upstream changes: - Delete buffer conistency check in espnow_recvinto(). - espnow_send(): only check for ROM addresses higher than GC pool. espnow: Docs minor update. - ESPNow.config(rate=XX) is only available on ESP32 and IDF>=4.3.0; and - Add pointer to the espnow Issues page. espnow: Rebase against main branch. Use MP_DEFINE_CONST_OBJ_TYPE() to initialise esp_espnow_type.
ESP-NOW is a proprietary wireless communication protocol which supports connectionless communication between ESP32 and ESP8266 devices, using vendor specific WiFi frames. This commit adds support for this protocol through a new `espnow` module. This commit builds on original work done by @nickzoic, @shawwwn and with contributions from @zoland. Features include: - Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring. - Core support in `_espnow` C module, extended by `espnow.py` module. - Asyncio support via `aioespnow.py` module (separate to this commit). - Docs provided at `docs/library/espnow.rst`. Methods available in espnow.ESPNow class are: - active(True/False) - config(): set rx buffer size, read timeout and tx rate - recv()/irecv()/recvinto() to read incoming messages from peers - send() to send messages to peer devices - any() to test if a message is ready to read - irq() to set callback for received messages - stats() returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts) - add_peer(mac, ...) registers a peer before sending messages - get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt) - mod_peer(mac, ...) changes peer info parameters - get_peers() returns all peer info tuples - peers_table supports RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Also included is a test suite in tests/multi_espnow. This tests basic espnow data transfer, multiple transfers, various message sizes, encrypted messages (pmk and lmk), and asyncio support. Initial work is from micropython#4115. Initial import of code is from: https://github.com/nickzoic/micropython/tree/espnow-4115.
ESP-NOW is a proprietary wireless communication protocol which supports connectionless communication between ESP32 and ESP8266 devices, using vendor specific WiFi frames. This commit adds support for this protocol through a new `espnow` module. This commit builds on original work done by @nickzoic, @shawwwn and with contributions from @zoland. Features include: - Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO. - Signal strength (RSSI) monitoring. - Core support in `_espnow` C module, extended by `espnow.py` module. - Asyncio support via `aioespnow.py` module (separate to this commit). - Docs provided at `docs/library/espnow.rst`. Methods available in espnow.ESPNow class are: - active(True/False) - config(): set rx buffer size, read timeout and tx rate - recv()/irecv()/recvinto() to read incoming messages from peers - send() to send messages to peer devices - any() to test if a message is ready to read - irq() to set callback for received messages - stats() returns transfer stats: (tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts) - add_peer(mac, ...) registers a peer before sending messages - get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt) - mod_peer(mac, ...) changes peer info parameters - get_peers() returns all peer info tuples - peers_table supports RSSI signal monitoring for received messages: {peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...} ESP8266 is a pared down version of the ESP32 ESPNow support due to code size restrictions and differences in the low-level API. See docs for details. Also included is a test suite in tests/multi_espnow. This tests basic espnow data transfer, multiple transfers, various message sizes, encrypted messages (pmk and lmk), and asyncio support. Initial work is from micropython#4115. Initial import of code is from: https://github.com/nickzoic/micropython/tree/espnow-4115.
ESP-Now enables direct communication from one ESP device to another.
This PR is originally based on issue micropython/micropython-esp32#197 and @nickzoic's branch.
I rewrote most of the functions to make it compatible between esp32 and esp8266.
Several workarounds were introduced to get rid of inherent bugs with the SDK.
SDK Ref
https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf
https://www.espressif.com/sites/default/files/2C-ESP8266_Non_OS_SDK_API_Reference__EN.pdf
https://www.espressif.com/en/products/software/esp-now/overview
API Docs
Bugs/Caveats:
IMHO documentations from Espressif are terrible. Both SDKs are buggy as hell. API behave not as described. Many settings don't even have effect...