examples/MQTT Subscriber Example/README.md
This project subscribes to Helsinki Regional Transport's (HSL) public MQTT feed and visualizes the live position of a single vehicle (bus, tram, or commuter train) in Serial Studio. Around 1,500 vehicles publish position updates roughly once per second, so the JS parser filters the stream down to one target vehicle and converts each VP payload into a dashboard row.
Live, real-world telemetry with no extra hardware. You only need Serial Studio and an internet connection.
HSL exposes its high-frequency positioning feed at mqtt.hsl.fi:1883 under the HFP v2 specification. Anonymous access is allowed; the project connects without credentials.
| Setting | Value |
|---|---|
| Host | mqtt.hsl.fi |
| Port | 1883 |
| Username | (empty) |
| Password | (empty) |
| Topic filter | /hfp/v2/journey/ongoing/vp/# |
| Mode | Subscriber |
Each MQTT message wraps a Vehicle Position object under the VP key:
{
"VP": {
"veh": "6314",
"desi": "550",
"dir": "1",
"lat": 60.21472,
"long": 24.93021,
"spd": 12.4,
"hdg": 188,
"tst": "2026-05-15T07:31:42.000Z"
}
}
The MQTT driver delivers a byte stream, not pre-split JSON objects. The parser keeps an internal buffer, locates { ... } boundaries while respecting string escapes and nested braces, and emits one dashboard row per complete VP message. A TARGET_VEHICLE constant filters the firehose down to a single vehicle:
const TARGET_VEHICLE = "6314";
Change this string to track a different bus, tram, or train. The vehicle ID format is NNNN where the first digit roughly corresponds to the operator (HSL's published Vehicle Identifiers documentation has the full mapping).
The speed dataset additionally carries a per-dataset transform that converts the native m/s reading to km/h:
function transform(value) {
const speedKmh = (value || 0) * 3.6;
return Math.round(speedKmh * 10) / 10;
}
HSL Helsinki Public Transit.ssproj.After the first matching message arrives (a second or two while the broker pushes the next position update for your target vehicle), the dashboard opens with the map zoomed to the vehicle's current location.
HSL Helsinki Public Transit.ssproj: Serial Studio project file (pre-configured).README.md: project documentation.doc/screenshot.png: visualization screenshot.clientId; if two machines run the same project at once, give one of them a different ID.