Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get a timestamp in Arduino-ESP8266?

I would like to get a timestamp with Arduino-ESP8266.

But I don't have any idea how to get that.

I suppose we have to get the time from the Internet since the ESP8266 doesn't have any clock. Do we need to do that only once or every time we need a timestamp?

I'm already connected by Wi-Fi to the Internet.

like image 748
stallingOne Avatar asked Nov 09 '16 20:11

stallingOne


1 Answers

Looking at that code I don't think this microcontroller directly has a clock built in as mentioned. Since you have Wi-Fi though you could make a web query to get it instead.

I'd use a REST query to a place like this:

https://timezonedb.com/api

Which will give you back a JSON formatted time. If you only need accuracy +/- a few seconds that will be fine. You could lower the bandwidth / improve battery life by setting the time like this and then using an internal timer to calculate an offset instead of making a query every time you need a time stamp. Eventually you would need to requery the time and 'correct' it since your timer on that probably is not accurate for long periods of time, plus it could eventually roll over.

If you need the time more accurately then that you will likely need a clock. You could try to do a bit of correction based on ping, but all in all how accurate it needs to be is based on your project requirements.

like image 175
Chase R Lewis Avatar answered Oct 27 '22 08:10

Chase R Lewis