#include #include // REPLACE WITH RECEIVER MAC Address uint8_t broadcastAddress[] = {0x58, 0xBF, 0x25, 0xD6, 0xF6, 0x8C}; #define REF_PIN 5 // Structure example to send data // Must match the receiver structure uint8_t data = 2; unsigned long lastTime = 0; unsigned long timerDelay = 300; // send readings timer // Callback when data is 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() { pinMode(REF_PIN, OUTPUT); // 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) { digitalWrite(REF_PIN, !digitalRead(REF_PIN)); // Send message via ESP-NOW esp_now_send(broadcastAddress, (uint8_t *) &data, sizeof(data)); lastTime = millis(); } }