void sleep()
{
Serial.println("Sleep");
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
gpio_pin_wakeup_enable(GPIO_ID_PIN(VIB_PIN), GPIO_PIN_INTR_LOLEVEL);
wifi_fpm_do_sleep(0xFFFFFFF);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.println("Startup");
pinMode(VIB_PIN, OUTPUT);
sleep();
}
void loop() {
if(digitalRead(VIB_PIN) != HIGH)
{
int n = WiFi.scanNetworks();
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
}
}
}
Running in sleep mode or in non-sleep mode is exactly the same amount of power not sure why.
Thanks!