Commit 803830f0 authored by Christian Eichler's avatar Christian Eichler
Browse files

sketch_timecube: Reenable esp_wifi_stop() prior to deep sleep

parent 7c086f6f
#include <WiFi.h>
#include <esp_bt.h>
#include <esp_wifi.h>
#include <esp_wpa2.h>
#include <esp_sleep.h>
#include <driver/gpio.h>
......@@ -28,6 +29,8 @@ RTC_DATA_ATTR unsigned deep_sleep = 0;
RTC_DATA_ATTR unsigned sync_counter = 0;
RTC_DATA_ATTR unsigned bug_counter = 0;
RTC_DATA_ATTR bool wifi_active = false;
static_assert(sizeof(time_t) == 4, "time_t Size");
static Accelerometer accel = Accelerometer(ACCEL_CS_PIN);
......@@ -140,6 +143,7 @@ static void wlanSetup(){
// Simple connection
WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
#endif
wifi_active = true;
}
/*! \brief Wait for WLAN connection
......@@ -290,9 +294,15 @@ static bool sync() {
return ret;
}
static void gotoDeepSleep(unsigned long long wakeupTime) {
static void gotoDeepSleep(unsigned long long wakeupTime, bool force = false) {
SDBGF("Preparing for Sleep #%d:\n", ++deep_sleep);
if(wifi_active && !force) {
SDBGLN(" * Powering down WiFi...");
esp_wifi_stop();
wifi_active = false;
}
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
rtc_gpio_isolate(ACCEL_INT_PIN);
......@@ -411,18 +421,16 @@ void setup() {
void resetSystem() {
++bug_counter;
SDBGLN(" -=============-");
SDBGLN(" -===============-");
SDBGLN("-=================-");
SDBGLN("|~~~ BUG ~~~|");
SDBGLN("-=================-");
SDBGLN(" -===============-");
SDBGLN(" -=============-");
SDBGF("[BUG %d] Watchdog triggered; Resetting System\n", bug_counter);
#ifdef SERIAL_DEBUG
Serial.flush();
#endif
gotoDeepSleep(5 * 1000ULL * 1000ULL);
gotoDeepSleep(5 * 1000ULL * 1000ULL, /* force = */ true);
}
void loop() { /* This is never going to be called due to deep sleep. */ }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment