Cloud & Infrastructure

ESP32 Spotify Display with Cloudflare Workers

What if your desk gadget and website widget could share Spotify data without doubling API calls or risking leaked secrets? Ateljé Vagabond's ESP32 setup does just that, powered by a single Cloudflare Worker.

Diagram of ESP32 Spotify display architecture with Cloudflare Worker connecting to Spotify API and serving IoT device and web widget

Key Takeaways

  • Single Cloudflare Worker centralizes Spotify API handling, eliminating credential risks and rate limit issues for multiple clients.
  • Custom zero-heap JSON parser and streaming pixel display make ESP32 viable for large album art without crashes.
  • Undocumented display flags highlight embedded dev pains; OTA and task mutexes add production polish.

Why trust a microcontroller with your Spotify password?

That’s the question no one’s asking — until their ESP32 brick turns into a security headache. Ateljé Vagabond, a studio crafting compact systems, sidestepped this trap with a 1.83-inch ESP32 display showing real-time Spotify playback. But the magic? A lone Cloudflare Worker that juggles OAuth, token refreshes, image crunching, and serves both the desk gadget and a live website widget. No duplicated API hits. No credentials baked into firmware. Just one edge-deployed brain handling it all.

This isn’t some hobbyist hack. It’s a blueprint for IoT that scales — or at least doesn’t crumble under rate limits.

How Does the Cloudflare Worker Pull This Off?

Picture this: Spotify’s API demands OAuth tokens refreshing hourly. Dump that logic on an ESP32? You’re begging for memory crashes, TLS nightmares, and anyone with a flash reader owning your account. Ateljé’s fix — a Worker at iot.ateljevagabond.se — owns the Spotify dance.

It fetches /currently-playing once per cycle, regardless of clients. Browsers get clean JSON with cover URLs. The ESP32? Same JSON, plus album art pre-converted to RGB565, run-length encoded, and base64-wrapped for safe transit. Cloudflare’s KV cache holds covers for 7 days. Edge caching skips Worker spins on repeats. Rate limits? Laughable now.

“The Spotify API is called once per polling cycle — one token refresh, one currently-playing fetch — regardless of how many clients are connected.”

That’s from their breakdown. Spot on. Duels over API quotas vanish.

Hardware’s a DFRobot FireBeetle ESP32 wired to a Waveshare 1.83-inch ST7789 IPS panel — 240x280 pixels over SPI. Sounds simple. Took trial-and-error hell to tune.

Why Was the Display Such a Pain?

Three undocumented PlatformIO flags saved the day — or the project.

TFT_OFFSET_Y=20 fixes the ST7789’s oversized 240x320 buffer; this panel crops to 280 lines from row 20. Miss it, images shift up, clip tops. TFT_RGB_ORDER=TFT_BGR swaps red-blue channels — otherwise reds go blue, blues red. TFT_INVERSION_ON kills the gray washout.

Datasheets? Useless. Forums and flashes got ‘em through. Classic embedded drudgery.

ESP32 heap’s tight — 115KB RGB565 art won’t fit reliably. Solution: stream in 512-byte chunks. FreeRTOS splits tasks: one polls metadata every 3 seconds, the other pipes pixels to display mid-download. A tftMutex locks SPI access; watchdog resets if it jams. Album art scrolls top-to-bottom as it loads. Serendipitous polish.

JSON’s bloated with encoded pixels. Standard parsers risk heap fragmentation. They built a zero-heap state machine — char-by-char parsing on the fly. No allocations. No crashes.

Is This Architecture Actually Scalable for Real IoT?

Here’s my take: yes, but with a historical nod to the Minitel debacle. France’s 1980s network centralized smart terminals via dumb glass teletypewriters — one backend, infinite edge devices. Ateljé echoes that: Worker as Minitel server, ESP32 as terminal. Secure. Efficient. No client bloat.

But skepticism creeps in. Cloudflare lock-in? If their edge hiccups, your desk goes dark. Spotify tweaks APIs? One Worker rewrite fixes all — dual clients would’ve been chaos. Still, for a studio desk toy doubling as web bling, it’s overengineered genius.

Corporate hype? Nah, this is indie engineering porn. No PR spin. Just code that works.

OTA updates seal it — pipeline pushes firmware sans cables. Polished.

Look, most IoT Spotify clocks poll APIs raw, leak secrets, eat quotas. This? Centralized brains win. Prediction: expect copycats in maker forums by Q1 2025, tweaking for Home Assistant or Sonos dashboards. Cloudflare’s free tier makes it dead simple.

And the streaming art? That’s the flex. Feels alive, not static.

Why Does the ESP32 Spotify Display Matter for Makers?

Market dynamics scream yes. ESP32 shipments hit 10 million quarterly last year, per Esonet data. IoT’s exploding — but security sucks. Firmware creds are ransomware bait. This Worker proxy? Drops exposure to zero, scales clients free.

Skeptical angle: it’s niche. Spotify-only. But swap APIs — tweak for Last.fm, YouTube Music — and you’ve got a template. Cloudflare pages boot in seconds; KV’s dirt cheap.

One quirk irks: mTLS for device auth, origin checks for web. Solid. But why not Workers Auth? Overkill for two clients, maybe.

Still, for devs eyeing physical-digital bridges, this crushes. No more “works on my bench” fragility.

Unique insight: Echoes AWS IoT’s shadow sync from 2015 — desired vs. reported state. Here, Worker as shadow: canonical Spotify truth, radiated out. Ateljé didn’t name it, but that’s the parallel. Smarter than they let on.


🧬 Related Insights

Frequently Asked Questions

What hardware do I need for an ESP32 Spotify display?

DFRobot FireBeetle ESP32 plus Waveshare 1.83-inch ST7789 LCD. SPI hookup, those three PlatformIO flags mandatory.

How does Cloudflare Worker handle Spotify OAuth securely?

Stores creds server-side, refreshes tokens hourly, serves preprocessed data to clients. No firmware exposure.

Can I adapt this for my own music service?

Absolutely — swap Spotify API calls in the Worker. Caching and conversion logic ports easy.

Priya Sundaram
Written by

Hardware and infrastructure reporter. Tracks GPU wars, chip design, and the compute economy.

Frequently asked questions

What hardware do I need for an ESP32 Spotify display?
DFRobot FireBeetle ESP32 plus Waveshare 1.83-inch ST7789 LCD. SPI hookup, those three PlatformIO flags mandatory.
How does Cloudflare Worker handle Spotify OAuth securely?
Stores creds server-side, refreshes tokens hourly, serves preprocessed data to clients. No firmware exposure.
Can I adapt this for my own music service?
Absolutely — swap Spotify API calls in the Worker. Caching and conversion logic ports easy.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from DevTools Feed, delivered once a week.