Skip to content

Instantly share code, notes, and snippets.

@jindrichsirucek
Last active January 23, 2018 08:54
Show Gist options
  • Save jindrichsirucek/5e6d7208d323e35231f8291810fa53f1 to your computer and use it in GitHub Desktop.
Save jindrichsirucek/5e6d7208d323e35231f8291810fa53f1 to your computer and use it in GitHub Desktop.
100% working example. It saves battery life greatly, but ESP can still operate (except wifi)..
extern "C" {
#include "user_interface.h"
}
void turnWifiOn()
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(E("WiFi Radio: Turning ON"));
wifi_fpm_do_wakeup();
wifi_fpm_close();
wifi_set_opmode(STATION_MODE);
wifi_station_connect();
yield();
}
#define FPM_SLEEP_MAX_TIME 0xFFFFFFF
void turnWifiOff()
{
if(MAIN_DEBUG) DEBUG_OUTPUT.println(E("Diconnecting client and wifi"));
// client.disconnect();
wifi_station_disconnect();
wifi_set_opmode(NULL_MODE);
wifi_set_sleep_type(MODEM_SLEEP_T);
wifi_fpm_open();
wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
yield();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment