Wemos WiFi and Fun With Clocks

I’m Dr Sheldon Cooper and welcome to another exciting episode of Fun With Flags. We, humor aside, trying to get an accurate time on a micro can be done a multitude of ways and I have given them all a crack this time around and will use 2 out of 3 in my latest project.

So being WiFi enabled, i can call the time of an NTP time server, get the Unix time, do some math wizardry to make the time usable and bing bang boom you have the time. Trouble is, i was getting a number of failed packets and this is of course bad and was making my time keeping go off. Even if i was detecting fail packets and polling again for a new packet, it could wreck my other data and put things off. So, it had to go.

Of course you can call the millis function and do your own time, and I do this for some of the other non critical timing functions, like do this every 5 minutes or do this every 10 minutes, where if the clock drifts by a few seconds its not all that critical. I did make a functioning clock this way and I was getting about 2 seconds drift per day, easy enough to correct for but the code was ugly and you had to reset the time and date everytime i rebooted, and for testing it was a pain in the arse.

So i busted out a real time clock and connected her up and of course this is always going to be a superior option and the one i should have went straight for rather than stuffing about for a couple of nights giving each of the other guys a crack. Oh well, I learned a whole lot in the process and now she is a choocker. Oh and BTW, there are a number of different RTC modules on the market, one works off the SPI bus and the other off the I2C bus, well I have both and I never really liked the SPI RCT Clocks, and much prefer the I2C clocks like the DS3231. The SPI clocks I have seem to forget the time, or some random pulse resets the time. Do not know what is the cause, but I ended up ordering more I2C clocks and binning the others.

Facebooktwitterredditpinterestlinkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.