Very Simple MicroPython ESP8266/ESP-12 Web Clock

A tutorial of building a web clock with only an ESP8266/ESP-12 board and an SSD1306 OLED display by using built-in modules of MicroPython.

This tutorial project is to create a very simple web clock on ESP8266/ESP-12 boards, by using only built-in modules (libraries) of MicroPython.

In short, the project does the following things:

Connect to a WiFi router;
HTTP GET and parse web JSON data every minute, then update the internal RTC (real time clock) module; (this is to avoid DDoS-like query to the server. However since the software RTCs are incredibly inaccurate, we still have to update it within a minute or an hour, depends the board you are using.)
Display internal RTC date and time on SSD1306 OLED display.
If the board lose WiFi connection it would reboot itself.
All the functions above can be achieved without importing any third party libraries. Neat!

Change the value of the variable ssid to the name of your local WiFi router, and pw as your Wifi router password. (Do not share your passwords online.)

The variable url is where we get JSON data. We are using World Time API. You can change it to any other city or timezone. You’ll get something like:




Then we extract item “datetime” and get all the info we need.

The SSD1306 OLED display is connected to the board via I2C pins (D1/GPIO5 = SCL, D2/GPIO4 = SDA). Most of the OLED models can be powered by either 5V or 3.3V.

If you don’t have or don’t want to use OLED, you can replace related codes as print() to output data directly to REPL. Without a connected OLED display the OLED module would time out and halt the code.”


Related Content