Not exactly sure what I am missing but if it's because I did not post the ESPNOW_Basic_Master listed on the Arduino IDE my bad. Made the "assumption" that it wasn't necessary because sketch is available on the Arduino IDE.
Here's a sketch that failed on Nano ESP32 and Adafruit Feather S3, exactly the same way, but ran okay on the other two development boards.
If that's not the reason for my not in board compliance please be specific.
Thank you.
/*
ESP-NOW Broadcast Master
Lucas Saavedra Vaz - 2024
This sketch demonstrates how to broadcast messages to all devices within the ESP-NOW network.
This example is intended to be used with the ESP-NOW Broadcast Slave example.
The master device will broadcast a message every 5 seconds to all devices within the network.
This will be done using by registering a peer object with the broadcast address.
The slave devices will receive the broadcasted messages and print them to the Serial Monitor.
*/
#include "ESP_NOW.h"
#include "WiFi.h"
#include <esp_mac.h> // For the MAC2STR and MACSTR macros
/* Definitions */
#define ESPNOW_WIFI_CHANNEL 6
/* Classes */
// Creating a new class that inherits from the ESP_NOW_Peer class is required.
class ESP_NOW_Broadcast_Peer : public ESP_NOW_Peer {
public:
// Constructor of the class using the broadcast address
ESP_NOW_Broadcast_Peer(uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) : ESP_NOW_Peer(ESP_NOW.BROADCAST_ADDR, channel, iface, lmk) {}
// Destructor of the class
~ESP_NOW_Broadcast_Peer() {
remove();
}
// Function to properly initialize the ESP-NOW and register the broadcast peer
bool begin() {
if (!ESP_NOW.begin() || !add()) {
log_e("Failed to initialize ESP-NOW or register the broadcast peer");
return false;
}
return true;
}
// Function to send a message to all devices within the network
bool send_message(const uint8_t *data, size_t len) {
if (!send(data, len)) {
log_e("Failed to broadcast message");
return false;
}
return true;
}
};
/* Global Variables */
uint32_t msg_count = 0;
// Create a broadcast peer object
ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL);
/* Main */
void setup() {
Serial.begin(115200);
// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
while (!WiFi.STA.started()) {
delay(100);
}
Serial.println("ESP-NOW Example - Broadcast Master");
Serial.println("Wi-Fi parameters:");
Serial.println(" Mode: STA");
Serial.println(" MAC Address: " + WiFi.macAddress());
Serial.printf(" Channel: %d\n", ESPNOW_WIFI_CHANNEL);
// Register the broadcast peer
if (!broadcast_peer.begin()) {
Serial.println("Failed to initialize broadcast peer");
Serial.println("Reebooting in 5 seconds...");
delay(5000);
ESP.restart();
}
Serial.println("Setup complete. Broadcasting messages every 5 seconds.");
}
void loop() {
// Broadcast a message to all devices within the network
char data[32];
snprintf(data, sizeof(data), "Screw You! #%lu", msg_count++);
Serial.printf("Broadcasting message: %s\n", data);
if (!broadcast_peer.send_message((uint8_t *)data, sizeof(data))) {
Serial.println("Failed to broadcast message");
}
delay(5000);
}
In order to assist, we need to see your EXACT code posted, you may have copy/pasted with some kind of error. This means you go to your sketch, select all, copy, back here to the forum and paste in code tags. NOW I can copy your code and see the errors.
Is your last post of source like that?
I grabbed your last sketch and it does NOT compile for a basic esp32. I am going to get a known good sketch just to make sure the DOIT board is valid. Back in a few.
Ok, I loaded a known good sketch, selected regular DOIT dev esp32 board, using 2.0.17 and all good. I have to go to breakfast now but will repeat with boards 3 when I return. Basically you have several errors.
Seems like the Arduino IDE does not like it if you try to mix "boards" on the same sketch instance. By this I run a sketch using Board A and then run the same sketch instance using Board B or perhaps Board C one of them a failed compile and you have to start with a fresh instance.
That seems to have been the case with my NANO ESP32 failure to compile. I started from scratch with a new instance of the sketch and it compiled okay.
Not sure if this is a total solution but at least this is what I found.
Not correct. Mistakenly loaded an old version of ESP32 Master which ran OK. My BAD!
My known good sketch also works with Boards 3, probably because that sketch does not use the part of the API that is changed and causing old code to trip up.
Now back to your specific problem. As I see it you have 2 possible trip points assuming a good sample sketch.
The Boards 3 issue.
Does an Arduino NANO ESP32 i fact support ESP-NOW
Did you pick the correct NANO ESP32 board, there are two of them, one by ESP and one by Aeduino. You want the one by Arduino. See attached pic.
I have no idea if the Adafruit board will work.
Are we in synch now?
Next I will try the Arduino NANO ESP32 using Boards 3 and my sample sketch to prove that in fact the Arduino NANO 32 supports ESP-NOW. brb
Not sure what you mean, but did you in fact use the correct NANO-ESP32, there are TWO of them, the wrong one by Espressif, and the right one by Arduino.
Somehow in loading so many sketches and unloading I somehow loaded an older version of ESP32 NOW Master which runs okay.
But the newest one doesn't.
This is the initial error message that I get.
C:\Users\Paul\AppData\Local\Temp\.arduinoIDE-unsaved2025010-20244-gdjl2a.wlvub\ESP_NOW_Broadcast_Master\ESP_NOW_Broadcast_Master.ino:14:10: fatal error: ESP32_NOW.h: No such file or directory
#include "ESP32_NOW.h"
^~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: ESP32_NOW.h: No such file or directory
The board I'm using is supposed to be an official Arduino NANO ESP32. I purchased it directly from Arduino. It's has all of the Arduino logo and information on the bottom and top.
I also reran the Adafruit S3 Feather and a compiled okay.
Something that I may have been missing with your replies.
For me both verify and compile fail the same way. Are you seeing the same thing that if you verify you fail and if you try to compile you fail with the board that is exhibiting failure?
I can neither verify or compile without getting a failure with NANO ESP32 as a selected board.
I've also tried to compile with a second "official" Arduino NANO ESP32 same result.