Giter Site home page Giter Site logo

node-serial-obd's Introduction

serial-obd 0.2.2

This version will only receive updates that were done in bluetooth-obd. On request I will update/sync this module with bluetooth-obd as this version is less-used.

Serial communication for OBD-II ELM327 devices.

This node module lets you communicate over a serial port with OBD-II ELM327 Connectors using Node.js.

Limitations

  • Only tested on Ubuntu
  • Only tested with rfcomm, and not with actual serial port yet.
  • Only tested on ELM327 devices.
  • Not all OBD-II Commands are implemented yet.

Use bluetooth-obd if you use a bluetooth OBD-II Connector!

Pre-requests

  • If it's a Bluetooth ELM327, then it should already be paired and connected with rfcomm connect!
  • You might need to run it with SUDO! (If it says: serial port X is not ready!)

Install

npm install serial-obd

Documentation

Basic usage

var OBDReader = require('serial-obd');
var options = {};
options.baudRate = 115200;
var serialOBDReader = new OBDReader("/dev/rfcomm0", options);
var dataReceivedMarker = {};

serialOBDReader.on('dataReceived', function (data) {
    console.log(data);
    dataReceivedMarker = data;
});

serialOBDReader.on('connected', function (data) {
    this.addPoller("vss");
    this.addPoller("rpm");
    this.addPoller("temp");
    this.addPoller("load_pct");
    this.addPoller("map");
    this.addPoller("frp");

    this.startPolling(2000); //Polls all added pollers each 2000 ms.
});

serialOBDReader.connect();

API

OBDReader

Event: ('dataReceived', data)

Emitted when data is read from the OBD-II connector.

  • data - the data that was read and parsed to a reply object

Event: ('connected')

Emitted when the connection is set up (port is open).

  • data - the data that was read and parsed to a reply object

OBDReader(portName, options)

Creates an instance of OBDReader.

Params:
  • string portName Port that will be connected to. For example: "/dev/rfcomm0"

  • Object options Object that contains options, e.g.: baudrate, databits, stopbits, flowcontrol. Same options serialport module uses.

getPIDByName(Name)

Find a PID-value by name.

Params:
  • name Name of the PID you want the hexadecimal (in ASCII text) value of.
Return:
  • string PID in hexadecimal ASCII

parseOBDCommand(hexString)

Parses a hexadecimal string to a reply object. Uses PIDS. (obdInfo.js)

Params:
  • string hexString Hexadecimal value in string that is received over the serialport.
Return:
  • Object reply - The reply.

  • string reply.value - The value that is already converted. This can be a PID converted answer or "OK" or "NO DATA".

  • string reply.name - The name. --! Only if the reply is a PID.

  • string reply.mode - The mode of the PID. --! Only if the reply is a PID.

  • string reply.pid - The PID. --! Only if the reply is a PID.

connect()

Connect/Open the serial port and add events to serialport. Also starts the intervalWriter that is used to write the queue.

disconnect()

Disconnects/closes the port.

write(message, replies)

Writes a message to the port. (Queued!) All write functions call this function.

Params:
  • string message The PID or AT Command you want to send. Without \r or \n!
  • number replies The number of replies that are expected. Default = 0. 0 --> infinite

requestValueByName(name)

Writes a PID value by entering a pid supported name.

Params:
  • string name Look into obdInfo.js for all PIDS.

addPoller(name)

Adds a poller to the poller-array.

Params:
  • string name Name of the poller you want to add.

removePoller(name)

Removes an poller.

Params:
  • string name Name of the poller you want to remove.

removeAllPollers()

Removes all pollers.

writePollers()

Writes all active pollers.

startPolling()

Starts polling. Lower interval than activePollers * 50 will probably give buffer overflows.

Params:
  • number interval Frequency how often all variables should be polled. (in ms) If no value is given, then for each activePoller 75ms will be added.

stopPolling()

Stops polling.

LICENSE

This module is available under a Apache 2.0 license, see also the LICENSE file for details.

node-serial-obd's People

Contributors

andreasbotsikas avatar damoclark avatar ericsmekens avatar frankzz avatar joouis avatar stefannilsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-serial-obd's Issues

MAF calculation error

I found i small math error in the formula!

On Line 103 in obdinfo.js
return (parseInt(byteA, 16) * 256.0) + (parseInt(byteB, 16) / 100);
A*256+(B/100)

This formular is slightly wrong

This is the fix!
return ((parseInt(byteA, 16) * 256.0) + parseInt(byteB, 16)) / 100;
((A*256)+B)/100

Thanks for fixing!
=)

Need help to start

Got this issue:

`pi@raspberrypi:~/project/node-serial-obd/example $ node test.js
/home/pi/project/node-serial-obd/lib/obd.js:155
this.serial = new SerialPort(this.SERIAL_PORT, this.OPTIONS);
^

TypeError: SerialPort is not a constructor
at OBDReader.connect (/home/pi/project/node-serial-obd/lib/obd.js:155:19)
at Object. (/home/pi/project/node-serial-obd/example/test.js:46:17)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)
`

need help

Timing

Timing new responses should be improved.

Contact

Do you have a discord I can message you on?

Tuning PIDs

Calculated LOAD Value
Engine Coolant Temperature
Short Term Fuel Trim - Bank 1,3
Long Term Fuel Trim - Bank 1,3
Short Term Fuel Trim - Bank 2,4
Long Term Fuel Trim - Bank 2,4
Fuel Rail Pressure (gauge)
Intake Manifold Absolute Pressure
Engine RPM
Vehicle Speed Sensor
Intake Air Temperature
Air Flow Rate from Mass Air Flow Sensor
Absolute Throttle Position
Ignition Timing Advance for #1 Cylinder
Ignition Timing Advance for #2 Cylinder
Ignition Timing Advance for #3 Cylinder
Ignition Timing Advance for #4 Cylinder
Ignition Timing Advance for #5 Cylinder
Ignition Timing Advance for #6 Cylinder
Ignition Timing Advance for #7 Cylinder
Ignition Timing Advance for #8 Cylinder
Knock detection for #1 Cylinder
Knock detection for #2 Cylinder
Knock detection for #3 Cylinder
Knock detection for #4 Cylinder
Knock detection for #5 Cylinder
Knock detection for #6 Cylinder
Knock detection for #7 Cylinder
Knock detection for #8 Cylinder

What are some other good PIDs to log for tuning?

Send OBD 0902 VIN command over WiFi

I have been able to connect to my Wifi OBDII adapter using Matt Parson's WifiWizard library. But because I'm writing a AngularJS/ionic application for Android I am not able to use your node module directly for sending and receiving OBDII commands.

I tried unsuccessfully to use browserify CDN to make the library available on the client side. I really only need to be able to pull the vehicle's VIN number though so this all seems like overkill. Can you recommend a way of implementing this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.