evanshortiss / obd-parser

Write commands to a generic OBDII connection and parse responses
Other
37 stars 17 forks source link

Example #2

Closed scramble45 closed 7 years ago

scramble45 commented 8 years ago

`var pollers = obd.pollers; ^

ReferenceError: obd is not defined at Object. (/node_code/obd-parser/obd2.js:3:15) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:141:18) at node.js:933:3 `

When using the example.

evanshortiss commented 8 years ago

@scramble45 well spotted, it should be:

var parser = require('obd-parser');
var pollers = parser.pollers;
scramble45 commented 8 years ago

`2016-05-18T20:39:12.017Z INF [obd-parser]: initialising obd-parser 2016-05-18T20:39:12.030Z DBG [connnection]: setting connnection function 2016-05-18T20:39:12.036Z DBG [obd-serial-connection]: creating serialport connection 2016-05-18T20:39:12.039Z DBG [obd-serial-connection]: opening a serial connection 2016-05-18T20:39:12.051Z INF [pollers]: getting poller of type "undefined" 2016-05-18T20:39:12.052Z DBG [pollers]: returning poller "ENGINE_RPM" by creating new instance 2016-05-18T20:39:12.053Z DBG [pids]: finding pid by "constname", for value "ENGINE_RPM" { getPollerTypes: [Function], getPoller: [Function], removePoller: [Function] } /node_code/obd-parser/obd2.js:33 var rpm = pollers.getPollerByPid('010C'); ^

TypeError: pollers.getPollerByPid is not a function at Object. (/node_code/obd-parser/obd2.js:33:19) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:141:18) at node.js:933:3 `

Looks like it should be something like this; var rpm = parser.pids.getByPid('010C');

scramble45 commented 8 years ago

onPollerData is not defined, trying to hunt down what its the new function is called to get data:

`2016-05-18T21:07:34.370Z INF [obd-parser]: initialising obd-parser 2016-05-18T21:07:34.385Z DBG [connnection]: setting connnection function 2016-05-18T21:07:34.391Z DBG [obd-serial-connection]: creating serialport connection 2016-05-18T21:07:34.395Z DBG [obd-serial-connection]: opening a serial connection 2016-05-18T21:07:34.409Z INF [pollers]: getting poller of type "undefined" 2016-05-18T21:07:34.410Z DBG [pollers]: returning poller "ENGINE_RPM" by creating new instance 2016-05-18T21:07:34.411Z DBG [pids]: finding pid by "constname", for value "ENGINE_RPM" [ { constname: 'ENGINE_COOLANT_TEMPERATURE', name: 'Engine Coolant Temperature', pid: '05' }, { constname: 'FUEL_LEVEL_INPUT', name: 'Fuel Level Input', pid: '2F' }, { constname: 'ENGINE_RPM', name: 'Engine RPM', pid: '0C' }, { constname: 'VEHICLE_SPEED', name: 'Vehicle Speed', pid: '0D' } ] 2016-05-18T21:07:34.492Z DBG [pids]: finding pid by "fullpid", for value "010C" /node_code/obd-parser/obd2.js:38 rpm.on('data', onPollerData); ^

ReferenceError: onPollerData is not defined at Object. (/node_code/obd-parser/obd2.js:38:16) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:141:18) at node.js:933:3 `

Thanks

evanshortiss commented 8 years ago

@scramble45 what's the current issue you're seeing? Is it ReferenceError: onPollerData is not defined? If so then that's because you need to write that function 😄

evanshortiss commented 8 years ago

Here's an example:

function onPollerData (data) {
  // Log the data Object returned by the poller
  console.log(data.value)      // The converted value e.g 4000
  console.log(data.pretty)     // The prettified value e.g 4000rpm
  console.log(data.byteString) // The bytes the ECU sent us e.g 410C1B56
}

rpmPoller.on('data', onPollerData);
scramble45 commented 8 years ago

Thanks for that, I thought it may have been a function already written. Good to know: Getting closer to getting this working:

var getObdConnector = require('obd-parser-serial-connection');
var parser = require('obd-parser');
var pollers = parser.pollers;

// Intialise our module and pass a configured connection function
parser.init({
  connectorFn: getObdConnector({
    serialPath: '/dev/ttyS0',
    serialOpts: {
      baudrate: 9600
    }
  })
});

// Poll for engine rpm three times per second
var rpmPoller = pollers.getPoller({
  constname: 'ENGINE_RPM',
  refreshRate: 3
});

rpmPoller.on('data', function onPollerData (data) {
  // Log the data Object returned by the poller
  console.log(data.value)      // The converted value e.g 4000
  console.log(data.pretty)     // The prettified value e.g 4000rpm
  console.log(data.byteString) // The bytes the ECU sent us e.g 410C1B56
});
//console.dir(pollers);

console.log(require('obd-parser').pollers.getPollerTypes());

var rpm = parser.pids.getByPid('010C');

rpmPoller.on('data', onPollerData);

function onPollerData (data) {
  // Log the data Object returned by the poller
  console.log(data.value)      // The converted value e.g 4000
  console.log(data.pretty)     // The prettified value e.g 4000rpm
  console.log(data.byteString) // The bytes the ECU sent us e.g 410C1B56
}

This is what I get Now: `2016-05-19T21:27:23.157Z INF [obd-parser]: initialising obd-parser 2016-05-19T21:27:23.169Z DBG [connnection]: setting connnection function 2016-05-19T21:27:23.175Z DBG [obd-serial-connection]: creating serialport connection 2016-05-19T21:27:23.179Z DBG [obd-serial-connection]: opening a serial connection 2016-05-19T21:27:23.191Z INF [pollers]: getting poller of type "undefined" 2016-05-19T21:27:23.192Z DBG [pollers]: returning poller "ENGINE_RPM" by creating new instance 2016-05-19T21:27:23.193Z DBG [pids]: finding pid by "constname", for value "ENGINE_RPM" [ { constname: 'ENGINE_COOLANT_TEMPERATURE', name: 'Engine Coolant Temperature', pid: '05' }, { constname: 'FUEL_LEVEL_INPUT', name: 'Fuel Level Input', pid: '2F' }, { constname: 'ENGINE_RPM', name: 'Engine RPM', pid: '0C' }, { constname: 'VEHICLE_SPEED', name: 'Vehicle Speed', pid: '0D' } ] 2016-05-19T21:27:23.267Z DBG [pids]: finding pid by "fullpid", for value "010C" events.js:154 throw er; // Unhandled 'error' event ^

Error: Port is opening at SerialPort.open (/node_code/obd-parser/node_modules/serialport/lib/serialport.js:198:24) at SerialPort. (/node_code/obd-parser/node_modules/serialport/lib/serialport.js:176:12) at _combinedTickCallback (node.js:370:9) at process._tickCallback (node.js:401:11) at Function.Module.runMain (module.js:449:11) at startup (node.js:141:18) at node.js:933:3`

evanshortiss commented 8 years ago

I can't be sure about that error since it's coming from the serialport module, and not obd-parser. I'd advise making sure the options you pass here are correct:

parser.init({
  connectorFn: getObdConnector({
    serialPath: '/dev/ttyS0',
    serialOpts: {
      baudrate: 9600
    }
  })
});

failing that verify the cable used is working, and maybe take a look at the code at _/node_code/obd-parser/nodemodules/serialport/lib/serialport.js:198:24 to see what might be causing it to throw that error :smile: