espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.37k stars 7.37k forks source link

esp_wifi_80211_tx sometimes not working when waking up from esp_light_sleep #3852

Closed ludoplt closed 4 years ago

ludoplt commented 4 years ago

Hardware:

Board: ESP32 WROOM IDE name: Arduino

Description:

I want to use esp_wifi_80211_tx after an esp_light_sleep period. Sometimes, after wakeup, esp_wifi_80211_tx don't want to work... and sometimes it work at the next wake up ! Strange and problematic for my case..

Any idea ?

#include <esp_wifi.h>
#include <esp_bt.h>
#include <esp_deep_sleep.h>
#include <WiFi.h>
#include <esp_spi_flash.h>

wifi_init_config_t wifiInitializationConfig = WIFI_INIT_CONFIG_DEFAULT();

void setup() {
  esp_wifi_init(&wifiInitializationConfig);
  esp_wifi_start();
  esp_wifi_set_promiscuous(true);
  esp_wifi_set_channel(2, WIFI_SECOND_CHAN_NONE);
  btStop();
  esp_bt_controller_disable();
  setCpuFrequencyMhz(80);
}

void loop() {
  esp_wifi_start();
  esp_wifi_set_promiscuous(true);
  esp_wifi_set_channel(2, WIFI_SECOND_CHAN_NONE);

  esp_wifi_80211_tx(WIFI_IF_STA, packet, sizeof(packet), false);
  delay(500);
  esp_sleep_enable_timer_wakeup(500 * 1000);
  esp_light_sleep_start();
}
hpsaturn commented 4 years ago

I have the same behavior with a TTGO-TDisplay board, I was trying to improve consumption in my Air quality device, for this reason I implemented a light suspend for keep the display on into each screen refresh, but after some hours the board go freezing, the only method for turn on it, is with reset button. I don't have any log because the output its fine, don't happened anything before it freezing.

My code:


//! Long time delay, it is recommended to use shallow sleep
void espShallowSleep(int ms) {
    esp_sleep_enable_timer_wakeup(ms * 1000);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
    esp_light_sleep_start();
}

void loop() {
    bmeLoop();                      // the BME680 sensor loop.
    pmsensorLoop(bleIsConnected()); // if phone is connected, the turnon
                                    // sensor interval is minor.
    wifiLoop();                     // check wifi or reconnect it.
    bleLoop();                      // notify data to phone or BLE device
    apiLoop();                      // CanAir.io API publication.
    influxDbLoop();                 // influxDB publication.
    otaLoop();                      // check for firmware updates.
    guiLoop();                      // gui ttf refresh methods.

    // save battery after phone disconnected:
    if (!bleIsConnected()) espShallowSleep(5000); // <== this line reproduce the behaivor 
}

when I comment the last line, the device works fine, many hours without any issue.

Full code here.

stale[bot] commented 4 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.