Chat freely about anything...

User avatar
By sp500
#84343 Hi,
I am using arduino ide to put my nodemcu 1.0 to deepsleep, but the board does not wake up if it sleeps for more than 30 minutes. Is that the limit or am I doing something wrong?
Thanks.

Here's my wiring:
RST--> D0


Code:

#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const int wakeUpTime = 23*3600+0*60+0;
int aft= 7*3600+0*60+0;
const char *ssid = "******";
const char *password = "*******";

const long utcOffsetInSeconds = -14400;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "north-america.pool.ntp.org", utcOffsetInSeconds);

int Led_OnBoard = 2; // Initialize the Led_OnBoard
int button = 5; // Initialize Push button



void setup(){


// put your setup code here, to run once:
delay(1000);


Serial.begin(115200);

// Wait for serial to initialize.
while(!Serial) { }


WiFi.mode(WIFI_OFF); // Prevents reconnection issue (taking too long to connect)
delay(1000);
WiFi.mode(WIFI_STA); // This line hides the viewing of ESP as wifi hotspot


WiFi.begin(ssid, password);

while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}

timeClient.begin();
}




void loop() {
delay(2000);
timeClient.update();

ESP.deepSleep(timeDif()*1000000);

delay(1000);
}






//Get Current Time in Seconds
int currentTimeSec(){
int h=timeClient.getHours();
int m=timeClient.getMinutes();
int s=timeClient.getSeconds();
int totalS=h*3600+m*60+s;
return totalS;
}
//Find the total sleep time
int timeDif(){
//int act=convSec(22,15,0);
if(currentSec()< morn){
Serial.print("A");
return (wakeUpTime-currentTimeSec());
}

}
User avatar
By QuickFix
#84346 According to our own Marcel Stör, the max time you can deep sleep an ESP8266 should be around 3.5 hours (Arduino core 2.4.1 and higher) or 71 minutes (core up to 2.4.1).

There are ways to "Extend" this of course, by briefly waking up every hour or so, incrementing your own counter in non volatile memory until a set value is reached and going back to sleep again or by using an external RTC with alarm-function (which is also more precise than the internal ESP RTC).
User avatar
By marcelstoer
#84364 Please put the code in code blocks to make it more legible. Before ESP.deepSleep(timeDif()*1000000); can you print timeDif()*1000000 to console and verify it's what you expect?