ESP-NOW Control
ESP-NOW is a connectionless protocol developed by Espressif that enables direct peer-to-peer communication between ESP32 devices without requiring a WiFi access point. This is ideal for multi-arm coordination, remote controllers, and low-latency wireless control.
Concepts
Section titled “Concepts”- Leader: The device that sends control commands (can be another RoArm-M2-S or any ESP32)
- Follower: The arm that receives and executes commands
- Broadcast: Send to all followers simultaneously using
FF:FF:FF:FF:FF:FF - Group: Send to multiple registered peers
- Single: Send to one specific peer by MAC address
-
Get each device’s MAC address
{"T":302} -
Configure the follower arm
Enable broadcast reception (accepts commands from any leader):
{"T":300,"mode":1}Or restrict to a specific leader MAC:
{"T":300,"mode":0,"mac":"CC:DB:A7:5B:E4:1C"} -
Configure the leader device
Set as group leader (sends to all registered followers):
{"T":301,"mode":1}Or as single-target leader:
{"T":301,"mode":2} -
Add follower(s) to the leader’s peer list
{"T":303,"mac":"CC:DB:A7:5B:E4:1C"}
ESP-NOW Modes
Section titled “ESP-NOW Modes”| Mode | Code | Description |
|---|---|---|
| None | 0 | ESP-NOW disabled |
| Group Leader | 1 | Sends commands to all registered peers |
| Single Leader | 2 | Sends to one specific follower |
| Follower | 3 | Receives and executes commands (default) |
Sending Commands
Section titled “Sending Commands”Group Control
Section titled “Group Control”Send to all registered peers simultaneously:
{"T":305,"dev":0,"b":0,"s":0,"e":1.57,"h":1.57,"cmd":0,"megs":"hello!"}| Parameter | Description |
|---|---|
dev | Device type identifier |
b, s, e, h | Joint angles (base, shoulder, elbow, hand) |
cmd | Command mode: 0 = mirror joint positions, 1 = send JSON command in megs |
megs | Message string (JSON command when cmd=1) |
Single Device Control
Section titled “Single Device Control”Send to one specific device (or broadcast to all with FF:FF:FF:FF:FF:FF):
{"T":306,"mac":"CC:DB:A7:5B:E4:1C","dev":0,"b":0,"s":0,"e":1.57,"h":1.57,"cmd":0,"megs":"hello!"}Sending JSON Commands via ESP-NOW
Section titled “Sending JSON Commands via ESP-NOW”Set cmd to 1 and put the JSON command string in megs:
{"T":306,"mac":"FF:FF:FF:FF:FF:FF","dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":255}"}This turns on the LED on all followers.
Flow-Leader Mode
Section titled “Flow-Leader Mode”When the leader is set to mode 1 or 2 with cmd=0, it continuously mirrors its own servo positions to followers. This creates a leader-follower teleoperation setup:
- Move the leader arm manually (with torque lock off)
- The follower arm tracks the leader’s movements in real time
Managing Peers
Section titled “Managing Peers”Add a follower:
{"T":303,"mac":"CC:DB:A7:5C:1C:40"}Remove a follower:
{"T":304,"mac":"CC:DB:A7:5C:1C:40"}Command Summary
Section titled “Command Summary”| T-Code | Command | Description |
|---|---|---|
| 300 | Broadcast follower config | Enable/disable broadcast reception |
| 301 | ESP-NOW mode | Set leader/follower mode |
| 302 | Get MAC | Read this device’s MAC address |
| 303 | Add follower | Register a peer MAC |
| 304 | Remove follower | Unregister a peer MAC |
| 305 | Group control | Send to all peers |
| 306 | Single control | Send to specific MAC |
ESP-NOW reference from firmware source json_cmd.h and Waveshare Wiki.