I’m struggling to find a simple example using esp now for one Esp32 board to send a message to another Esp32 board.
All the examples and tutorials that I have found don’t work for me and I get error messages.
The examples included in the ide seem over complicated and when I try to remove unnecessary code I just break it!
Any help would be greatly appreciated
gfvalvo
December 23, 2025, 2:35pm
2
That would indicate that the code you removed was in fact necessary.
xfpd
December 23, 2025, 2:38pm
3
DroneBotWorkShop.com does a great job of explaining ESP NOW (and everything he does). Wiring diagrams, sketches, and video, with descriptive narration.
Unfortunately his examples don’t work anymore, I think since the esp now update
Well, try these ones. They are a cut of sketches I’ve done after ESP changed from V2.x.x to V3.x.x (untested, since I’m far from my equipment).
Sender:
#include <esp_now.h>
#include <WiFi.h>
uint8_t broadcastAddress[] = {0x64, 0x06, 0x90, 0x64, 0x90, 0xF4}; //put here the MAC adress of the receiver ESP
typedef struct struct_message {
int command;
} struct_message;
int counter=0;
struct_message myData;
esp_now_peer_info_t peerInfo;
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { //send data callback function
Serial.print("I sent: ");
Serial.println(myData.command);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("Fail to initialize ESP-NOW");
return;
}
esp_now_register_send_cb(esp_now_send_cb_t(OnDataSent));
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Fail to ad the receiver");
return;
}
}
void loop() {
myData.command = counter++
esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
delay(2000);
}
Receiver
#include <esp_now.h>
#include <WiFi.h>
typedef struct struct_message {
int command;
} struct_message;
struct_message myData;
// Callback function executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t * incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("Fail to initialize ESP-NOW");
return;
}
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
delay(1000);
}
void loop() {
Serial.print("Data received: ");
Serial.println(myData.command);
}
Yes Brazilino , this is exactly it and wroks as i expected! thank you
You’re welcome. Happy to help. Have fun!