-->
Page 1 of 2

How to run a clock on ESP8266?

PostPosted: Thu Jun 18, 2015 8:16 am
by Atlantis
I need quite accurate time on my projects utilizing ESP8266.
It is quite easy to get a current time by SNTP API, already present in SDK.
But what to do next? How to increment variable storing time every second, to be sure it is precise?
How precise is software timer (os_timer_t)? Can I just set it to perform time_var++ every 1000 milliseconds, or do I need something better? I do not want synchronize time every 10 minutes...
Maybe there is a better way? Can I use system_get_rtc_time() somehow to increment standard Unix timestamp?

Re: How to run a clock on ESP8266?

PostPosted: Thu Jun 18, 2015 11:59 am
by scargill
Grab the time library from Arduino and pinch the central core of it. So I update the time from the web every 24 hours - and in a 1 second callback I maintain it - works a treat. I've not yet used the NTP library - I get my time from a Raspberry Pi running MQTT - but same general idea.

Re: How to run a clock on ESP8266?

PostPosted: Fri Jun 19, 2015 1:59 am
by Atlantis
Grab the time library from Arduino and pinch the central core of it.


For now, I do not need human readable data format. Unix timestamp will be fine. I need it for marking time of measurements from sensors, before sending them to the server.

So I update the time from the web every 24 hours - and in a 1 second callback I maintain it - works a treat. I've not yet used the NTP library - I get my time from a Raspberry Pi running MQTT - but same general idea.


You mean os_timer_t?
Is it precise enough to not adrift from correct value in 24h?
Can software timer be distorter, if delay function is used in different section of code? Or it just runs by itself, as a separate "thread"?

Re: How to run a clock on ESP8266?

PostPosted: Fri Jun 19, 2015 3:27 am
by scargill
Depends what you call drift - I haven't checked but I'd be surprised if it is more than a second out..