LOG // ARDUINO · DRUPAL
An 8×8 LED Matrix That Reports to Drupal
On my desk there’s a tiny screen made of 64 LEDs. It scrolls the time, the date, and the current weather, and if a significant earthquake happens anywhere in the world it turns red and beeps.
The part I like most is one you can’t see. Every time it checks for earthquakes, it writes a note to a Drupal site. So when it acts strangely, I don’t need to plug in a USB cable and watch the serial monitor. I just open the log.
Here’s how it fits together.
The hardware
Nothing exotic:
- Arduino Uno with an Ethernet Shield (the W5100 kind) for a wired network connection
- WS2812B 8×8 matrix — 64 individually addressable RGB LEDs on one data pin
- A piezo buzzer for audible feedback
- A 3D-printed PETG easel to hold it upright on the desk, which I modeled in CadQuery (Python code that generates CAD models)
An 8×8 grid fits about one and a half characters at a time, so everything scrolls. The Adafruit NeoMatrix and GFX libraries handle the text drawing; the sketch just moves the cursor one pixel left every 150 milliseconds and wraps around at the end of the message.
Problem 1: the Uno has no clock
An Arduino Uno knows how many milliseconds have passed since it powered on. It has no idea what time it is.
So once an hour it asks a time server. It sends a 48-byte NTP request over UDP to pool.ntp.org, reads back the server’s timestamp, and converts it from the NTP epoch (1900) to the Unix epoch (1970). Between checks it simply adds the elapsed millis() to the last known time.
Then comes the annoying part: daylight saving time. There’s no time-zone library doing the work here, so the sketch decides for itself whether US Eastern time is on EDT or EST:
// US Eastern DST: starts 2nd Sunday of March at 2AM EST (7AM UTC),
// ends 1st Sunday of November at 2AM EDT (6AM UTC)
if (month > 3 && month < 11) return true;
if (month < 3 || month > 11) return false;
int dow = dayOfWeek(year, month, 1);
int firstSun = (dow == 0) ? 1 : 8 - dow;
if (month == 3) {
int dstStart = firstSun + 7; // 2nd Sunday
return (day > dstStart) || (day == dstStart && hour >= 7);
}
int dstEnd = firstSun; // 1st Sunday of November
return (day < dstEnd) || (day == dstEnd && hour < 6);
dayOfWeek() is Tomohiko Sakamoto’s algorithm — a well-known one-liner that returns the weekday for any date. With that, the clock switches between UTC−4 and UTC−5 by itself twice a year, and the display shows a 24-hour HH:MM time followed by the month and day.
Problem 2: the Uno can’t do HTTPS
Weather is the easy one. Every 15 minutes the sketch makes a plain HTTP request to OpenWeatherMap, finds the "main" condition (Clear, Clouds, Rain…) and the "temp" value in the response, and scrolls something like 14:05 1-12 | 41F Clouds.
Earthquakes were harder. The earthquake data I wanted is published as GeoJSON over HTTPS, and an Uno with a W5100 shield has nowhere near enough memory to handle TLS.
The fix was to let a server do the heavy lifting. My Drupal site exposes a small earthquake proxy endpoint. Every five minutes the Arduino asks it, over plain HTTP, for “significant earthquakes in the past day”:
GET /api/arduino/earthquake-proxy?mag=significant&period=day
Drupal fetches the real feed over HTTPS and hands back the result. The Arduino doesn’t parse JSON in the usual sense — 2KB of RAM doesn’t allow it. Instead it streams the response and uses client.find() to jump to the first "place" and "mag" values. If it finds them, the text turns red, the buzzer plays two tones, and the matrix scrolls something like M6.1 <location>.
If there’s nothing significant, it stays quiet and keeps showing the time and weather.
The part I’m happiest with: logging to Drupal
Embedded devices are hard to debug once they’re sitting on a shelf. Serial output only helps when a laptop is plugged in.
So the sketch has a small sendLogToDrupal() function. It POSTs a JSON message to a custom endpoint on the same Drupal site:
// Simplified. The real key never goes in a blog post.
client.println(F("POST /api/arduino/log HTTP/1.1"));
client.println(F("Content-Type: application/json"));
client.print(F("X-API-Key: "));
client.println(API_KEY);
// ...
// {"device_id":"weather-matrix-v1","message":"No EQ Msignificant+","level":"info"}
Each message carries three things:
device_id— which gadget is talking (this one isweather-matrix-v1), so more devices can share the same log latermessage— what happened: “Checking EQ”, “EQ: No connect”, “EQ: M5.9 …”level—info,warningorerror, the same severity idea Drupal’s own logging uses
On the Drupal side, the endpoint checks the X-API-Key header, saves the entry, and answers 200 or 201. The sketch waits up to two seconds for that answer and then moves on either way, so a slow server can never freeze the display.
If you’ve built Drupal sites, this will feel familiar: it’s a custom route that accepts a small JSON payload and records it. The only unusual thing is that the “client” is a microcontroller with 2KB of RAM.
Why route everything through my own server
Putting Drupal in the middle sounds like extra work, but it pays off:
- The Arduino stays dumb. All the hard parts — HTTPS, full JSON parsing, storing history — happen on a server that’s good at them.
- I can change behavior without reflashing. If the earthquake source changes, I update the proxy, not the firmware.
- There’s a history. I can see when the device last checked in, when the network dropped, and when it caught a quake.
What I’d tell someone building one
- Use
millis()timers, notdelay(), for anything slow. Time, weather, earthquakes and the display each run on their own interval insideloop(), which keeps the scroll smooth. - Read responses as a stream. On an Uno you can’t hold a whole JSON response in memory.
client.find()and reading character by character into small fixed buffers works. - Give every network call a timeout. Every request here gives up after a few seconds instead of waiting forever.
- Keep secrets out of version control. Put API keys in a separate header file that git ignores, so the sketch can be shared safely.
It’s a small project, but it’s a nice example of something I enjoy: a cheap piece of hardware doing one job well, with a real web backend quietly supporting it.