Micropython espnow wrapper

May 29, 2026 ยท View on GitHub

Send and receive data between ESPs over espnow without worries. This library provides asynchronous message sending and receiving with support for chunked data transmission and acknowledgments.

Features

  • Asynchronous ESP-NOW message handling
  • Automatic chunking of large messages
  • CRC32 verification for data integrity
  • Optional acknowledgment (ACK) support
  • Configurable timeout and cycle time
  • Debugging mode for easier troubleshooting

install

Install using ViperIDE

Usage

Initializing the ESPNowManager

from mp_espnow_wrapper import ESPNowManager

esp_manager = ESPNowManager(peer='AA:BB:CC:DD:EE:FF', debug=True)
esp_manager.set_callback('on_receive', lambda msg: print("Received:", msg))
esp_manager.init()

Sending Messages

import asyncio

async def send():
    message = b'Hello ESP-NOW!'
    await esp_manager.send(message)

asyncio.run(send())

Receiving Messages

Call init() to start the background receive task. Register callbacks with set_callback(event, callback):

  • 'on_receive': Called when a complete, verified message is received. The callback accepts one argument: the message as a bytearray.
  • 'on_timeout': Called when no message is received within timeout_ms. The callback accepts no arguments.
esp_manager.set_callback('on_receive', lambda msg: print("Received:", msg))
esp_manager.set_callback('on_timeout', lambda: print("Timeout!"))

Configuration

  • peer: MAC address of the target device (default: broadcast)
  • rxbuf: Buffer size for incoming messages
  • timeout_ms: Message receive timeout in ms
  • cycle_time_ms: Interval between message chunks (ms). Needs to be > 2โ€“3 ms for stable operation
  • wait_msg_ack: Whether to wait for acknowledgment after sending. Includes the on_receive callback execution at the receiver.
  • send_ack_after_cb: Whether to send ACK after the callback execution (instead of before).
  • send_async: Whether to send messages asynchronously.
  • debug: Enables debug output