← All case studies
Personal project · open source · 2025 – present

MIA: vehicle telemetry and IoT control from phone to microcontroller

MIA connects an Android app, a Raspberry Pi, ESP32 and Arduino boards and a car's diagnostic port into one system an AI agent can drive through Model Context Protocol tools. The prototype car is a 2004 Audi A4 Cabriolet (8H). This page covers the architecture, the decisions that keep it testable without the car, and the safety rules for touching a real vehicle.

4
runtimes: Android, Raspberry Pi, ESP32 and Arduino
~300
commits since August 2025
850+
Python test functions, plus Android unit and instrumented tests
7
GitHub Actions workflows, triggered per platform

The problem

A car, a Raspberry Pi, a couple of microcontrollers and a phone all speak different languages: CAN and OBD-II, USB serial, GPIO, Wi-Fi and HTTP. Getting them to cooperate usually means brittle point-to-point scripts that only run when every device is plugged in.

The goal for MIA was one message bus and one schema across all of them, code that runs identically with or without hardware attached, and a tool surface an AI agent can use — without ever giving that agent a way to actuate anything safety-relevant in the car.

Architecture

Five layers, one monorepo. The Pi is the hub: HTTP and WebSocket at the edge, ZeroMQ inside.

Android companion
Kotlin · Jetpack Compose · Hilt · Room

Voice commands, live telemetry over WebSocket, mDNS discovery of the Pi, and a camera screen for number-plate recognition.

Raspberry Pi backend
Python · FastAPI · ZeroMQ

REST and WebSocket gateway on port 8000 in front of a ZeroMQ ROUTER broker (5555) and a PUB/SUB telemetry bus (5556). Workers for GPIO, serial, OBD and vehicle bridges run as systemd services.

C++ voice and orchestration core
C++17 · FlatBuffers · MQTT · CMake / Conan

TCP and MQTT servers over a job and message queue, speech-to-text and text-to-speech workers driven by a voice-control state machine, a hardware-control server, and FlatBuffers codecs shared with the Python side.

Microcontrollers
ESP32 (ESP-IDF / PlatformIO) · Arduino

Sensor and potentiometer telemetry over USB serial, a Wi-Fi bridge, OBD-II framing on the ESP32, an LED-strip controller and an ESP32 camera for plate capture.

MCP modules
Python · Model Context Protocol

Core orchestrator, service discovery, AI audio assistant (speech-to-text, text-to-speech), hardware bridge and vehicle bridges, exposed as tools an agent can call.

An OBD-II digital twin

To develop against diagnostics without a running engine, physical potentiometers drive an ELM327 emulator. Off-the-shelf diagnostic apps connect to it exactly as they would to a car and see the numbers move as the knobs turn.

  1. 01 Potentiometers on an MCU Physical knobs stand in for throttle and road speed
  2. 02 Serial bridge USB serial JSON → ZeroMQ PUB on mcu/telemetry
  3. 03 OBD worker Maps ADC 0–1023 to RPM, speed and coolant, thread-safe car state
  4. 04 ELM327 emulator Answers PIDs from the live state on a virtual serial port
  5. 05 Real diagnostic apps Torque, OBD Eleven or VCDS connect as if to a car

Design decisions

A broker, not point-to-point calls

Every worker is a ZeroMQ DEALER behind one ROUTER. The broker tags requests with an id that workers echo back, tracks worker health, and persists pending messages in SQLite so a restarted worker can pick up where it left off.

Simulation behind every hardware module

I²C sensors, the serial bridge and the Arduino controller each take a tri-state simulation flag: auto-detect and fall back, force simulation, or require hardware. The simulated serial source produces idle RPM, coolant warm-up and voltage ripple, so CI and laptops run the same code paths as the car.

One schema across languages

FlatBuffers schemas define vehicle telemetry, GPIO commands and sensor messages once; generated bindings are used from Python and C++, and contract regression tests catch schema drift.

Per-platform CI

Path-based workflow triggers mean an Android change does not rebuild the C++ core. Native build failures are surfaced as annotations, and release builds publish artifacts.

Safety posture for a real car

The vehicle profile is a machine-readable file, not a comment in the code. It sets what MIA may do on the car, and the defaults say: listen, don't talk.

  • Read-only by default: no transmit on the powertrain or comfort CAN, UDS polling off, and only read services 0x19 and 0x22 allowed.
  • No extended diagnostic session, no security access, no write services.
  • A forbidden-actuation list: convertible top, central locking, exterior lighting, immobiliser, airbag and pyrotechnic circuits.
  • Listen-only is enforced in hardware by leaving the CAN transceiver’s TXD line unconnected, because a controller’s listen-only bit is a register a software bug can overwrite.
  • Every interface in the vehicle survey carries a confidence level and stays blocked until it has been verified on the car.

Latest feature: number-plate recognition

One feature cut across every layer: the Android app and an ESP32 camera capture a plate, the backend reads it and checks the Czech electronic vignette, and the result comes back to the phone. The eDálnice client has its own unit tests, and results are cached so repeated plates don't hit the service again.

  1. 01 Capture Phone camera or ESP32 camera frame
  2. 02 Recognise Plate read and post-processed on the backend
  3. 03 Look up Czech e-vignette status via the eDálnice service
  4. 04 Cache In-memory and on-disk cache, 24 h TTL
  5. 05 Show Result on the Android ANPR screen

Where it stands

Working

  • ZeroMQ broker, FastAPI gateway and workers
  • OBD-II digital twin with an ELM327 emulator
  • Simulation fallback for every hardware module
  • Android companion app and ANPR flow
  • Per-platform CI and release artifacts

Designed, not yet built

  • Audi A4 Cabriolet 8H in-car install: power and ignition sense, passive comfort-CAN sniffing, CD-changer audio path
  • Vehicle interfaces stay blocked until verified on the car

Much of the recent work was done with AI coding agents under the same review-and-CI flow as the rest of the repository; the project's own agent skills and MCP modules are part of what it demonstrates.

Stack

PythonFastAPIZeroMQSQLiteC++17FlatBuffersKotlinJetpack ComposeESP-IDFPlatformIOArduinoOBD-II / ELM327CANMCPsystemdDockerGitHub Actions