#include <esp_now.h>
#include <WiFi.h>
uint8_t customMAC[] = {0x24, 0x6F, 0x28, 0x12, 0x34, 0x01};
uint8_t receiverAddress[] = {0x24, 0x6F, 0x28, 0xFF, 0xFF, 0xFF}; // Replace with receiver's MAC address
const char* message = "Hello ESP-NOW";
void onSent(const uint8_t* macAddr, esp_now_send_status_t status) {
Serial.print("Message Sent: ");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Success" : "Failed");
}
void setup() {
Serial.begin(115200);
esp_base_mac_addr_set(customMAC);
Serial.print("Custom MAC Address Set: ");
Serial.println(WiFi.macAddress());
WiFi.mode(WIFI_STA); // Set WiFi mode to Station (STA)
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW Initialization Failed");
return;
}
esp_now_register_send_cb(onSent);
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, receiverAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to Add Peer");
return;
}
}
void loop() {
esp_now_send(receiverAddress, (uint8_t*)message, strlen(message));
delay(2000);
}