Skip to content

Commit 7fa322a

Browse files
glenn20dpgeorge
authored andcommitted
esp32,esp8266: Add support for the Espressif ESP-NOW protocol.
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.
1 parent 9d735d1 commit 7fa322a

38 files changed

+3542
-4
lines changed

docs/library/espnow.rst

+917
Large diffs are not rendered by default.

docs/library/index.rst

+5
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

+1
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

+9
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

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ set(MICROPY_SOURCE_PORT
8484
${PROJECT_DIR}/mpthreadport.c
8585
${PROJECT_DIR}/machine_rtc.c
8686
${PROJECT_DIR}/machine_sdcard.c
87+
${PROJECT_DIR}/modespnow.c
8788
)
8889

8990
set(MICROPY_SOURCE_QSTR

0 commit comments

Comments
 (0)