8000 esp/espnow: Support for the Espressif ESP-NOW protocol. · glenn20/micropython@d365770 · GitHub
[go: up one dir, main page]

Skip to content

Commit d365770

Browse files
committed
esp/espnow: Support for the Espressif ESP-NOW protocol.
- 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.
1 parent 294baf5 commit d365770

38 files changed

+3576
-4
lines changed

docs/library/espnow.rst

Lines changed: 917 additions & 0 deletions
Large diffs are not rendered by default.

docs/library/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ The following libraries are specific to the ESP8266 and ESP32.
155155
esp.rst
156156
esp32.rst
157157

158+
.. toctree::
159+
:maxdepth: 1
160+
161+
espnow.rst
162+
158163

159164
Libraries specific to the RP2040
160165
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ports/esp32/boards/manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require("bundle-networking")
66

77
# Require some micropython-lib modules.
8+
# require("aioespnow")
89
require("dht")
910
require("ds18x20")
1011
require("neopixel")

ports/esp32/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
#include "extmod/modbluetooth.h"
6868
#endif
6969

70+
#if MICROPY_ESPNOW
71+
#include "modespnow.h"
72+
#endif
73+
7074
// MicroPython runs as a task under FreeRTOS
7175
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
7276
#define MP_TASK_STACK_SIZE (16 * 1024)
@@ -190,6 +194,11 @@ void mp_task(void *pvParameter) {
190194
mp_bluetooth_deinit();
191195
#endif
192196

197+
#if MICROPY_ESPNOW
198+
espnow_deinit(mp_const_none);
199+
MP_STATE_PORT(espnow_singleton) = NULL;
200+
#endif
201+
193202
machine_timer_deinit_all();
194203

195204
#if MICROPY_PY_THREAD

ports/esp32/main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(MICROPY_SOURCE_PORT
8585
${PROJECT_DIR}/mpthreadport.c
8686
${PROJECT_DIR}/machine_rtc.c
8787
${PROJECT_DIR}/machine_sdcard.c
88+
${PROJECT_DIR}/modespnow.c
8889
)
8990

9091
set(MICROPY_SOURCE_QSTR

0 commit comments

Comments
 (0)
0