1The board is not an ESP8266
espnow.h is the ESP8266 header. Choose an ESP8266 board. In Mokxi, ESP-NOW is simulated between the ESP boards on the canvas.
#include <espnow.h>
void setup() {
Serial.begin(9600);
}
void loop() {
}#include <ESP8266WiFi.h>
#include <espnow.h>
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
typedef struct struct_message {
char a[32];
int b;
} struct_message;
struct_message myData;
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
(void)mac_addr;
Serial.print("Last Packet Send Status: ");
Serial.println(sendStatus == 0 ? "Delivery success" : "Delivery fail");
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_register_send_cb(OnDataSent);
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
strcpy(myData.a, "THIS IS A CHAR");
myData.b = 7;
esp_now_send(broadcastAddress, (uint8_t *)&myData, sizeof(myData));
Serial.println("Sent");
}
void loop() {}Mokxi’s build tab says: espnow.h is the ESP8266 core's ESP-NOW