I've created an sketch to make an automatic clock on an ESP8266 that gets

I’ve created an sketch to make an automatic clock on an ESP8266 that gets UTC time, finds your geo location, adds the timezone offset and displays it on whatever you like - LED, OLED, etc.

This one is on a 24-led ring using FastLED:

https://github.com/myk3y/RingClock

It’s my first ‘real’ program that wasn’t all hacking someone else’s code and as I know I’m about as good at programming as I am at prostate surgery, feel free to critique.

The first version was built using a tiny OLED screen to check out that it was all working: https://github.com/myk3y/AutoClock

Thanks @Mike_Thornbury , just what I needed for my hot water controller. I’ve struggled to get it to sync with daylight saving times. This looks like it’ll solve the problem :))

Now thats a great hack. Let me know how you get on.

Learn something new every day. I have always hardcoded my timezone data and DST offsets. This should fix it quick. I appreciate it even if you didn’t mean it.

Didn’t mean what? That it copes with DST?

That’s exactly the reason for the sketch, to have the correct time - all the time :slight_smile:

Where I live there is no daylight or winter time adjustment - there is no winter and the days and nights are 12 hours, ~15 minutes, all year round, but I designed it to work anywhere in the world.

It may not work if you use a VPN to connect, as the IP address it gets will be that of the VPN end point, not your local ISP connection.

I am interested as I also played a bit with 60 led ring, esp8266, and oled screen to make clocks. Turned out, I don’t like a way hours and minutes are displayed, as it’s hard to remember which color is minutes and which color is hours. Looking into your project, I just got an idea to use two rings – the bigger one for minutes (and maybe seconds – I did some cool effects for it), and the smaller one for hours. This way, it will be the same as wall clock, smaller hand for hours, bigger hand for minutes. Maybe I need to buy another pixel ring )

The other thing is, I look at the RingClock code and can’t understand how it can even be compiled. Perhaps you have committed some wrong version, or it’s too late for me to read the code. In particular, the line

time_t getNTPTime();

seems odd. Also, you don’t call it from inside the loop, it seems the time is only synced once, upon booting (in setup). Finally, maybe it makes sense to add a delay() as you’re constantly updating the ring, probably thousands times a second.

@Kirill_Kolyshkin the NTP function defines the refresh time - in this case the default using 60 seconds, but I have my clock currently set to ten minutes (600 seconds).line 22: NTPClient ntpClient(ntpUDP, “http://time.google.com”); // initialist NTP client with server name

I will add the missing defaults and update the code to indicate, thanks for pointing that out.
And yes, I should put a delay in to allow the ESP to handle housekeeping, but it’s not an interactive device, so I didn’t really need to allow for any client activity like a web server, etc.

The issue was in deciding what delay to use, so I didn’t use one.

As some background, this is my first program - I’m not a programmer, but am learning C++. I’m an engineer by trade. Finding my way slowly… :slight_smile:

Glad you found it useful.

Initially I just wanted to learn how to parse using json, this grew from that as I had a 24-led ring sitting on my workbench and my wife’s clock was driving me crazy.

As to hands, the hour hand in my clock uses two LEDs, so no getting confused.

It’s been running over a week and is keeping perfect time. I intend on running a monitor to see how often and how much web traffic it generates, but we’re in the process of moving to a new town and all my stuff apart from one computer is boxed up.