Source: https://mokxi.com/libraries/esp-now
Updated: 2026-11-23

Libraries / Communication

Arduino library · Communication

# ESP-NOW on the ESP32: board to board with no router

Yes. You can use the ESP-NOW (ESP32 core) library online in Mokxi with nothing to install, and the sketch runs in your browser. The example below, "ESP-NOW button and LED", runs on the ESP32 DevKit V1.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <esp_now.h> and it builds, with nothing to install. Free, and no account needed.

## What ESP-NOW (ESP32 core) does

ESP-NOW is Espressif’s own radio protocol: one ESP32 sends a short frame straight to another one’s MAC address, with no access point, no IP address and no connection to set up. A message of up to 250 bytes arrives within a millisecond or two, and the receiving radio answers with an acknowledgment, which suits remote buttons, sensor nodes on batteries and robot controllers.

A sketch puts WiFi in station mode, calls esp_now_init(), and then either adds the other board as a peer and calls esp_now_send(), or registers a receive callback and waits. The usual pattern is a struct defined the same way on both boards: the sender passes its bytes, the receiver copies them back into the struct. The send callback reports whether the other radio acknowledged.

The runnable project here is two ESP32s on one canvas: a button on GPIO 4 of one toggles an LED on GPIO 4 of the other. Mokxi simulates the air between every ESP board on the canvas, with each board’s MAC, channels, ACKs and timing, so a wrong MAC really gives "Delivery fail". There is no range or fading, and encryption is accepted but not applied. For the ESP8266’s different API, see the espnow.h page.

Library Manager name | ESP-NOW (ESP32 core)

Author | Espressif

Include | #include <esp_now.h>

Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM

In the simulator | Simulated: it runs against the part the way it does on the bench.

## Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM.

In Mokxi it is built in: #include <esp_now.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board it comes with the board package (Espressif), so the Arduino IDE has it as soon as the board is installed: there is nothing to add from the Library Manager.

- ESP32-C3
- ESP32-C6
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32 DevKit
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- ESP32-S3-DevKitC-1
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- ESP32-S3-CAM

## The calls you will use

In the order a sketch meets them.

### esp_now_init()

Starts ESP-NOW after WiFi.mode(WIFI_STA). Returns ESP_OK on success; nothing else in the API works before it.

### esp_now_register_send_cb(onSent)

Registers the function told about each send: ESP_NOW_SEND_SUCCESS when the receiver’s radio acknowledged, a failure otherwise.

### esp_now_peer_info_t peer = {}

Describes the board you will send to: copy its MAC into peer.peer_addr, set peer.channel to 0 for the current channel and peer.encrypt to false.

### esp_now_add_peer(&peer)

Adds the receiver to the peer list. esp_now_send() to an address that is not a peer fails.

### esp_now_send(receiverMac, (uint8_t *)&msg, sizeof(msg))

Sends up to 250 bytes to one peer. ESP_OK means the frame was queued; the send callback says later whether it arrived.

### esp_now_register_recv_cb(onReceive)

Registers the function that runs for each frame received, with the sender’s address, the bytes and the length.

## Example: ESP-NOW button and LED

On the ESP32 DevKit V1. It runs in the browser exactly as printed.

sketch.ino · ESP32 DevKit V1

Open it in the editor, wired and ready to run · ESP-NOW button and LED: the project page

## Common errors and how to fix them

### invalid conversion from 'void (*)(const uint8_t*, esp_now_send_status_t)'

The callback signatures changed with Arduino-ESP32 core 3.x. The send callback now takes const wifi_tx_info_t *info (core 3.3) and the receive callback const esp_now_recv_info_t *info, with the sender’s MAC in info->src_addr. Match the core you build with; Mokxi accepts both forms.

### Every send prints "Delivery fail"

No radio acknowledged that MAC. Print WiFi.macAddress() on the receiver and copy it byte for byte into the sender, and keep both boards on the same channel. In the Mokxi project the receiver’s wifiMac setting is that address; clear it and every send fails.

### ESP-NOW stops working once the board joins my router

Joining an access point moves the radio to the router’s channel, and frames on another channel are not heard. Put the receiver on the same channel, or set the peer channel to 0 so it follows the current one.

### The received numbers are garbage

The struct differs between the two sketches, so the bytes are read with the wrong layout. Copy the exact same typedef into both, check len equals sizeof(msg) before memcpy(), and avoid String fields, which hold a pointer rather than the text.

## Questions and answers

### Can an ESP32 and an ESP8266 talk ESP-NOW?

Yes, the frames are the same on the air. The ESP8266 uses espnow.h with roles and a different callback signature, but a struct of fixed-size fields reads the same on both. Mokxi carries frames between both kinds of board on one canvas.

### How far does ESP-NOW reach?

It depends on the antenna, walls and interference, so test on real boards where they will be mounted. The simulator has no range, so every board on the canvas hears every other.

## Keep going

### Learn

- ESP32 DevKit V1 Pinout: Every Pin and Which to Avoid
- ESP32 Projects for Beginners You Can Run Right Now

### More communication libraries

- OneWire
- TinyGPS
- TinyGPSPlus
- MFRC522
- SoftwareSerial
- AltSoftSerial
- i2cdetect
- Keyboard
- RadioHead (RH_NRF24 driver)
- RF24Mesh
- SoftWire
- MicroNMEA
- NeoGPS

Every built-in library · Open the editor

## Try ESP-NOW (ESP32 core) without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
