ESP_NOW broadcasts stop working after light sleep

hdsjulian2
Posts: 15
Joined: Wed Apr 10, 2024 8:08 am

ESP_NOW broadcasts stop working after light sleep

Postby hdsjulian2 » Thu Jul 18, 2024 11:22 pm

This is the code that runs before and after light sleep:

```

WiFi.disconnect();
WiFi.mode(WIFI_OFF);
esp_now_deinit();
esp_sleep_enable_timer_wakeup(sleepTime);
esp_light_sleep_start();
WiFi.mode(WIFI_STA);
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_register_recv_cb(OnDataRecv);
esp_now_register_send_cb(OnDataSent);
```

and while i can receive directed messages, receiving Broadcasts stops working?
I'm using an esp32 S3, arduino as framework and i'm including

```
#include "Arduino.h"
#include "esp_now.h"
#include "WiFi.h"
```

What could I be doing wrong?

hdsjulian2
Posts: 15
Joined: Wed Apr 10, 2024 8:08 am

Re: ESP_NOW broadcasts stop working after light sleep

Postby hdsjulian2 » Thu Jul 18, 2024 11:54 pm

Edit: i think this fixes it. when i deinitialize esp_now i also have to add the broadcastaddress back to the peer list.

memcpy(&peerInfo.peer_addr, messageHandler.broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}

Who is online

Users browsing this forum: No registered users and 7 guests