กลับไปหน้ารวมไฟล์
sl-real-time-information-4-fc81b8-en.md

Smart Commuting: Real-Time Transit Data on ESP8266

Navigating a massive urban transport network like Stockholm Lokaltrafik (SL) requires up-to-the-minute accuracy. This project utilizes the NodeMCU (ESP8266) to interface directly with the SL REST API, transforming a small microcontroller into a powerful, dedicated transit dashboard that provides real-time departure counts for any bus, train, or tram stop in the city.

The Big Data Challenge: Memory Management

Interfacing a microcontroller with only a few hundred kilobytes of RAM with a modern REST API presents a unique "Big Data" problem.

  • JSON Overhead: A typical transit API response can be tens of thousands of characters long, containing nested objects for every line and stop. This easily exceeds the buffer capacity of a standard Arduino.
  • Stream Parsing with ArduinoJson: This project solves the memory hurdle by using the ArduinoJson library. By parsing the incoming data stream "on the fly" rather than loading the entire document into memory, the NodeMCU can extract specific departure times while ignoring the redundant metadata.
  • Secure Requests: The NodeMCU handles HTTPS (TLS) handshakes to communicate with the SL servers, ensuring the data integrity of the request-response cycle.

API Integration: Platsuppslag and Realtidsinformation

The project architecture relies on two critical SL API modules:

  1. SL Platsuppslag: Used to find the unique "SiteID" for a specific stop name (e.g., "T-Centralen").
  2. SL Realtidsinformation 4: Using the SiteID, the ESP8266 requests the live departures. The data is then filtered for transport type and countdown time.

Future-Proofing and UI

While the current output is designed for the Serial Monitor or a character LCD, the modular nature of the code allows for:

  • E-Paper Integration: Create a low-power "Bus Stop" display that only updates when a change in departure time occurs.
  • LED Indicators: Use NeoPixel strips that change color based on how many minutes remain, providing an "at-a-glance" status for your morning commute.

This project was about interfacing a small RAM microcontroller with the massive REST interface of the SL API, to parse json documents orders of magnitude bigger than the RAM and to make that data easily accessible to the user.

I tried many approaches but settled upon the excellent ArduinoJson library.

The code is easy to remix and use in your own project.

Default output

ข้อมูล Frontmatter ดั้งเดิม

title: "SL Real Time Information 4"
description: "Arduino sketch written for NodeMCU to fetch information from Stockholm Lokaltrafiks API about departures from any given stop."
author: "Nosen"
category: ""
tags:
  - "sl"
  - "bus"
  - "transportation"
views: 1264
likes: 0
price: 1499
difficulty: "Intermediate"
components:
  - "1x NodeMCU ESP8266 Breakout Board"
tools: []
apps:
  - "1x SL Realtidsinformation 4"
  - "1x SL Platsuppslag"
downloadableFiles: []
documentationLinks: []
passwordHash: "39e08cad60337ef3ddccd0cdc78289651ddf2c6453b4f856a1db56ce02ba178c"
encryptedPayload: "U2FsdGVkX19M6RNiAahLRK0mSXdclqZBkzlzHpFQWCvYZgkKh27eTG5NPzWwGOHY4NKbbgWRaILXE5Ub2i6RXf/T2I9LKg7/45TvvaoSdJdkQ6y4jDjdPbffxCQm/DqcTeie0CxE+ocMTKwISJW48g=="
seoDescription: "Arduino sketch for NodeMCU to fetch real-time departure info from Stockholm Lokaltrafiks API."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/sl-real-time-information-4-fc81b8_cover.jpg"
lang: "en"