EpochClock
Sometimes I have to go into log monkey mode; Incident response, building custom alerts, parsing event dumps, and threat hunting all require the ability to relate in universal time. Instead of just pulling up another tiny browser window with the times I need, I decided to build a small wall clock which could give me the current UTC and Linux Epoch. Its pencil time.
I scavenged around in my parts bin and found a couple HD44780 modules with i2c adapters that I could build around. My first idea was to use a Raspi Zero, but there were heat issues due to everything being sealed inside of an enclosure (and im too lazy to add vents and a fan). I went with a Weimo D1/8266 dev board instead. Super low cost and very simple. Now that I know all the primary dimensions for the parts it was time to whip up a basic case in Fusion360.
I added a little hole in the case to pass a usb cable through. I skipped the 18650 holder, KISS.
The case printed in about 3hr50min on my Ender3. The case is simple enough that I am planning on making a platinum cure silicone mold of the case front and casting a few sparkly resin parts; but thats a future project. Got the 8266 soldered to the LCD i2c bus and 5vdc rail using the following super simple pinout:
8266 — — — — LCD
==========
5VDC_________VCC
GND_________GND
D1___________SDA
D2___________SCL
Power up testing ran clean and I found the i2c address for the LCD with a little address scanner sketch (0x3F). I had to tune the contrast pot on the back of the LCD, but no i2c level shifters (3.3vdc to 5vdc) were required whatsoever. Time to slap together some absolutely terrible code…
#include <LiquidCrystal_I2C.h>
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>const char *ssid = "lolYeahRight";
const char *password = "D0ntExposeYourCreds!";
int lcdColumns = 16;
int lcdRows = 2;
WiFiUDP ntpUDP;IPAddress local_IP(10, 0, 0, 200);
IPAddress gateway(10, 0, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(8, 8, 8, 8);LiquidCrystal_I2C lcd(0x3F, lcdColumns, lcdRows);
NTPClient timeClient(ntpUDP, "time-e-g.nist.gov", 0, 0);void setup()
{
lcd.begin(5, 4);// initialize LCD
lcd.init();
lcd.backlight();
Serial.begin(115200);
Serial.println();
Serial.println(WiFi.macAddress());
WiFi.config(local_IP, gateway, subnet, dns);
WiFi.begin(ssid, password);while ( WiFi.status() != WL_CONNECTED ) {
delay (500);
Serial.println(WiFi.status());
Serial.println(".");
lcd.setCursor(0, 0);
lcd.print("Connecting...");
lcd.setCursor(0, 1);
lcd.print(" @mntlbrdn");
}
timeClient.begin();
timeClient.update();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NTP SERVER:");
lcd.setCursor(0, 1);
lcd.print("TIME.NIST.GOV");
delay(4000);
lcd.clear();
}void loop()
{
Serial.println(timeClient.getFormattedTime());
lcd.setCursor(0, 0);
lcd.print(" " + timeClient.getFormattedTime() + " ");
lcd.setCursor(0,1);
lcd.print(" " + String(timeClient.getEpochTime()));
delay(1000);
}
This was a fun weekend project and I saved a little money in the long run. A comparable wall clock would have cost me around $40USD, but I was able to build the EpochClock for less than $16USD. The LCD looks great in person and I can read it from across the room.
I started this project on June 17th at 4PM and finished on June 19th at 2PM, 46hours from an idea and sketch to a completed product. I had a lot of fun building this project and it was another good example of rapid prototyping skills.