Apollon77/smartmeter-obis

this.option.debug undefined

Closed this issue · 1 comments

node version v10.15.3
smartmeter-obis version 1.1.3
I take the modified usage example:

var SmartmeterObis = require('smartmeter-obis');

var options = {
'protocol': "D0Protocol",
'transport': "SerialRequestResponseTransport",
'transportSerialPort': "/dev/ttyUSB0",
'transportSerialBaudrate': 300,
'protocolD0WakeupCharacters': 40,
'protocolD0DeviceAddress': '',
'requestInterval': 20,
'obisNameLanguage': 'de',
'obisFallbackMedium': 1,
'debug': 0
};

function displayData(err, obisResult) {
if (err) {
// handle error
// if you want to cancel the processing because of this error call smTransport.stop() before returning
// else processing continues
return;
}
for (var obisId in obisResult) {
console.log(
obisResult[obisId].idToString() + ': ' +
SmartmeterObis.ObisNames.resolveObisName(obisResult[obisId], options.obisNameLanguage).obisName + ' = ' +
obisResult[obisId].valueToString()
);
}
}
var smTransport = SmartmeterObis.init(options, displayData);
smTransport.process();
setTimeout(smTransport.stop, 60000);

get the following result:
node test_as1440.js >> test.log
/home/pi/app/node_modules/smartmeter-obis/lib/transports/SerialRequestResponseTransport.js:329
if (this.options.debug === 2) this.options.logger('STOP');
^

TypeError: Cannot read property 'debug' of undefined
at Timeout.stop [as _onTimeout] (/home/pi/app/node_modules/smartmeter-obis/lib/transports/SerialRequestResponseTransport.js:329:22)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)

Reson is your code!

setTimeout(smTransport.stop, 60000);

This needs to be

setTimeout(() => smTransport.stop(), 60000);