Skip to content

Commit

Permalink
add monitor command. use new obd-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
evanshortiss committed Mar 16, 2017
1 parent 762c52a commit 78a1e90
Show file tree
Hide file tree
Showing 9 changed files with 1,744 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage
typings
*.d.ts
*.js
*.rdb
*.rdb
outputs/
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# obd-parser-cli

A CLI tool that can interface with On Board Diagnostics (OBD) of vehicles.
A CLI tool that can interface with On Board Diagnostics (OBD II) of vehicles.

## Testing
## Compatibility and Testing
This software has only been tested with a Volkswagen MK6 GTI. Your success in
using this software with your vehicle might vary.

Expand Down Expand Up @@ -57,29 +57,35 @@ the help menu:
```
$ obd --help
🚔 OBD CLI 🚘
🚔 OBD CLI 🚘
Usage: index [options] [command]
Commands:
list list supported pids that can be passed to "poll" commands
poll <pid> [pids...] poll for an OBD value(s) specified by <pid> or a list of pids
list list supported pids that can be passed to "poll" commands
poll <pid> [pids...] poll for an OBD value(s) specified by <pid> or a list of pids
monitor <pid:interval> [pid:interval...] similar to poll, but continously checks PID values every n milliseconds,
e.g 0C:1000 will get RPM every 1000 milliseconds
Options:
-h, --help output usage information
-V, --version output the version number
-c, --connection <string> type of connection, valid options are "fake" or "serial"
-b, --baudrate <number> control connection baudrate, e.g 38400
-o, --outdir <string> loation to create folder containing monitor results
-i, --interface <name> the interface to use for connection, e.g /dev/tty.serialusb
```

### Listing PIDs (list)

Use the list command to view PIDs that can be read from vehicles. Currently only
a handful are supported. Here's how you can view them:
Use the list command to view PIDs that can be read from vehicles. Currently
only a handful are supported by this module and certain vehicles will not
support all PIDS either.

Here's how you can view them:

```
$ obd list
Expand All @@ -92,6 +98,15 @@ Available PIDs for "poll" commands are:
0C - Engine RPM
05 - Engine Coolant Temperature
0D - Vehicle Speed
04 - Calculated Engine Load
0A - Fuel Pressure
0B - Intake Manifold Absolute Pressure
0F - Intake Air Temperature
10 - MAF Air Flow Rate
11 - Throttle Position
1C - OBD Standard
03 - Fuel System Status
20 - Supported PIDs
Example command usage: "obd poll 2F"
Expand Down Expand Up @@ -128,7 +143,7 @@ Results:

The above example uses the "fake" connection type and therefore returns
randomised values for the PIDs you requested. If you'd like to connect via
a serial conncetion you can try the following (macOS) example:
a serial conncetion you can try the following (macOS tested) example:

```
$ obd poll -c serial -b 38400 -i /dev/tty.serialusb "Engine RPM"
Expand All @@ -143,4 +158,49 @@ Results:
┌────────────┬────────┐
│ Engine RPM │ 835.50 │
└────────────┴────────┘
```

### Monitor

The monitor command is similar to poll, but instead it prints lines of JSON
continuously until the process is killed. You can use the `--output` option
to specify a directory to write JSON files to that will contain this data.
This creates a folder in the specified `output` directory with the current
date, and then writes the JSON to folders that represent each trip taken.
Inside each folder a JSON file is created. The name of the file will be
0.json by default. Once this file reaches ~128KB in size a new file, 1.json
will be created, and so on until the process is killed.

Here's a sample command and output data:

```
$ obd monitor 0d:100 0c:1000 05:5000 -c serial -i /dev/tty.usbserial -b 38400
🚔 OBD CLI 🚘
Connecting via "fake" type...
OBD module intialised...
{"ts":"2017-03-15T16:57:18.296Z","bytes":"410D26","value":38,"counter":715,"pretty":"38km/h","name":"Vehicle Speed","pid":"0D"}
{"ts":"2017-03-15T16:57:18.318Z","bytes":"410C16CA","value":1458.5,"counter":716,"pretty":"1458.5rpm","name":"Engine RPM","pid":"0C"}
{"ts":"2017-03-15T16:57:18.946Z","bytes":"410F43","value":27,"counter":717,"pretty":"27°C","name":"Intake Air Temperature","pid":"0F"}
{"ts":"2017-03-15T16:57:19.295Z","bytes":"410D26","value":38,"counter":718,"pretty":"38km/h","name":"Vehicle Speed","pid":"0D"}
{"ts":"2017-03-15T16:57:19.316Z","bytes":"410C1684","value":1441,"counter":719,"pretty":"1441rpm","name":"Engine RPM","pid":"0C"}
{"ts":"2017-03-15T16:57:20.296Z","bytes":"410D22","value":34,"counter":720,"pretty":"34km/h","name":"Vehicle Speed","pid":"0D"}
{"ts":"2017-03-15T16:57:21.235Z","bytes":"410572","value":74,"counter":722,"pretty":"74°C","name":"Engine Coolant Temperature","pid":"05"}
```

If using the `--output` option, then the created folder structure might look
as follows if you had two trips in a given day:

```
| |____
| | |____2017-03-12
| | | |____2ee5ff94-a02d-4791-9cd8-8b0d9770c34f
| | | | |____0.json
| | | |____599d7463-c568-441d-b6f7-86ea92ea3e59
| | | | |____0.json
| | | | |____1.json
| | | | |____2.json
| | | | |____3.json
```
22 changes: 20 additions & 2 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import * as Promise from 'bluebird';

function onError (e) {
console.log('uncaught error', e);
function onError (e: Error) {
console.log('uncaught error', e.stack);
}

Promise.onPossiblyUnhandledRejection(onError)
Expand All @@ -18,13 +18,16 @@ g.program = program;

import poll from '../lib/command-poll';
import list from '../lib/command-list';
import monitor from '../lib/command-monitor';

console.log('\n🚔 OBD CLI 🚘');

program
.version(require('../package.json').version)
.option('-c, --connection <string>', 'type of connection, valid options are "fake" or "serial"')
.option('-b, --baudrate <number>', 'control connection baudrate, e.g 38400')
.option('-o, --outdir <string>', 'loation to create folder containing monitor results')
.option('-z, --zip', 'if this option is passed then output files will be zipped')
.option(
'-i, --interface <name>',
'the interface to use for connection, e.g /dev/tty.serialusb'
Expand All @@ -47,6 +50,21 @@ program
poll([pid].concat(extraPids || []));
});

program
.command('monitor <pid:interval> [pid:interval...]')
.description(
`similar to poll, but continously checks PID values every n milliseconds,
e.g 0C:1000 will get RPM every 1000 milliseconds`
)
.action(function (pid:string, extraPids:string[]) {
if (!pid) {
console.log('please specify at least 1 pid, e.g "obd poll -c fake 2F')
process.exit(1);
}

monitor([pid].concat(extraPids || []));
});

if (!process.argv.slice(2).length) {
program.outputHelp();
} else {
Expand Down
Loading

0 comments on commit 78a1e90

Please sign in to comment.