#define SECONDS 1000000
#define SLEEPTIME 60
ESP.deepSleep(SLEEPTIME * SECONDS);
still only dropping to 5mA though, must check my regulator..
Explore... Chat... Share...
Moderator: igrr
// GPIO16 is connected to Reset pin
#include <ESP8266WiFi.h>
#define LED_BUILTIN 1 // high turns it off
#define LED 5
#define LED_ON digitalWrite(LED, 0)
#define LED_OFF digitalWrite(LED, 1)
const char* ssid = "WifiSSID";
const char* password = "wifiPassword";
// ------------------------
void setup() {
// ------------------------
Serial.begin(115200);
Serial.println();
Serial.print("** STARTED at: ");Serial.println(millis());
// prepare GPIO direction
pinMode(LED, OUTPUT);
blink();
Serial.print("current wifi: "); Serial.println(WiFi.SSID());
Serial.println("*** Connecting to wifi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
}
Serial.print("Wifi established in: ");Serial.println(millis());
Serial.print("IP address: ");Serial.println(WiFi.localIP());
blink();
blink();
blink();
sendData();
}
// ------------------------
void loop() {
// ------------------------
Serial.println("this is never executed");
}
// ------------------------
void sendData() {
// ------------------------
Serial.println("connecting to host:port...");
// Use WiFiClient class to create TCP connections
WiFiClient client;
while( !client.connect("host", 9090) ) {
Serial.println("connection failed!, retrying...");
delay(10);
}
delay(10);
Serial.print("Connected at: ");Serial.println(millis());
Serial.println("Posting data...");
client.print("Hello message from ESP\r\n\r\n");
client.flush();
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection, sleeping");
Serial.print("Finished at: ");Serial.println(millis());
delay(100);
// **** IMP stop or destroy client before going to sleep or else wdt will wake it up
client.stop();
delay(100);
// enter deep sleep
ESP.deepSleep(20 * 1000 * 1000, WAKE_RF_DEFAULT);
delay(1000);
}
// ------------------------
void blink() {
// ------------------------
LED_ON;
delay(100);
LED_OFF;
delay(100);
}
extern "C" {
#include "user_interface.h"
uint16 readvdd33(void);
bool wifi_set_sleep_type(enum sleep_type type);
enum sleep_type wifi_get_sleep_type(void);
}
#define SLEEPTIME 60
#define SECONDS 1000000
#include <ESP8266WiFi.h>
const char* ssid = "TP-LINK_2.4GHz_******";
const char* password = "abcdefgh";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Booting");
delay(1000);
// We start by connecting to a WiFi network
// Serial.print("Connecting to ");
// Serial.println(ssid);
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) delay(500);
// WiFi.mode(WIFI_STA);
// Serial.println("WiFi connected");
// Serial.println("IP address: ");
// Serial.println(WiFi.localIP());
WiFi.disconnect();
// client.stop();
}
void loop() {
delay(5000);
//method 1 .. everything is 60mA at wake up..
// ESP.deepSleep(SLEEPTIME * SECONDS, WAKE_RF_DEFAULT);
// ESP.deepSleep(SLEEPTIME * SECONDS, WAKE_RFCAL);
// ESP.deepSleep(SLEEPTIME * SECONDS, WAKE_NO_RFCAL);
// ESP.deepSleep(SLEEPTIME * SECONDS, WAKE_RF_DISABLED);
// ESP.deepSleep(SLEEPTIME * SECONDS);
//method 2 .. everything is 60mA at wake up..
// wifi_set_sleep_type(NONE_SLEEP_T); //displays sleep type 0, wakes at 62.4mA
//wifi_set_sleep_type(LIGHT_SLEEP_T); //displays sleep type 1, wakes at 62.4mA
wifi_set_sleep_type(MODEM_SLEEP_T); //displays sleep type 2, wakes at 62.4mA
system_deep_sleep_set_option(4); // 0 rfcal depends on 108,1 rfcal ,2 no rfcal ,4 rf disabled
Serial.print("wifi Sleep type = ");
Serial.println(wifi_get_sleep_type());
system_deep_sleep(0); // time in uS or 0 for never wake
delay(1000);
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]