Project Title: Development of a Cross-Domain Communication Bridge between MQTT Protocol and In-Vehicle CAN Bus System
[Your Name Here] Department: Mechanical Engineering with Interest in Embedded Systems / IoT Advisor: [Professor's Name] Date of Submission: [Insert Date]
Modern vehicles are becoming increasingly connected, with the integration of cloud-based services, mobile applications, and real-time telemetry. Most vehicles use the CAN (Controller Area Network) bus protocol for internal communication between Electronic Control Units (ECUs). On the other hand, MQTT (Message Queuing Telemetry Transport) is a lightweight protocol widely used in IoT and remote monitoring applications.
This project proposes the development of a Cross-Domain Communication Bridge that enables two-way communication between MQTT and CAN bus, providing real-time control and monitoring of vehicle systems remotely.
To design and implement a hardware-software system that:
- Subscribes to MQTT topics and converts messages into CAN frames.
- Sends CAN bus messages to MQTT for remote monitoring.
- Acts as a secure, scalable bridge between cloud/mobile apps and vehicle systems.
[ Mobile App / MQTT Client ]
|
v
[ MQTT Broker (Cloud) ]
|
v
[ MQTT-CAN Gateway (Raspberry Pi or MCU) ]
|
v
[ CAN Bus ]
|
v
[ In-Vehicle ECUs (e.g., door lock, engine control) ]
-
Hardware:
- Raspberry Pi (or ESP32 / STM32 MCU)
- MCP2515 CAN transceiver
- 12V to 5V voltage converter
- OBD-II port connection for CAN
-
Software:
- Python 3
paho-mqtt
(for MQTT communication)python-can
(for CAN communication)- JSON for message payloads
- The gateway device connects to a public or private MQTT broker.
- It subscribes to control topics like
car/control
. - Incoming MQTT messages are parsed and translated into CAN bus messages.
- The translated CAN frames are sent to the vehicle's CAN bus.
- The system also listens to the CAN bus and publishes readable data (e.g., speed, fuel) to an MQTT topic like
car/status
.
import can
import paho.mqtt.client as mqtt
import json
MQTT_BROKER = "broker.hivemq.com"
MQTT_TOPIC_SUB = "car/control"
MQTT_TOPIC_PUB = "car/status"
can_interface = 'can0'
bus = can.interface.Bus(channel=can_interface, bustype='socketcan')
def on_message(client, userdata, msg):
data = json.loads(msg.payload.decode())
can_id = data.get("id", 0x123)
payload = bytes(data.get("data", [0x00]))
message = can.Message(arbitration_id=can_id, data=payload, is_extended_id=False)
bus.send(message)
print(f"Sent to CAN: ID={hex(can_id)}, Data={payload.hex()}")
def can_to_mqtt(client):
while True:
message = bus.recv()
if message:
payload = {
"id": message.arbitration_id,
"data": list(message.data)
}
client.publish(MQTT_TOPIC_PUB, json.dumps(payload))
print(f"Published to MQTT: {payload}")
client = mqtt.Client()
client.on_message = on_message
client.connect(MQTT_BROKER)
client.subscribe(MQTT_TOPIC_SUB)
client.loop_start()
try:
print("Bridge is running...")
can_to_mqtt(client)
except KeyboardInterrupt:
print("Stopping bridge.")
client.loop_stop()
- MQTT to CAN message example:
{
"id": 291,
"data": [1, 0, 255]
}
- CAN to MQTT (published message):
{
"id": 291,
"data": [1, 0, 255]
}
- Enables remote diagnostics and control
- Useful in fleet management systems
- Can be extended to automated emergency services
- Forms the base for connected autonomous vehicle architectures
- Add support for other protocols like Modbus, FlexRay, or LIN
- Add encryption, authentication, and logging
- Mobile app interface for real-time control and status
This project successfully demonstrates the bridging of two different communication domains: MQTT (cloud/mobile) and CAN bus (automotive embedded). The proposed MQTT-CAN bridge can become a key component in modern IoT-enabled automotive systems.
- ISO 11898 Standard (CAN Protocol)
- MQTT.org Documentation
- Python
python-can
andpaho-mqtt
libraries - Raspberry Pi CAN interface guides