#include // initializing the required resource libraries #include // uint8_t broadcastAddress[] = {0xEC, 0xFA, 0xBC, 0x1D, 0xBC, 0x07}; // RECEIVER MAC Address //---------------------------------------------------------------------------------------------------------------------------------------------------- /*Define a structure that contains all the data that you want to send and receive. The structure must be same on both transmitter and receiver*/ //---------------------------------------------------------------------------------------------------------------------------------------------------- typedef struct struct_message { //create a structure called "message" and add the contents of the message char a[32]; //character "a" of max size 32 bytes int b; //integer value "c" float c; //float value "c" String d; // String "d" bool e; // boolean value "e" } struct_message; struct_message myData; // Create a struct_message called myData unsigned long lastTime = 0; unsigned long timerDelay = 2000; // send readings timer // Callback when data is sent This is a callback function to verify if the data is successfully sent void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) { Serial.print("Last Packet Send Status: "); if (sendStatus == 0){ Serial.println("Delivery success"); } else{ Serial.println("Delivery fail"); } } void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != 0) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER); esp_now_register_send_cb(OnDataSent); // Register peer esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0); } void loop() { if ((millis() - lastTime) > timerDelay) { // Set values to send strcpy(myData.a, "THIS IS A CHAR"); myData.b = random(1,20); myData.c = 1.2; myData.d = "Hello"; myData.e = false; // Send message via ESP-NOW esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); lastTime = millis(); } }