Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

Lab: Cloud-Connected Vehicle Application

ComponentTechnologyPurpose
Vehicle simulatorPython + Kuksa.val clientGenerates realistic VSS signal stream
Cloud ingestionMQTT -> AWS IoT Core (local: Mosquitto)Receives telemetry from vehicle
Fleet dashboardStreamlit + PandasReal-time fleet KPI visualisation
Remote diagnosticsFastAPI REST endpointQuery vehicle DTC list remotely
OTA triggerMQTT command messageInitiate OTA update campaign on vehicle

Exercise 1: Vehicle Simulator and Fleet Dashboard

Pythonvehicle_simulator.py
#!/usr/bin/env python3
"""Realistic vehicle telemetry simulator for cloud connectivity lab."""
import asyncio
import json
import math
import random
import time
import paho.mqtt.client as mqtt

BROKER = "localhost"
PORT   = 1883
VIN    = "SIM_VEHICLE_001"

class VehicleSimulator:
    def __init__(self, vin: str):
        self.vin = vin
        self.speed   = 0.0
        self.soc     = 85.0
        self.lat     = 48.137154  # Munich
        self.lon     = 11.576124
        self.odometer = 12543.0
        self.dtcs    = []
        self.client  = mqtt.Client()
        self.client.connect(BROKER, PORT)
        self.client.loop_start()

    def simulate_step(self):
        """Update vehicle state for one 1-second step."""
        # Simple city driving profile: accelerate/cruise/brake
        t = time.time() % 120  # 2-minute drive cycle
        if t < 30:
            self.speed = min(50, self.speed + 2.0)  # accelerate
        elif t < 80:
            self.speed += random.gauss(0, 1)  # cruise with noise
            self.speed = max(30, min(60, self.speed))
        else:
            self.speed = max(0, self.speed - 3.0)  # brake

        # SOC decreases with speed
        self.soc -= self.speed * 0.0001
        self.soc = max(10, self.soc)

        # Move location
        self.lat += self.speed * 0.00001
        self.odometer += self.speed / 3600

        # Occasionally inject a DTC
        if random.random() < 0.001:
            self.dtcs.append("P0300")  # random misfire

    def publish_telemetry(self):
        payload = {
            "vehicleId": self.vin,
            "timestamp": int(time.time() * 1000),
            "signals": {
                "Vehicle.Speed": round(self.speed, 1),
                "Vehicle.Powertrain.TractionBattery.StateOfCharge.Current": round(self.soc, 1),
                "Vehicle.CurrentLocation.Latitude": self.lat,
                "Vehicle.CurrentLocation.Longitude": self.lon,
                "Vehicle.TraveledDistance": round(self.odometer, 2)
            }
        }
        self.client.publish(f"vehicles/{self.vin}/telemetry",
                            json.dumps(payload), qos=0)

if __name__ == "__main__":
    sim = VehicleSimulator(VIN)
    print(f"Simulating vehicle {VIN}...")
    while True:
        sim.simulate_step()
        sim.publish_telemetry()
        time.sleep(1)

Exercise 2: Remote Diagnostics REST API

Pythonremote_diagnostics_api.py
"""Remote diagnostics REST API (FastAPI)."""
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import json
import paho.mqtt.client as mqtt
from typing import List

app = FastAPI(title="SDV Remote Diagnostics API")

# In-memory store for demo (use database in production)
vehicle_dtcs: dict = {}  # VIN -> [DTC codes]
vehicle_signals: dict = {}  # VIN -> {signal: value}

# MQTT subscriber to receive vehicle telemetry
def on_message(client, userdata, msg):
    data = json.loads(msg.payload)
    vid = data.get("vehicleId")
    if vid:
        vehicle_signals[vid] = data.get("signals", {})

mqtt_client = mqtt.Client()
mqtt_client.on_message = on_message
mqtt_client.connect("localhost", 1883)
mqtt_client.subscribe("vehicles/+/telemetry")
mqtt_client.loop_start()

@app.get("/vehicles/{vin}/signals")
async def get_vehicle_signals(vin: str):
    if vin not in vehicle_signals:
        raise HTTPException(404, f"Vehicle {vin} not found or offline")
    return {"vin": vin, "signals": vehicle_signals[vin]}

@app.post("/vehicles/{vin}/ota-trigger")
async def trigger_ota(vin: str, version: str):
    """Send OTA update command to vehicle via MQTT."""
    command = {"action": "ota_update", "target_version": version}
    mqtt_client.publish(f"vehicles/{vin}/commands",
                        json.dumps(command), qos=1)
    return {"status": "command_sent", "vin": vin, "version": version}

Summary

The cloud-connected vehicle lab integrates all five SDV technology pillars into a working end-to-end system. The vehicle simulator generates realistic telemetry (drive cycle, SOC drain, location update, occasional DTC injection); the MQTT broker receives it; the REST API exposes it for remote diagnostics and OTA triggering. This is the minimal viable SDV cloud stack -- the same pattern used by production fleet management systems, just without the Kubernetes orchestration, database persistence, and TLS authentication that production systems require. The OTA trigger endpoint demonstrates the command channel that fleet operators use to deploy updates: a single HTTP POST to the diagnostics API translates to an MQTT message that the vehicle receives and acts on -- the beginning of the update orchestration flow covered in the OTA lessons.

🔬 Deep Dive — Core Concepts Expanded

This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.

Key principles to reinforce:

  • Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
  • Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
  • Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.

🏭 How This Topic Appears in Production Projects

  • Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
  • Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
  • Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.

⚠️ Common Mistakes and How to Avoid Them

  1. Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
  2. Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
  3. Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
  4. Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.

📊 Industry Note

Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.

← PreviousData Analytics and ML at the Edge