Hi I’m trying to implement ESP-NOW on 2 ESP8266 devices, I can send the data to turn on a led connected to (D1 in the receiver) but when I turn off the transmitter the receiver’s led is always on. How can I implement a watchdog ? example, if the data is not received, restart the system after a certain number of seconds.
Thank you
RECEIVER CODE :
#define D1 5
#include <ESP8266WiFi.h>
#include <espnow.h>
#include <SimpleTimer.h>
SimpleTimer timer;
int WatchdogLed = 0 ;
int count = 0;
typedef struct struct_message {
int WatchdogLed ;
}
struct_message;
// Create a struct_message called myData
struct_message myData;
void onDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
Serial.println("Messaggio ricevuto.");
memcpy(&myData, incomingData, sizeof(myData));
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != 0) {
Serial.println("Problem during ESP-NOW init");
return;
}
esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(onDataRecv);
digitalWrite (D1, LOW);
pinMode(D1, OUTPUT);
timer.setInterval(1000L, myTimerEvent);
}
void myTimerEvent() {
digitalWrite (D1, myData.WatchdogLed);
}
void loop() {
timer.run ();
}