Archive: I've connected my car to Salesforce.com

Archive: I've connected my car to Salesforce.com

As seen at Dreamforce 2013: Slideshare

Say you’re driving down the road. You’re in the middle of nowhere, and your check engine light goes on. Is the engine about to blow up or did you just leave your gas cap a bit loose? Can you keep driving it until you have time to make an appointment at your dealership, or do you need to head in to the closest repair shop right now?

What if your car was connected to the Cloud, and had been logging sensor data for the past 30 days? What if it could automatically file a Case with your local dealership with the Diagnostic Trouble Codes from your car and all that log data attached? What if the Service department could give you a call to schedule an appointment to get it fixed, so you don’t even have to remember to call them? Since they have all the automotive log information they need to diagnose the problem before you even show up, they can even tell you what’s wrong over the phone and quote you an estimate for the repair.

Here’s a Raspberry Pi DIY project that does just that.

First off, start with the information in Connecting your Raspberry Pi to a Bluetooth OBD-II Adapter to get the basics set up. You’ll then need to install Node.js on your Raspberry Pi to run the scripts from https://github.com/tomgersic/obd2pi.

Both of these scripts run continuously on the Raspberry Pi. obd.js handles offline logging of OBD-II messages to the SD card, and obdsync.js handles pushing those messages up to the API hosted on Heroku.com.

obd.js

Reads from an OBD-II adapter connected to a serial (/dev/rfcomm0) port and logs messages to a TingoDB Database. TingoDB is a lightweight file-base NoSQL database that implements the same function calls as MongoDB. So, you can think of it as a MongoDB database without needing to run a MongoDB Server.

Here’s a video showing the logger script running:

Started from the command line with “node obd.js”

Response mode 43 is a response to a mode “03” request for Diagnostic Trouble Codes that would cause the “Check Engine Light”, or Malfunction Indicator Lamp (MIL) to light up. Response mode 41 is a response to a “01” request for real-time sensor data. The PID indicates the hex code associated with the sensor being queried. 0D is the Vehicle Speed Sensor (vss), 0C shows current engine RPM, 05 is the coolant temperature, and 04 is a percentage value indicating current load on the engine. You can see in this sensor data that my car is basically idling at around 700 RPM, and speed (VSS) is 0.

> { mode: ’43’,  
>  name: ‘requestdtc’,  
>  value: { errors: [ ‘P0444′, ‘-‘, ‘-‘ ] } }  
>  { mode: ’41’, pid: ‘0D’, name: ‘vss’, value: 0 }  
>  { mode: ’41’, pid: ‘0C’, name: ‘rpm’, value: 715 }  
>  { mode: ’41’, pid: ’05’, name: ‘temp’, value: 60 }  
>  { mode: ’41’, pid: ’04’, name: ‘load_pct’, value: 5.46875 }  
>  { mode: ’43’,  
>  name: ‘requestdtc’,  
>  value: { errors: [ ‘P0444′, ‘-‘, ‘-‘ ] } }  
>  { mode: ’41’, pid: ‘0D’, name: ‘vss’, value: 0 }  
>  { mode: ’41’, pid: ‘0C’, name: ‘rpm’, value: 714 }  
>  { mode: ’41’, pid: ’05’, name: ‘temp’, value: 62 }  
>  { mode: ’41’, pid: ’04’, name: ‘load_pct’, value: 5.078125 }  
>  { mode: ’43’,  
>  name: ‘requestdtc’,  
>  value: { errors: [ ‘P0444′, ‘-‘, ‘-‘ ] } }  
>  { mode: ’41’, pid: ‘0D’, name: ‘vss’, value: 0 }  
>  { mode: ’41’, pid: ‘0C’, name: ‘rpm’, value: 715 }  
>  { mode: ’41’, pid: ’05’, name: ‘temp’, value: 63 }  
>  { mode: ’41’, pid: ’04’, name: ‘load_pct’, value: 4.6875 }

obdsync.js

Node.js Script to send the logged OBD-II Messages from obd.js to Cloud API from Raspberry Pi.

API is [YOUR DOMAIN]/log/:json

Started from the command line with “node obdsync.js your.domain.here.com”

An example payload to the API would be something like this:

{ obddata: { mode: ’41’, pid: ’04’, name: ‘load_pct’, value: 10.9375 },  
 vin: ‘JF1BJ673XPH968228′,  
 localdatetime: Sun Nov 10 2013 17:23:10 GMT+0000 (UTC),  
 _id: 160 }

Logging information as the sync script pushes data up to the server:

> Syncing… 3 records remain  
>  { obddata: { mode: ’41’, pid: ’04’, name: ‘load_pct’, value: 11.328125 },  
>  vin: ‘JF1BJ673XPH968228′,  
>  localdatetime: Sun Nov 10 2013 17:25:55 GMT+0000 (UTC),  
>  _id: 180 }  
>  200  
>  success  
>  Syncing… 2 records remain  
>  { obddata: { mode: ’43’, name: ‘requestdtc’, value: { errors: [Object] } },  
>  vin: ‘JF1BJ673XPH968228′,  
>  localdatetime: Sun Nov 10 2013 17:26:05 GMT+0000 (UTC),  
>  _id: 181 }  
>  200  
>  success  
>  Syncing… 1 records remain  
>  { obddata: { mode: ’41’, pid: ‘0D’, name: ‘vss’, value: 0 },  
>  vin: ‘JF1BJ673XPH968228′,  
>  localdatetime: Sun Nov 10 2013 17:26:10 GMT+0000 (UTC),  
>  _id: 182 }  
>  200  
>  success

server.js

The missing piece, of course, is the code for the server API being hosted in Heroku. You can find that here: https://github.com/tomgersic/obd2server

Simple API to receive OBD-II Messages and log them in mongojs, with Diagnostic Trouble Codes (DTC) being uploaded as Cases to Salesforce.com.

Also contains a simple log viewing API at http://[SOMEDOMAINHERE.COM]/view/[VIN #]

This is intended for demo/POC purposes only. There’s literally no security here, so you’ll want to add some security measures if you’re going to use this in a production environment.

Example log GET request

http://[SOMEDOMAINHERE.COM]/log/{ obddata: { mode: ’41’, pid: ’04’, name: ‘loadpct’, value: 10.9375 },vin: ‘JF1BJ673XPH968228′,localdatetime: Sun Nov 10 2013 17:23:10 GMT+0000 (UTC),id: 160 }

Salesforce.com

The server-side Logger API takes care of logging all messages in a MongoDB database, but if any Diagnostic Trouble Codes are created, it will also create a Case in Salesforce.com, thus completing the alert to the manufacturer or dealer that your car is experiencing a problem.

Dreamforce

Want to learn more? I’ll be presenting this at Dreamforce 2013. Come see!

  • Monday, November 18th: 1:45 PM – 2:30 PM
  • Moscone Center West, 2022