How to stream Car Data using our MQTT Auto API? OpenDevTalk#3

October 10, 2022
Periodical polling (for instance via REST API) works great for use cases that require regular snapshots of the vehicle status information (e.g. Pay-as-you-drive). But if you need to track ongoing information changes the request/response model will quickly fall short as you risk to miss updates if the request is not repeated often enough and bandwidth will be wasted if the vehicle sends no new information for example when it is parked. High Mobility offers a push technology to overcome those challenges. MQTT enables our data customers to continuously subscribe to data updates. In our third Open Dev Talk our CTO Kevin Valdek introduces recommended steps for integrating our new interface.

Getting started with MQTT

MQTT (MQ Telemetry Transport) is one of the most popular messaging protocols that is commonly adopted in the context of the Internet of Things. The protocol is grounded on a publish/subscribe pattern. At High Mobility, cars will act as senders (Publisher) and our data customers will take over the role of the receivers (Subscribers). The connection is managed by the MQTT broker. In order to start working with MQTT, we are recommending going through each of the following steps. Every underlying aspect will be explained in more detail both in the video of our first Open Dev Talk and this blog post.

  • Check availability using our data catalogue
  • Setup the MQTT client
  • Connect to the MQTT broker
  • Subscribe to vehicle data

Streaming Availability

Before starting with the actual integration we propose to check out our data catalogue.This overview highlights all available data items and explains which ones can be pulled or pushed through our existing APIs. The current offering might slightly differ from brand to brand and in some cases also in regards to ICE and electric vehicles. Feel free to apply filters to the brand columns to easily figure out which data set and use cases are supported by the selected OEMs.

High Mobility’s MQTT API is currently supported in our live environment only. Consequently, the corresponding application must be submitted and approved and fleet clearance / driver consent needs to be obtained before the data streams of connected cars can be consumed. Learn more about that process in our Open Dev Talk #1. We are planning to add streaming capabilities to the test environment and its simulation features in future.

Preparing the MQTT client

Following our step by step documentation is a good starting point in order to get familiar with our MQTT service: The first step is to login at our High Mobility platform and to navigate to the Live Data module. If you have not yet created a data container for live data usage please go ahead and create a new one. You will be asked to set a name and permissions (data points) that you like to receive later on. In order to consume live data the app container needs to be submitted and activated.

If you already have an active data container you can go directly to the certificates section. Hit the plus button to generate a new set of credentials. The associated files are downloaded as a zip package to your local device. 

Connecting to the MQTT broker

Next up, you can use your preferred MQTT client software or library to connect to the MQTT by passing in the root certificate, client certificate and private key.

In our example, we utilise the terminal tool mosquito_sub and have prepared a code snippet in the documentation that can be easily adjusted to your own set of credentials. We have set the parameter –disable-clean-session and Quality of Service to 1 to not miss any message in case of unexpected or scheduled downtimes. The host needs to point to mqtt.high-mobility.com and the port is supposed to be 8883. Additionally, the path needs to be set to live/level13/<your-app-id>/# which contains the current data protocol version and your data container id that you can retrieve from our platform. The hashtag in the end is a wildcard representing all topics underneath that path.

All placeholders for the referenced certificate authority file, the data container certificate and the respective private key need to be replaced with the exact file names of your downloaded certificate files. The identifier for your MQTT client should be derived from the unique file name id that is included in the certificate file names. 

After executing the request successfully you can use the open session to receive the data that is generated by active vehicles. 

Subscribe to live vehicle data

As soon as new data is generated it will now be pushed to your MQTT client. As High Mobility focuses on personalized vehicle data every incoming message will include the VIN which also can be pseudonymised for more specialised use cases. Please be aware that there might be infrastructure-related latencies but since all messages contain a timestamp that explains when the data was generated you will always be able to recreate the correct historical order of events. 

-------------------------------
High Mobility Open Dev Talks 

At High Mobility, we are passionate about new technology. We offer free open source tools and developer friendly documentation for any projects to be integrated smoothly. More than 800 developers and product managers have already signed up for our moderated community platform and we are hosting connected car competitions for your innovative, connected car ideas. 

In our free monthly, 30-minute Open Dev Talk online session we are explaining exciting connected car related topics in 15 minutes and dedicate the rest of the time to your questions and ideas.

Join our community on Slack