Context Mapping and Driver Behavior tutorial, Part 1: Sending car probe data and issuing analysis requests
The first part of this tutorial describes how you can set up your Bluemix environment to use the following services for simulating and analyzing driver behavior.
- Watson IoT Platform uses the MQTT protocol to retrieve car probe data from a simulated car, and then passes that data to the Node-RED service. Car probe data is a sequence of car probes that are ordered by timestamp. A single car probe consists of the heading, latitude, longitude, speed, and timestamp retrieved from the car for each journey that is recorded.
- Node-RED Starter creates work flows between components of the sample application. The Node-RED visual tool helps you to easily understand the work flows.
- Watson IoT Driver Behavior gives you an insight into the behavior of a driver during the simulated journey from the associated car probe data. The Driver Behavior APIs let you use both the context data and the car probe data to analyze the journey and to identify the driving behaviors, such as:
- Speeding
- Frequent acceleration and braking
- Harsh acceleration and braking
- Sharp turns
- Watson IoT Context Mapping provides a service API from which you can extract further information from the car probe data, such as:
- The exact location of the car on a mapped road, because the location data from the car is not accurate
- The road ID, which is called
link_id
in APIs, of the road that the car traveled
In part 1 of this tutorial, you will learn the following:
- How to set up Driver Behavior and Context Mapping.
- The types of car data that is needed to analyze the behavior of a driver.
- How to send the car probe data to the Context Mapping and Driver Behavior services by using the Watson IoT Platform and Node-RED services.
- How to analyze the behavior of a driver.
Note: After you send a job request by using the Driver Behavior API, the job ID is generated, which you will need in part 2 of this tutorial.
In part 2 of this tutorial, you will learn how to see the results of the analysis on a map user interface by hovering the cursor over points on the map.
For "Tutorial part 2: Displaying the analysis result on a Java client map UI", refer to this GitHub repository
The following steps provide a sequential outline of how your application interacts with the Driver Behavior API:
Note: Steps 1 - 4 are explained below, and steps 5 - 7 are explained in part 2 of the tutorial.
- The Java client that simulates a car sends car probe data from to the Watson IoT Platform instance.
- The application receives the car probe data and then adds more data to the car probe data by using the Context Mapping API.
- Gets map matched car probe data by using the
mapMatching
API of Context Mapping.- [Request] Car probe data
- [Response] Map matched car probe data
- Gets road type data by using the
getLinkInformation
API of Context Mapping.- [Request] Road link ID
- [Response] Road type
- Gets map matched car probe data by using the
- The application sends car probe data to the store so that it can then be analyzed by using
sendCarProbe
API of Driver Behavior.- [Request] Map matched car probe data and Road type
- The application sends a job request to analyze car probe data by using the
sendJobRequest
API of Driver Behavior.- [Request] Date from and to
- [Response] Job ID
- The application gets the analyzed trip summary list by using the
getAnalyzedTripSummaryList
API of Driver Behavior.- [Request] Job ID
- [Response] List of analyzed trip summary
- The application gets the analyzed trip information by using the
getAnalyzedTripInfo
API of Driver Behavior.
- [Request] Trip UUID
- [Response] Details of the analyzed trip
- The application displays the analyzed results on a map UI from the Java client.
Architecture diagram of the Watson IoT Context Mapping and Driver Behavior services
If you do not already have a Bluemix ID, click the following link to register: https://console.ng.bluemix.net/registration/.
To complete the tutorial, the following prerequisite software must be installed on your system:
- Java V1.7 or higher to run the Watson IoT Platform Java client.
- Git to clone project code locally.
- Requires maven to build the Java client of the Watson IoT Platform.
- Optional: Eclipse to run the IoT Platform Java client.
- IBM Watson IoT Platform Java Client Library
When you complete part 1 of this tutorial, the following components are downloaded:
File | Description |
---|---|
SendCarProbe.java | Sample Java to send car probe data to Watson IoT Platform |
device.prop | A configuration file of SendCarProbe.java, which is used to load the credentials of Watson IoT Platform |
nodered-workflow-send-car-probe-data.json | Node-RED flow to receive car probe data from Watson IoT Platform and to store the data into the Driver Behavior service |
nodered-workflow-send-job-request.json | Node-RED flow to send a driving behavior analysis request |
CarProbeSample.json | Sample car probe data |
When you complete the instructions in this tutorial, the following services will be instantiated in your Bluemix organization:
- IBM Watson IoT Context Mapping
- IBM Watson IoT Driver Behavior
- IBM Watson IoT Platform
- Node-RED Starter
To complete part 1 of the tutorial, you must complete the following tasks:
- Setting up Context Mapping.
- Setting up Driver Behavior.
- Creating the Node-RED application.
- Setting up a Watson IoT Platform instance.
- Setting up the Node-RED workflow for sending car probe data.
- Setting up the Node-RED workflow for sending analysis job requests.
- Setting up the Java client of the Watson IoT Platform.
- Running the Send Car Probe Data sample.
- Running the Send Analysis Job Request sample.
- Optional: Setting up and running the Watson IoT Platform Java client by using Eclipse.
This section explains how to subscribe Context Mapping that is required for this sample application.
- Go to the IoT Context Mapping service in the Bluemix catalog.
- Select the Free plan option, enter the required information, and then click CREATE.
WARNING: If you do not select the Free plan option, there could be a payment charge for using this service.
- Tenant ID
- Username
- Password
Complete the following steps to set up and subscribe the Driver Behavior service:
- Go to the IoT Driver Behavior service in the Bluemix catalog.
- Select the Free plan option, enter the required information, and then click CREATE.
WARNING: If you do not select the Free plan option, there could be a payment charge for using this service.
- Make a note of the following information for your service instance, as you will need this information later on in the process.
Complete the following steps to set up and subscribe the required Node-RED application:
- Go to the Node-RED Starter boilerplate in the Bluemix catalog.
- Enter a name, for example,
watson-iot-sample
. - Default on SDK for Node.js, and select Shared on Cloudant NoSQL DB.
- Click SDK for Node.js service, and then select Default plan on Pick a Plan list.
- Click Cloudant NoSQL DB service, and then select Default plan on Pick a Plan list.
- Click CREATE.
WARNING: If you exceed the threshold levels that are described in this plan, you could be required to pay further charges.
Complete the following steps to subscribe the required Watson IoT Platform.
- Go to the IoT Platform service in the Bluemix catalog.
- Under App heading, select the
watson-iot-sample
that you created earlier in step 3. - Select the Free plan option, enter the required information, and then click CREATE.
WARNING: If you do not select the Free plan option, there could be a payment charge for using this service.
- When prompted, click RESTAGE.
- Go to your Internet of Things Platform service and click Launch dashboard.
- Click Add Device. Step 5-11 is for registering Vehicle type for sample application in Watson IoT Platform.
- Click Create device type.
- Click Create device type again.
- Enter
vehicle
as the Name, and then click Next.
- Click Next.
- Click Next again.
- Click Create.
- Click vehicle as device type, followed by Next. Steps 13-18 are for registering a single sample vehicle for the sample application in Watson IoT Platform.
- For Device ID, specify
vehicle-sample
, and then click Next.
- Click Next.
- Click Next.
- Click Add.
- Make a note of the Organization ID and Authentication Token as you will need these credentials later on in the process when you set up the sample application.
The Node-RED workflow receives car probe data through the Watson IoT Platform. The workflow adds more properties to the car probe data by calling the Context Mapping API and storing the car probe data into Driver Behavior to be analyzed.
- Return to the Bluemix dashboard, go to your Node-RED application, and then click the Routes link.
- Click Go to your Node-RED flow editor.
- Open the menu on the upper right, click Flows > Rename, and rename the flow to
Send Car Probe Data
.
- Go back to the menu, and click Import > Clipboard.
- Copy the content from nodered-workflow-send-car-probe-data.json and click OK.
- Double-click the Common Config node.
- Set the values for
msg.mapTenantId
andmsg.driverTenantId
.msg.mapTenantId
: Tenant ID from Context Mappingmsg.driverTenantId
: Tenant ID from Driver Behavior
- Double-click the mapMatching node.
- Select Use basic authentication? and enter the following credentials:
- Username: Username from Context Mapping
- Password: Password from Context Mapping
- Double-click the getLinkInformation node.
-
Select Use basic authentication? and enter the following credentials:
- Username: Username from Context Mapping
- Password: Password from Context Mapping
-
Double-click carProbe.
-
Select Use basic authentication? and enter the following credentials:
- Username: Username from Driver Behavior
- Password: Password from Driver Behavior
-
Click Deploy and wait for the Successfully deployed notification.
This Node-RED workflow requests an analysis job for the stored car probe data.
- Create another new tab in the Nod-RED editor by clicking the upper right
+
icon, and rename the tab toSend Job Request
.
- Click Import > Clipboard.
-
Copy the content from nodered-workflow-send-job-request.json and click OK.
-
Double-click Config.
- Double-click sendJobRequest.
- Select Use basic authentication? enter the following credentials:
- Username: Username from Driver Behavior
- Password: Password from Driver Behavior
Complete the following instructions to set up and configure the Java client. Alternatively, you can skip step 7 and set up and run IoT Platform Java client using Eclipse instead.
The Java client that you are about to install, loads sample car probe data from a file named CarProbeSample.json
, and then sends the data to the Watson IoT Platform instance by using the Watson IoT Platform Java API com.ibm.iotf.client.device.DeviceClient
. The file device.prop
provides the configuration for the Watson IoT Platform Java API. The car probe data is received by a Node-RED workflow through threshold Watson IoT Platform and is processed by the workflow logic.
-
Clone the car-data-management project by using git clone, as follows:
git clone https://github.com/IBM-Bluemix/car-data-management
-
Navigate to the car-data-management project.
cd car-data-management
-
Run the maven build as follows to build the Java client.
mvn clean compile
The Java Client library for the Watson IoT Platform and all required dependencies are downloaded and the build process starts.
-
Edit the
config/device.prop
file, and add theOrganization-ID
andAuthentication-Token
, which you recorded in the previous step section. -
Run the sample by using the following maven command:
mvn test
-
To see whether the Java client Successfully transmitted the car probe data to Watson IoT Platform, check the log file:
... [INFO] --- exec-maven-plugin:1.4.0:java (default) @ samples.car-data-management --- 4 28, 2016 3:29:59 ?? com.ibm.iotf.client.AbstractClient createClient ??: com.ibm.iot.auto.bluemix.samples.nodered.SendCarProbe.main(): Org ID = XXXXX Client ID = d:XXXXX:vehicle:vehicle-sample 4 28, 2016 3:29:59 ?? com.ibm.iotf.client.AbstractClient connect ??: com.ibm.iot.auto.bluemix.samples.nodered.SendCarProbe.main(): Connecting client d:XXXXX:vehicle:vehicle-sample to ssl://XXXXX.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)... 4 28, 2016 3:30:01 ?? com.ibm.iotf.client.AbstractClient connect ??: com.ibm.iot.auto.bluemix.samples.nodered.SendCarProbe.main(): Successfully connected to the IBM Watson IoT Platform {"heading":273.995431,"latitude":30.398979,"longitude":-97.746781,"speed":0.0,"timestamp":"2016-03-11T13:43:16.000Z","trip_id":"1457671273"} {"heading":273.995431,"latitude":30.398981,"longitude":-97.746804,"speed":8.256416399999999,"timestamp":"2016-03-11T13:43:17.000Z","trip_id":"1457671273"} {"heading":273.995431,"latitude":30.398984,"longitude":-97.746846,"speed":14.5477296,"timestamp":"2016-03-11T13:43:18.000Z","trip_id":"1457671273"} {"heading":273.995431,"latitude":30.398987,"longitude":-97.746895,"speed":16.8379884,"timestamp":"2016-03-11T13:43:19.000Z","trip_id":"1457671273"} ... ```
- To confirm whether the message arrived successfully, open the Send Car Probe Data tab in the Node-RED flow editor and view the debug messages, as outlined in the following screen capture:
-
Open the Send Job Request node tab in the Node-RED flow editor.
-
Click the inject icon and wait for the workflow request to complete. After the request is completed, view the debug output message that is generated for the job request. Make a note of the
job_id
value.
- To view the analysis results, proceed to "Tutorial Part 2: Displaying the analysis result on a Java client map UI".
As an alternative to step 7, you can set up and run the Java client in the Eclipse environment instead.
Before you begin: Install the Eclipse with the Eclipse Maven plugin. This is required to import and run the sample in Eclipse. For more information about Java and Eclipse, click here.
-
Clone the car-data-management project using git clone as follows;
git clone https://github.com/IBM-Bluemix/car-data-management
-
Import the car-data-management project into Eclipse using the File >Import... >General >Existing Projects into Workspace option in Eclipse.
-
Open the
config/device.prop
file and enter theOrganization-ID
andAuthentication-Token
that you made a note in step 4.
-
To build and run, right-click on the project, and select Run As > Maven test.
-
To confirm whether the message was successfully set to Watson IoT Platform, open the console tab of the Eclipse client, and view the log information.
- To configure analysis parameters, see Administering Driver Behavior.
- To customize the car probe data further:
- Add more devices (vehicles) to Watson IoT Platform in accordance with step 13 - 18 in the "Step 4: Set up the Watson IoT Platform instance" section.
- Format your own car probe data, ensuring that you match the format in: CarProbeSample.json.
- Replace
CarProbeSample.json
on the Eclipse project. - Replace the analysis arguments
from
andto
with your custom car probe data in this section.