Tag Archives: ESP8266 clock


Tutorial 8: ESP8266 Internet clock

The National Institute of Standards and Technology (NIST) provides official time in the United States. NIST disseminates the time using several methods, including radio broadcasting over short-wave and long-wave frequencies, telephone dial-in services (ACTS), and Network Time Service (NTS) over the internet. This tutorial describes how to build an ESP8266-based internet clock that uses NIST’s NTS service to retrieve accurate time information. The time is displayed on a colorful TFT LCD (ILI9341 driven) in both analog clock dial and digital formats. The time is synchronized to the NIST server in every 2-minute interval.

ESP8266 Internet Clock

ESP8266 Internet Clock

Hardware

This project uses an ESP8266 module to connect to the NIST time server through a local home/office WiFi. I am using EasyESP-1 board for illustration. The time will be displayed on a 2.2″ ILI9341-driven TFT LCD. Please read Tutorial 7 for more details on how to interface the TFT LCD to EasyESP-1. The hardware setup for this project is same as for Tutorial 7.

Complete setup of LCD on the EasyESP-1 breadboard

Complete setup of LCD on the EasyESP-1 breadboard for Internet Clock

Software

As discussed in Tutorial 7, we will use the same TFT ILI9341 ESP library by Bodmer in this project too. The library comes with some really cool demo examples. This tutorial actually incorporates their TFT_Clock example for displaying time in an analog clock dial format. There are several examples available online showing how to implement Network Time Protocol (NTP) in Arduino to fetch time from NIST server. NIST operates several time servers for its Internet Time Service (ITS). The list of these time servers and their IP addresses can be found here. Note that NIST does not allow queries to any of their servers more frequently than once every 4 seconds. In this project, the queries are made once every two minutes. In between the queries, which is a 2-minute interval, the time is kept running locally using the delay() routine. You can download the complete ESP8266 Firmware for this project from the following link.

Download Internet Clock ILI9341 code

Important notes:

  • The time-fetching code was derived from Kev_MacD‘s instructables on Steampunk ESP8266 Internet connected Clock.
  • In the code, you need to change the network SSID and password to match to your network.
  • In addition, you also need to adjust the GMT offset for your location to get the correct local time. For example, the GMT offset for EST is -5 (int hours_Offset_From_GMT = -5;).
  • The display part of the code uses the TFT ILI9341 ESP library. You can read more about it in Tutorial 7.
  • The time is displayed in 12 hour format on analog dial as well as in 24 hour digital format .
Internet clock

ESP8266 Internet clock

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER
TUTORIAL 6: ESP8266 AND BME280 MAKE A LOCAL/REMOTE WEATHER STATION
TUTORIAL 7: ESP8266 AND ILI9341 TFT LCD

Animated IoT clock that can’t be trusted

An animated IoT clock shared by Tobozo Tagada does not use any RTC module orconnect to a NTP server to retrieve the time. It rather scans the open WiFi access points in its surrounding and extract the date/time from the “Date” HTTP header, if sent out by some. Trust this clock’s accuracy at your own risk. It uses WeMOS ESP8266 board and an OLED screen to display the time along with a pong animation in the background to “cut on the boringness of the clock”, as he said.

Expecting unknown networks to provide a HTTP header value and relying on it to estimate time is like counting on other people’s wealth to survive, hence the Hobo name.

The exclusive use of open access points removes the hassle of hardcoding SSID/password into the sketch but also compensates its lack of auth plus the fact that the optional NTP connexion attempt will always fail, unless the AP acts as.

The Pong animation with a bouncing rotating cube is there to cut on the boringness of the clock but also to demonstrate how this tiny OLED can animate fast (nearly 60fps).

Since it has trust issues, don’t trust this clock more than you would trust a stranger’s watch! The available space and power consumption won’t let it run more than a couple of hours on the LiPo anyway.

Animated IoT clock

Animated IoT clock