If you have the kindness and the time, it should only take a few min.
If you have a 2 ESP32 boards or a ESP32 and a ESP8266
If you load my original code at the top of my post into a ESP32
And load this code into another ESP32 to be the ESP-Now receiver:
#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_now.h>
uint8_t CustomMacAddress = {0x20, 0xAE, 0xA4, 0x20, 0x0D, 0x20};
typedef struct now_struct {
int d1 = 123; // fake test data
int d2 = 456; // fake test data
}
now_struct;
now_struct NowData;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
esp_wifi_set_mac(ESP_IF_WIFI_STA, &CustomMacAddress[0]);
if (esp_now_init() != ESP_OK) {return;}
esp_now_register_recv_cb(OnDataRecv);
}
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&NowData, incomingData, sizeof(NowData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("D1: "); Serial.println(NowData.d1);
Serial.print("D2: "); Serial.println(NowData.d2);
Serial.println();
}
void loop() {
}
or if you don't have another ESP32 load this code into a ESP8266
#include <ESP8266WiFi.h>
#include <espnow.h>
uint8_t CustomMacAddress = {0x20, 0xAE, 0xA4, 0x20, 0x0D, 0x20};
typedef struct now_struct {
int d1;
int d2;
}
now_struct;
now_struct NowData;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
wifi_set_macaddr(STATION_IF, &CustomMacAddress[0]);
if (esp_now_init() != 0) {return;}
esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);
}
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
memcpy(&NowData, incomingData, sizeof(NowData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("D1: "); Serial.println(NowData.d1);
Serial.print("D2: "); Serial.println(NowData.d2);
Serial.println();
}
void loop() {
}
Then watch the serial monitor on the ESP32 sender you will see:
Delivery Status: fail
Comment out the WiFi.begin(ssid, password);
Then reload it you will see:
Delivery Status: ok
Thanks,
Mike.