Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Stoney
#16426 I am using this in the arduino build environment and its working fine with the estra wire soldered on (01 module), I get a reboot every minute.

#define SECONDS 1000000
#define SLEEPTIME 60

ESP.deepSleep(SLEEPTIME * SECONDS);

still only dropping to 5mA though, must check my regulator..
User avatar
By willfly
#20546 p1337 - your code is fine except for you must call ESP.deepSleep after the calling client.stop(), or destroying the client object. Also, block the code with a delay statement. Here is my barebone working code for Arduino IDE

Code: Select all// 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);
}
User avatar
By Stoney
#24905 Why can't I get low power wake up options to work ?
Every single method attempted below results in a 61mA wake up..
I am using an unmodded ESP01, just tapping the reset button to wake up, deep sleep is dropping to 340uA or so, most of which is the power LED I would think.
I want to wake the device using a tipping bucket rain gauge pulse, accumulate a bunch of data without connecting to wifi or powering up the unit, then using a fairly high value on the RTC clock to send a packet of info every hour or so.
Last thing I added was the wifi.disconnect thinking that perhaps it is automatically reconnecting ?


Code: Select all
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);
 
}