Close

Switching from WebSocket to MQTT for Reliable Frequency Streaming

A project log for Electric time

Vintage pressure gauge hacked into a frequency meter, sensing the 50 Hz electrical grid tremors; time wavers, bends, and fades away.

dtournerDétourner 11/05/2025 at 14:070 Comments

The first implementation of The Electric Time used a WebSocket connection between the Raspberry Pi and the display device to stream the measured mains frequency in real time.

While this worked fine for short sessions, I started to experience unstable communication after several hours  / days of uptime: dropped connections, frozen values, and occasional buffering delays.

WebSockets are great for browser-based communication, but in this project the Raspberry Pi acts more like a data source, and the display device (an ESP32) behaves like an IoT client.
That’s why I decided to migrate the data exchange to MQTT, which is far better suited for this kind of setup.

Architecture Overview

This new setup offers several advantages:

Discussions