Skill Level: Beginner


Event FormatFollow the instructions given in https://developer.ibm.com/iot/recipes/improvise-registered-devices/ which details how devices publish events to the IBM Watson IoT Platform. You can also use these instructions to register your OBD-II device to the IBM Watson IoT Platform. The event format for all the events sent from your vehicle is as follows:{ d: {param1: value1,param2: value2 }} […]


Before you start, Your vehicle must have the capability to be registered with the IBM Watson IoT Platform organization. If you do not have a vehicle, you can use the simulator.

On-Board Diagnostic Device (OBD-II)

The OBD-II device in your vehicle can send vehicle data over Global System for Mobile Communications (GSM) or Bluetooth Low Energy (BLE) networks. You can find more information about the ODB-II standard at the following link: http://www.obdii.com/background.html


If you do not have a vehicle or an OBD-II device, you can use the simulator available at [https://github.com/jeffdare/iot-onboard-vehicle-data].

 Download the file https://github.com/jeffdare/iot-onboard-vehicle-data/archive/master.zip to your computer, and extract the contents.

The simulator runs in your browser and can be used to simulate vehicle events, for example, fuel and battery power remaining, engine temperature and tire pressure.

Getting the Bluemix services ready:

This IoT Recipe makes use of the Create Toolchain button to help deploy the necessary services on to Bluemix. Click on the Create Toolchain button provided below, provide a custom name to your application and choose to click on Create button, to quickly deploy the Watson IoT Platform – Node-RED Bluemix starter app. Post successful deployment, you shall have both the above mentioned services, up & running on Bluemix along with a Cloudant NoSQL DB at your disposal.


Note: If you are a User using the United Kingdom Region in your Bluemix environment, then please make use of the steps mentioned in the IoT Recipe Deploy Internet of Things Platform Starter service on Bluemix to deploy the setup. Alternatively, you can also try using the Deploy to Bluemix button, to deploy the setup under your United Kingdom Region, provided your Jazzhub account is validated. Users of US South Region can ignore this step.



  1. Register your Vehicle

    Open the Bluemix Dashboard and click on the Application service that you have currently deployed (using the Create Toolchain button), if you have already moved away from it. You should see the Watson IoT Platform listed under the Connections. Click on the WIoTP service and choose the click on Launch button to launch the WIoTP Dashboard.

    Carry out the steps present in this recipe to create Watson IoT Platform and register your car in it. You must use a unique ID to register your vehicle to the IBM Watson IoT Platform, for example, the chassis number or the International Mobile Station Equipment Identity (IMEI) number of your OBD-II device. When the device is registered, you will be provided with the registration details shown below. Make a note of them, we need these details to connect the Vehicle or Simulator to Watson IoT Platform later.


    After registering, store the credentials for the registered device.

    • On-Board Diagnostic Device (OBD-II) – Enter the credentials into your device to send events to your IBM Watson IoT Platform organization.
    • Simulator
      • Open the js/realtime.js file on your computer and update the credentials.
      • Double click on index.html file to start the simulator.
  2. Event Format

    Events are the mechanism by which Vehicle (IoT Device) publish data to the Watson IoT Platform. Device controls the content of their messages, and assign a name for each event that is sent. The Watson IoT Platform uses the credentials that are attached to each event received to determine which device sent the event. This architecture prevents devices from impersonating one another

    The event format for all the events sent from your vehicle is as follows:

    { d: {param1: value1,param2: value2   }}

    The topic to be published should be of the format iot-2/evt/eventType/fmt/json where the eventType is the type of event that the vehicle sends. For example, fuel, emissions and GPS events.

    A few examples of code formats are shown here:

    Fuel event: iot-2/evt/fuel/fmt/json

    {   "d": {               "fuel": "32"   }}

    Emission Event: iot-2/evt/emission/fmt/json

    {   "d": {       "hc": "32",       "co": "32",       "no": "32",       "co2": "32"   }}

    GPS Event: iot-2/evt/gps/fmt/json

    {   "d": {       "lat": "12.9521265",       "long": "77.6439412"   }}

    You can also combine multiple events for publishing by using the following example code format:

    All events : iot-2/evt/all/fmt/json

    {   "d": {       "hc": "32",       "co": "32",       "no": "32",       "co2": "32",       "fuel": "32",       "engineTemp" : "180"   }
  3. Configure Node-RED application to receive Vehicle data

    You have deployed the Node-RED service on to the Bluemix by clicking on the Create Toolchain button in Pre-requisites section. Access your Node-RED application by clicking on View App link and then choosing the option Go to you Node-RED flow editor, to access the editor.

    Parallelly, you can also access the Node-RED editor directly by accessing the following URL


    Note: The Node-RED Editor opens up with a default flow for the first time. Click on the + sign to create a new tab and continue working with the steps mentioned in the subsequent sections of this recipe.

  4. Node-RED flows to receive Vehicle data events

    Listed here are three sample Node-RED flows that you can use with your vehicles data. The three flows demonstrate different capabilities of Node-RED.

    To use any of the following sample flows:

    1. Click on Menu->Import->Clipboard in your Node-RED editor
    2. Paste the Generic flow, MBaaS or HDFS JSON content, as present in the boxes below
    3. In the flow, double click on IBM IoT App In node and select Bluemix Service for authentication.

    Generic Flow

    This flow demonstrates how Node-RED accepts and uses any event that can be sent to a Bluemix application. You can extend this flow and implement your business logic.

    [{"id":"26a2dad.fd95d26","type":"ibmiot in","authentication":"boundService","apiKey":"","inputType":"evt","deviceId":"","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT App In","service":"registered","allDevices":true,"allApplications":false,"allDeviceTypes":true,"allEvents":true,"allCommands":false,"allFormats":true,"x":126,"y":220,"z":"7d639053.67fa68","wires":[["496e9445.89d834","e0c2a5f5.6c1a6"]]},{"id":"e0c2a5f5.6c1a6","type":"debug","name":"","active":true,"console":"false","complete":"true","x":216,"y":372,"z":"7d639053.67fa68","wires":[]},{"id":"496e9445.89d834","type":"switch","name":"Splitting based on the eventType","property":"eventType","rules":[{"t":"eq","v":"fuel"},{"t":"eq","v":"airbag"},{"t":"eq","v":"torque"},{"t":"eq","v":"GPS"},{"t":"eq","v":"tyrepressure"},{"t":"eq","v":"pollution"},{"t":"eq","v":"engineTemp"},{"t":"eq","v":"speed"},{"t":"eq","v":"all"}],"checkall":"true","outputs":9,"x":413,"y":222,"z":"7d639053.67fa68","wires":[["ba699674.5978a8"],[],[],[],[],[],[],[],[]]},{"id":"5dd34de0.e76d54","type":"comment","name":"Generic Flow to accept events sent from car","info":"","x":281,"y":88,"z":"7d639053.67fa68","wires":[]}]

    Mobile Application Security and Push Integration (MBaaS)

    This flow demonstrates how to integrate the Mobile Push service to the Node-RED flow.

    In this sample flow, a business rule engine is used to check if the fuel level of the vehicle is less than the level specified. If the fuel level is less than the specified amount, the application will search for the location of the nearest fuel stations and send a Push notification to the vehicle owner. The Push notification will include details of the current fuel level and the locations of the nearest fuel stations.

    Further information about Push notification can be found at the IBM Bluemix website https://www.ng.bluemix.net/docs/?cm_mmc=developerWorks-_-dWdevcenter-_-iot-_-lp#services/IoT/index.html#iot140.

    [{"id":"4ecec8b8.1b2c58","type":"comment","name":"Flow to have a rule engine and send notification to a mobile phone","info":"","x":421,"y":50,"z":"7d639053.67fa68","wires":[]},{"id":"26a2dad.fd95d26","type":"ibmiot in","authentication":"boundService","apiKey":"","inputType":"evt","deviceId":"","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT App In","service":"registered","allDevices":true,"allApplications":false,"allDeviceTypes":true,"allEvents":true,"allCommands":false,"allFormats":true,"x":126,"y":220,"z":"7d639053.67fa68","wires":[["496e9445.89d834","e0c2a5f5.6c1a6"]]},{"id":"e0c2a5f5.6c1a6","type":"debug","name":"","active":true,"console":"false","complete":"true","x":216,"y":372,"z":"7d639053.67fa68","wires":[]},{"id":"496e9445.89d834","type":"switch","name":"Splitting based on the eventType","property":"eventType","rules":[{"t":"eq","v":"fuel"},{"t":"eq","v":"airbag"},{"t":"eq","v":"torque"},{"t":"eq","v":"GPS"},{"t":"eq","v":"tyrepressure"},{"t":"eq","v":"pollution"},{"t":"eq","v":"engineTemp"},{"t":"eq","v":"speed"},{"t":"eq","v":"all"}],"checkall":"true","outputs":9,"x":373,"y":220,"z":"7d639053.67fa68","wires":[["ba699674.5978a8"],[],[],[],[],[],[],[],[]]},{"id":"d831b6a9.f44d8","type":"debug","name":"No action taken","active":true,"console":"false","complete":"false","x":779,"y":286,"z":"7d639053.67fa68","wires":[]},{"id":"ba699674.5978a8","type":"switch","name":"fuel rule engine","property":"payload.d.fuel","rules":[{"t":"lt","v":"3"},{"t":"else"}],"checkall":"true","outputs":2,"x":617,"y":168,"z":"7d639053.67fa68","wires":[["87466171.ca4d"],["d831b6a9.f44d8"]]},{"id":"8d76dc29.00c598","type":"ibmpush","name":"Send Push notifications","ApplicationID":"","ApplicationRoute":"","identifiers":"driver1","notification":"deviceid","x":1292,"y":160,"z":"7d639053.67fa68","wires":[]},{"id":"56503f1d.c3342","type":"template","name":"Build message","field":"payload","template":"Fuel is very less and is {{msg.payload.d.fuel}}. Please refill in the nearest Fuel Station","x":1058,"y":159,"z":"7d639053.67fa68","wires":[["8d76dc29.00c598"]]},{"id":"87466171.ca4d","type":"function","name":"Fuel station details","func":"// here you can make any maps API call and get the nearest n//fuel station.nreturn msg;","outputs":1,"x":835,"y":159,"z":"7d639053.67fa68","wires":[["56503f1d.c3342"]]}]

    Hadoop Distributed File System(HDFS)

    This flow demonstrates how to integrate the IBM Analytics for Hadoop service to the Node-RED flow. This Bluemix service can be used analyze data by using Hadoop software.

    In this sample flow, the application creates a new file for each vehicle based on its chassis number or IMEI number and stores all the events that the vehicle emitted.

    Further information about HDFS can be found at the IBM Bluemix site:


    [{"id":"6977e53f.1624e4","type":"comment","name":"Flow to put all the car events into HDFS system","info":"","x":284,"y":101,"z":"74a1ae21.252c48","wires":[]},{"id":"eef0e10c.eba21","type":"ibmiot in","authentication":"boundService","apiKey":"","inputType":"evt","deviceId":"","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT App In","service":"registered","allDevices":true,"allApplications":false,"allDeviceTypes":true,"allEvents":true,"allCommands":false,"allFormats":true,"x":182,"y":209,"z":"74a1ae21.252c48","wires":[["fe24f384.28b82","d008c80c.f72258"]]},{"id":"fe24f384.28b82","type":"debug","name":"","active":true,"console":"false","complete":"true","x":336,"y":339,"z":"74a1ae21.252c48","wires":[]},{"id":"21b9afe9.21d6d","type":"ibm hdfs","name":"","filename":"test.txt","appendNewline":true,"overwriteFile":false,"x":693,"y":208,"z":"74a1ae21.252c48","wires":[]},{"id":"d008c80c.f72258","type":"function","name":"Formatting the message for HDFS","func":"msg.filename = msg.deviceId;nreturn msg;","outputs":1,"x":445,"y":209,"z":"74a1ae21.252c48","wires":[["21b9afe9.21d6d"]]}]
  5. Extend with other Services (Optional)

    Optionally, you can use other services like Visualization and Geo-spatial service to extend the view of your vehicle data.

    Visualize your data using Watson IoT Platform Boards & Cards

    With the new boards and cards in the Watson IoT Platform, you can build your own Custom Dashboard. You can use the boards as the landing page of interest and then make use of the cards to:

    • Create visualization charts for the real time data from your devices
    • Create Gauges for visualizing physical quantities like Vehicle Speed, Temperature, pressure.
    • Create Donuts charts, bar charts to display the current value of the data points
    • See the Data and storage consumption of your devices
    • List of registered device

    Carry out the steps present in this recipe to view the Vehicle events graphically,

    Visualize Your Data outside Watson IoT Platform

    You can use the IBM Watson IoT Platform tools to build dashboards for your vehicles data. To deploy your visualization sample, follow the steps in the IBM Bluemix page https://www.ng.bluemix.net/docs/?cm_mmc=developerWorks-_-dWdevcenter-_-iot-_-lp#services/IoT/index.html#iot200. You do not need to follow the Create an instance of the Internet of Things Service step, because you do not need a separate organization for visualization.

    Generate API Key and Token of Watson IoT Platform

    In order to connect the visualization application to IBM Watson IoT Platform to receive Vehicle events, we need to generate the API key and token first. This can be achieved by carrying out steps present in this section – Generate API Key in Watson IoT Platform.

    Click Use a different API-key and Auth Token in your visualization application and enter the credentials. Now you can view multiple dashboards for your vehicles data.

    Integration with Geospatial Analytics

    Use the Bluemix Geospatial Analytics service to track when devices enter or leave defined regions, or geofences. IBM Geospatial Analytics for Bluemix allows you to monitor moving devices from your Bluemix application. You can use the Geospatial Analytics service to monitor when devices are entering and leaving specified locations.

    For further information on IBM Bluemix geospatial service, see https://www.ng.bluemix.net/docs/#services/geospatial/index.html

    1. Add the Geospatial service to your Node.js application.
    2. To set up the Geospacial service follow the steps at https://www.ng.bluemix.net/docs/#services/geospatial/index.html
    3. Generate an API key for your organization in IBM Watson IoT Platform and store the API-key and Auth token
    4. The Geospatial service requires an MQTT broker to provide the device messages. You can use the IBM Watson IoT Platform service as the MQTT broker. Use the following settings
    // Create the JSON objectjsonObject = JSON.stringify({"mqtt_client_id_input" : "a:"+ your_org + ":geoInput","mqtt_client_id_notify" : "a:"+ your_org + ":geoNotify","mqtt_uid" : api_key,"mqtt_pw" : " auth_token ","mqtt_uri" :your_org + ".messaging.internetofthings.ibmcloud.com:1883","mqtt_input_topics" : " iot-2/type/car/id/+/evt/gps/fmt/json","mqtt_notify_topic" : " iot-2/type/car/id/geospatialAlerts/cmd/geoAlert/fmt/json ","device_id_attr_name" : "deviceId","latitude_attr_name" : "lat","longitude_attr_name" : "long"});


    api_key & auth_token API-Key that you generated for your organization

    uri Your organization MQTT hostname

    mqtt_input_topics Topic used by the geospatial service to get the current location of the vehicles.

    mqtt_notify_topic Topic used by geospatial service to send back alerts to the device. device_id_attr_name The device ID attribute in the JSON message

    latitude_attr_name The latitude attribute in the JSON message. In the simulator, the attribute is lat.

    longitude_attr_name The longitude attribute in the JSON message. In the simulator, the attribute is long

    1. Then use the geospatial ReST APIs – https://www.ng.bluemix.net/docs/?cm_mmc=developerWorks-_-dWdevcenter-_-iot-_-lp#services/geospatial/index.html#restapi
      1. To start the service using the jsonObject
      2. Define a geo-fence region using the addRegion operation.
        jsonObject=JSON.stringify({    "regions": [        {            "region_type": "regular",            "name": "Coffee Shop",            "notifyOnExit": "false",            "center_latitude": "12.9521265",            "center_longitude": "77.6439412",            "number_of_sides": "10",            "distance_to_vertices": "150"       }   ]})
      3. You can also add multiple regions for geo-fencing.
    1. Now when the vehicle enters the geo-fence area, a notification will be sent to the device geospatialAlerts which is listening to command geoAlert. Here is a sample snippet of the device code.
    var deviceId = "geospatialAlert";var clientId = "d:" + your_org + ":" + "car" + ":" + deviceId ;var subscribeTopic = "iot-2/cmd/geoAlert/fmt/json";deviceClient.subscribe(subscribeTopic);

    This device will receive all notifications from the geospatial service.

  6. Next step

    As a next step, go through the Vehicle telematics analytics recipe to analyze the Vehicle data in realtime that is being sent to the IBM Watson IoT Platform.

Expected Outcome

At the end of this tutorial, you will have a vehicle connected to IBM Internet of Things Foundation and sending data to the cloud.

3 comments on"Sending Vehicle Data to the IBM Watson IoT Platform"

  1. Hello,

    I am trying to implement integration with Geospatial Analytics. I have followed the recipe using the simulator (I am able to implement the the nodered Generic Flow mentioned in the recipe ). Then, I added the geospatial service to node.js app, started the service (using IoTF as the MQTT broker) and added the regions.

    So far all good, I can the geospatial service is started and regions are created successfully.

    After this, I am not getting any clue how to implement a simple flow where I can see if the simulated vehicle has entered the regions i created and a notification is sent to alert the vehicle entry.

    Appreciate any help on this to move forward.

  2. Very nice!

    I wrote a recipe to use a browser plugin instead of your simulator: https://developer.ibm.com/recipes/tutorials/create-a-iot-simulator-of-any-iot-device-mqtt/

    Have you got any Android application connected to the OBD device, and Bluemix? I’m just trying that now, will share when its working properly

  3. Can you provide some context for this project, specifically what IBM are doing with the data once provided?

Join The Discussion