Skip to content

Instantly share code, notes, and snippets.

@OrganicIrradiation
Created April 19, 2016 18:14
Show Gist options
  • Save OrganicIrradiation/9e4613b9596553bdce941efd0a889c75 to your computer and use it in GitHub Desktop.
Save OrganicIrradiation/9e4613b9596553bdce941efd0a889c75 to your computer and use it in GitHub Desktop.
Simple ESP8266 deepsleep example
#include <ESP8266WiFi.h>
const char* ssid = "#########";
const char* password = "#########";
byte connect_wifi() {
byte timeout = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
if (timeout++ >= 20) {
Serial.println("--> ERROR: Wifi commection timeout");
return 1;
}
}
Serial.println();
return 0;
}
void setup()
{
byte ret_code;
WiFi.persistent(false);
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(2000);
Serial.println();
Serial.print("--> Connecting Wifi");
ret_code = connect_wifi();
if (ret_code == 0) {
Serial.println("--> Connected!");
WiFi.printDiag(Serial);
}
Serial.println("--> Disconnecting");
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
Serial.println("--> Deep sleep");
ESP.deepSleep(60 * 1000 * 1000, WAKE_RF_DEFAULT);
delay(1000);
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment