62 lines
1.6 KiB
C++
Executable File
62 lines
1.6 KiB
C++
Executable File
//extern "C" {
|
|
// #include "user_interface.h"
|
|
//}
|
|
//
|
|
//void setup() {
|
|
// Serial.begin(9600);
|
|
// Serial.println();
|
|
//}
|
|
//
|
|
//void loop() {
|
|
// Serial.println("Go to light sleep, 10 secs");
|
|
// wifi_station_disconnect();
|
|
// wifi_set_opmode(NULL_MODE);
|
|
// wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // LIGHT or MODEM doesn't seem to make a difference
|
|
// wifi_fpm_open();
|
|
// Serial.print("wifi_fpm_get_sleep_type: "); Serial.println(wifi_fpm_get_sleep_type());
|
|
//
|
|
// int resp = wifi_fpm_do_sleep(10000000); // 10 secs
|
|
// Serial.print("wifi_fpm_do_sleep resp: "); Serial.println(resp);
|
|
//// delay(20000); // 20 secs, so should light sleep for just the first 10 secs then go to full power
|
|
////
|
|
//// Serial.println("delay 10 secs..."); // Now delay using full power
|
|
//// delay(10000);
|
|
//}
|
|
|
|
#include <Wire.h>
|
|
#include <ESP8266WiFi.h>
|
|
|
|
const char* ssid = "Livebox-37cc";
|
|
const char* password = "8A6060920A8A86896F770F2C47";
|
|
const int sleepTime = 6; //Power down WiFi for 6 seconds
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
WiFi.begin(ssid, password); //Connect to local Wifi
|
|
|
|
Serial.println();
|
|
Serial.print("Connecting to WiFi");
|
|
while(WiFi.status() != WL_CONNECTED)
|
|
{
|
|
Serial.print(".");
|
|
delay(500);
|
|
}
|
|
Serial.println("WiFi Connected!");
|
|
|
|
//Do your thing.
|
|
|
|
//Time to let the WiFi go to sleep!
|
|
Serial.println("Sleeping...");
|
|
WiFi.disconnect();
|
|
WiFi.mode(WIFI_OFF);
|
|
WiFi.forceSleepBegin(sleepTime * 1000000L); //In uS. Must be same length as your delay
|
|
delay(sleepTime * 1000); //Hang out at 15mA for 6 seconds
|
|
WiFi.mode(WIFI_STA);
|
|
Serial.println("Awake!");
|
|
}
|