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());
}
}