Utilizing the ESP8266's capability to retrieve the current time in the form of a Unix timestamp (a long-type number of how many seconds elapsed since the last epoch, i.e. January 1, 1970) from an NTP server, we are able to process the timestamp and output it in a human-readable form on a display screen. As if that wasn't enough, why don't we add a feature where we can view the latest weather information? With custom weather icons, no less?
The design of the WiFi clock is largely inspired by Ubuntu, a Linux distro. The startup screen resembles that of the Ubuntu terminal, with the colour scheme and font to match. A weather API called Dark Sky is used to obtain weather data in the JSON format. As the ESP8266 has limited memory, a streaming parser is used to collect necessary data, instead of storing the entire JSON tree in memory.
In terms of hardware, you will need:
- An ESP8266 module with enough free pins to support a screen output (a NodeMCU Lua ESP-12E WiFi Development Board mounted on a breadboard is used here)
- A display screen hooked up to the ESP8266 module (a 2.4" TFT LCD Touchscreen is used here)
As for software, you will need to install the Arduino IDE on your computer. Once that's done, you will need to install the addon for the ESP8266. A quick guide on installing the addon can be found here.
The libraries used here are third-party libraries you can download from Github. They are:
- Adafruit GFX Library - A graphics library for fonts and shapes.
- Adafruit ILI9341 - Display library for the LCD
- XPT2046 - Touch library for the LCD.
- Json Streaming Parser - A streaming parser to parse JSON data.
- Time - For time-related calculations and functions.
The documentation for the Dark Sky API used in this project can be found here. You will need to create an account and obtain a special API key. This key will be required when sending GET requests.
2023 Update: As of 31 March 2023, the Dark Sky API will be discontinued (thanks, Apple). You may find a drop-in replacement with Pirate Weather, which - despite its unfortunate name - is legal and compatible with the original Dark Sky API format. I will not update the code to use Pirate Weather, but it shouldn't be too hard to get it working with the WiFi clock. Please support Pirate Weather's creator if you can!
- Download or clone this repository into your desired directory. To clone using git, on the command line, type
git clone https://github.com/AugFJTan/ESP8266-WiFiClock
- Place the files in the repository's
Fonts
folder into the actualFonts
folder in theAdafruit_GFX
library folder. - Change the values in the
ESP8266-WiFiClock.ino
sketch where needed. - Compile the sketch and upload it to your ESP8266 module.