Arduino Ide and Wemos lolin32 problems with the light sleep mode
Posted: Mon Jan 13, 2025 5:11 pm
Hello everyone. I have a project on Arduino Ide and Wemos lolin32. And I also have problems with the light sleep mode. Here is my code.
At first everything works fine, then the wifi cannot start after waking up from sleep. After an hour, the memory is full and the code cannot get enough memory to allocate for the buffer. After rebooting, the situation repeats. Here are the error codes that were at first.
After several reboots and several hours of work, the error has changed, now this.
What is this and what are the possible solutions?
Code: Select all
#include <esp_now.h>
#include <WiFi.h>
uint8_t buttonState = 0;
uint8_t Receive_LED_DATA = 0;
bool isRecv = false;
uint8_t broadcastAddress[] = {0x24, 0xD7, 0xEB, 0x88, 0x6B, 0x30};
typedef struct struct_message {
bool state;
} struct_message;
esp_now_peer_info_t peerInfo;
String success;
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void OnDataRecv(const esp_now_recv_info *mac_addr, const uint8_t *data, int data_len) {
char macStr[18];
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
if (data_len > 0) {
Receive_LED_DATA = *data;
}
isRecv = true;
}
void wifiOn() {
WiFi.mode(WIFI_STA);
WiFi.setSleep(WIFI_PS_NONE);
if (esp_now_init() != ESP_OK) {
return;
}
esp_now_register_send_cb(OnDataSent);
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0; // максимум каналов 14, но на всех, кроме 0, не подключается
peerInfo.encrypt = false;
esp_now_add_peer(&peerInfo);
esp_now_register_recv_cb(OnDataRecv);
}
void setup() {
wifiOn();
esp_sleep_enable_timer_wakeup(1000 * 1000);
}
void loop() {
esp_err_t result = esp_now_send(broadcastAddress, &buttonState, sizeof(&buttonState));
if (result == ESP_OK)
Serial.println("Sent with success\t");
else
Serial.println("Error sending the data\t");
buttonState = !buttonState;
WiFi.mode(WIFI_OFF);
esp_light_sleep_start();
wifiOn();
}
Code: Select all
19:10:36.564 -> E (487376) wifi:NAN WiFi stop
19:10:37.595 -> E (487422) wifi:Expected to init 4 rx buffer, actual is 3
19:10:37.595 -> E (487426) wifi_init: Failed to deinit Wi-Fi driver (0x3001)
19:10:37.595 -> E (487426) wifi_init: Failed to deinit Wi-Fi (0x3001)
Code: Select all
20:55:53.352 -> E (571631) wifi:wifi nvs cfg alloc out of memory
20:55:53.352 -> E (571632) wifi:init nvs: failed, ret=101
20:55:53.352 -> E (571635) wifi_init: Failed to deinit Wi-Fi driver (0x3001)
20:55:53.352 -> E (571635) wifi_init: Failed to deinit Wi-Fi (0x3001)