Is the ESP8266 connected to WiFi & the internet?
If it is then you could use NTP code to get the date/time from the internet every so often to synchronise an internal clock.
@Riva thats not a good solution. What if there will be internet outage at some point.
Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.
surepic: @Riva thats not a good solution. What if there will be internet outage at some point.
Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.
You could use millis() and from time to time synchronize using NTP if you have connection. The question is: Is the time really needed or is it sufficient to trigger that function once a day?
That also depends how exact you need time. If via at command then for every ntp request timezone must be set then request sent to time server then wait for response and parse received ascii data back. So correction of time will be needed by calculating how long is taking response i think its about a second or 2 seconds.
But via rtc its fastest.
surepic: @Riva thats not a good solution. What if there will be internet outage at some point.
Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.
A 'time' program running on the ESP8266 is AFAIK always using millis().
It only gets synchronised with an internet time server when you want it to (code).
That could be once an hour, or once a day, or not at all if internet isn't available.
You need ofcourse to synchronise on bootup, after ESP power loss.
I run some of my ESP (WemosD1 mini) projects with NTP on a powerbank under constant charge,
so I never have a power cut (~36hours on a 5Ah powerbank).
Leo..
Im using at firmare and request to ntp server is being sent every time i ask for time. So dont think its using millis().
Easy check will be disconnect from internet and request time.
Connect to internet get time then switch off your router do same thing agaib you will see that time is going to default 1970year.
Use something like the Time library to supply RTC like time to your sketch. It uses millis() to keep time but it can be periodically synchronized to a real time source like an RTC, NTP, GPS.