ESP-NOW and Mesh Networking
After Wi-Fi, the next important ESP32 wireless concept is ESP-NOW and mesh networking.
These are useful when you have multiple ESP32 boards that need to communicate with each other.
For example:
ESP32 #1 ESP32 #2 Sensor Display │ ▲ │ │ └────── ESP-NOW ──────┘
No traditional router is required for basic ESP-NOW communication.
1. What is ESP-NOW?
ESP-NOW is a wireless communication protocol developed for Espressif devices.
It allows devices to exchange small amounts of data directly.
ESP32 A │ │ ESP-NOW │ ▼ ESP32 B
Compared with normal Wi-Fi:
Normal Wi-Fi: ESP32 → Router → ESP32
ESP-NOW can be:
ESP-NOW: ESP32 → ESP32
2. Why Use ESP-NOW?
ESP-NOW is useful when you need:
- Fast device-to-device communication
- Low overhead
- Low power
- No traditional Wi-Fi router
- Remote sensors
- Wireless buttons
- Robotics
- Smart agriculture
- Home automation
For example:
Wireless Button │ ESP-NOW │ ▼ ESP32 │ ▼ Relay
Press the button and the remote ESP32 can turn on a light.
3. ESP-NOW vs Wi-Fi
| Feature | Normal Wi-Fi | ESP-NOW |
|---|---|---|
| Router required | Usually | ❌ Not for basic peer communication |
| Internet | Can use | ❌ Not inherently |
| Device-to-device | Yes | Yes |
| Setup | More networking | Lightweight |
| IoT sensors | Good | Excellent |
| Web server | Excellent | Not its purpose |
| Cloud | Yes | Not directly |
| Low-power applications | Possible | Very useful |
Think:
Wi-Fi → Network + Internet ESP-NOW → Device-to-device communication
4. ESP-NOW Architecture
A simple system:
ESP32 TRANSMITTER │ │ ESP-NOW │ ▼ ESP32 RECEIVER │ ┌──────┼──────┐ │ │ │ LED Relay Motor
The transmitter sends a packet.
Example:
LED = ON
Receiver receives it and performs the action.
5. MAC Address
ESP-NOW commonly identifies peers using their MAC addresses.
A MAC address looks like:
24:6F:28:AB:CD:EF
You can think of it as a hardware/network identifier.
ESP32 A MAC: AA:BB:CC:11:22:33 ESP32 B MAC: AA:BB:CC:44:55:66
Then A can communicate with B.
6. Find ESP32 MAC Address
Example:
#include <WiFi.h> void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); Serial.print("MAC Address: "); Serial.println(WiFi.macAddress()); } void loop() { }
Serial Monitor might show:
MAC Address: 24:6F:28:AB:CD:EF
You can use this address when configuring ESP-NOW peers.
7. Basic ESP-NOW Concept
Imagine two boards:
ESP32 #1 TRANSMITTER │ │ │ "LED ON" ▼ ESP32 #2 RECEIVER │ ▼ LED
The transmitter sends data.
The receiver processes it.
8. Sending Structured Data
You don't have to send only strings.
You can create a structure:
typedef struct { int temperature; int humidity; bool motion; } SensorData;
Then send:
Temperature = 29 Humidity = 65 Motion = true
Conceptually:
ESP32 │ └── SensorData ├── temperature ├── humidity └── motion │ ESP-NOW │ ▼ ESP32
This is extremely useful for IoT.
9. Example IoT System
Imagine you have two ESP32 boards.
ESP32 #1
Connected to:
DHT22 PIR
ESP32 #2
Connected to:
LCD Relay Buzzer
Architecture:
DHT22 ──┐ │ PIR ────┤ ▼ ESP32 #1 │ ESP-NOW │ ▼ ESP32 #2 / | \ / | \ LCD Relay Buzzer
ESP32 #1 can send:
Temperature: 28°C Humidity: 64% Motion: YES
ESP32 #2 displays and acts on the information.
10. ESP-NOW Callback
ESP-NOW communication is event-based.
When a packet arrives, a callback function can be triggered.
Conceptually:
void onDataReceived(...) { // Process received data }
This means you don't necessarily need to continuously poll for data.
11. Important ESP-NOW Concept: Peer
A peer is another device that your ESP32 communicates with.
Example:
ESP32 A │ ├── Peer B ├── Peer C └── Peer D
One ESP32 can communicate with multiple ESP32 devices, subject to ESP-NOW/platform limitations.
12. One-to-One
The simplest topology:
ESP32 A │ │ ▼ ESP32 B
Example:
Remote Button → ESP32 → Relay
13. One-to-Many
One ESP32 can act as a transmitter for several devices.
ESP32 A │ ┌─────────┼─────────┐ │ │ │ ▼ ▼ ▼ ESP32 B ESP32 C ESP32 D
Example:
Central Controller │ ├── Room 1 ├── Room 2 └── Room 3
14. Many-to-One
Several sensor ESP32s can send data to one central ESP32.
ESP32 Sensor 1 ──┐ ESP32 Sensor 2 ──┤ ESP32 Sensor 3 ──┼──→ Central ESP32 ESP32 Sensor 4 ──┘
For smart farming:
Central ESP32 ▲ ┌─────────┼─────────┐ │ │ │ Soil 1 Soil 2 Soil 3 ESP32 ESP32 ESP32
15. What is Mesh Networking?
Now we move to a different concept.
In a mesh network, devices can communicate through other devices.
Example:
ESP32 A │ ▼ ESP32 B │ ▼ ESP32 C │ ▼ ESP32 D
If A cannot directly reach D, B and C can potentially help relay communication depending on the mesh implementation.
16. Why Mesh?
Imagine a large farm:
Farm ───────────────────────────── Sensor A Sensor B \ / \ / ESP32 C │ ESP32 D │ Main Controller
A single wireless link may not cover the entire area.
Mesh can extend communication through multiple nodes.
17. Normal Wi-Fi vs Mesh
Normal network
Router / | \ / | \ A B C
All devices communicate through the router.
Mesh
A ─── B ─── C │ │ D ─────┘
Devices can communicate through multiple paths.
18. ESP-NOW vs Mesh
Don't confuse these two.
ESP-NOW
Primarily:
Device ↔ Device
Fast, lightweight wireless communication.
Mesh
Primarily:
Device ↕ Device ↕ Device ↕ Device
A network architecture where nodes can relay/route information.
ESP-NOW can be used as a building block in some custom multi-node systems, but ESP-NOW itself is not automatically a full mesh routing protocol.
19. Example: Wireless Remote Car
This is especially useful for robotics.
Remote ESP32 Controller │ ESP-NOW │ ▼ Car ESP32 / \ / \ L298N Motors
Remote commands:
F → Forward B → Backward L → Left R → Right S → Stop
The car does not need your home Wi-Fi router.
20. Example: Smart Agriculture
Imagine 5 sensor nodes:
Main ESP32 Controller ▲ ┌──────────┼──────────┐ │ │ │ ▲ ▲ ▲ Node 1 Node 2 Node 3 Soil Soil DHT22
Data:
Node 1: Soil = 35% Node 2: Soil = 42% Node 3: Temperature = 31°C Humidity = 58%
Central ESP32 can decide:
Soil < 30% ↓ Pump ON
21. ESP-NOW + Wi-Fi
One powerful architecture is:
Sensors │ │ ESP-NOW ▼ Gateway ESP32 │ │ Wi-Fi ▼ Internet │ ▼ Cloud
This is very useful for IoT.
For example:
Soil Sensor ESP32 │ │ ESP-NOW ▼ Gateway ESP32 │ │ Wi-Fi ▼ Firebase / MQTT / Server
The sensor nodes don't each need an Internet connection.
22. Practical Project
Wireless Home Sensor
ESP32 #1:
PIR DHT22 LDR
ESP32 #2:
LCD Relay Buzzer
Communication:
┌───────────────┐ │ ESP32 #1 │ │ │ │ PIR │ │ DHT22 │ │ LDR │ └───────┬───────┘ │ ESP-NOW │ ▼ ┌───────────────┐ │ ESP32 #2 │ │ │ │ LCD │ │ Relay │ │ Buzzer │ └───────────────┘
This is a very good practical ESP32 project.
23. Advantages of ESP-NOW
✅ No normal router required
✅ Fast communication
✅ Low overhead
✅ Useful for battery-powered nodes
✅ Good for remote controls
✅ Good for sensors
✅ Good for robotics
✅ Multiple ESP32 devices can communicate
24. Limitations
ESP-NOW isn't a replacement for Wi-Fi in every project.
❌ Not designed for normal web browsing
❌ Doesn't inherently provide Internet access
❌ Small packet-oriented communication
❌ Peer management is required
❌ Range depends on hardware/environment
❌ Mesh routing isn't automatically provided
25. Common Mistakes
❌ Wrong MAC address
If the receiver's MAC is incorrect, communication won't work.
❌ Wi-Fi mode problems
ESP-NOW operates through the ESP32's Wi-Fi radio, so Wi-Fi configuration/channel considerations matter.
❌ Different Wi-Fi channels
When combining ESP-NOW with a Wi-Fi network, channel configuration becomes important.
❌ Forgetting callbacks
ESP-NOW applications commonly use callbacks for send/receive events.
❌ Sending incompatible data
Both devices should agree on the data structure.
For example:
Sender: temperature humidity motion
Receiver should interpret those fields in the same order/type.
🧠 Quick Summary
ESP-NOW │ ├── Direct ESP32 communication ├── No normal router required ├── Fast ├── Lightweight ├── Low power └── Excellent for IoT
Mesh:
ESP32 A │ ▼ ESP32 B │ ▼ ESP32 C │ ▼ ESP32 D
And a powerful IoT architecture is:
Sensor ESP32 │ ESP-NOW │ ▼ Gateway ESP32 │ Wi-Fi │ ▼ Cloud / Internet