OpenZWave / node-openzwave-shared

OpenZWave addon for Node.js (all versions) including management and security functions
Other
199 stars 113 forks source link

Not properly disconnecting? #347

Closed wmmihaa closed 4 years ago

wmmihaa commented 4 years ago

Hi, I'm running openzwave-shared@1.5.6 and see some weird behavior on every other time I start the application.

My code is pretty much copy/paste from the samples:

zwave.on('scan complete', function () {
    console.log('scan complete');
    if (zwave.hasOwnProperty('beginControllerCommand')) {
        console.log('using legacy mode (OpenZWave version < 1.3) - no security');
        zwave.beginControllerCommand('AddDevice', true);
    } else {
        console.log( 'using new security API');
        zwave.addNode(false);
    }
});

zwave.on('controller command', function (n, rv, st, msg) {
    console.log(`node==${n}, retval=${rv}, state=${st}, msg=${msg}`);
}

self.zwave.connect('/dev/ttyAMA0');

First time:

>scan complete
>using new security API
>node==0, retval=1, state=0, msg=AddDevice ControllerCommand - Starting
>node==0, retval=8, state=0, msg=AddDevice ControllerCommand - Failed
>node==0, retval=7, state=0, msg=AddDevice ControllerCommand - Completed

After the first run, all seems to work. I can control actuators and get value changed events when values are updated

Second time (after restarting the application):

>scan complete
>using new security API
>node==0, retval=1, state=0, msg=AddDevice ControllerCommand - Starting
>node==0, retval=4, state=0, msg=AddDevice ControllerCommand - Waiting

After the second run, I get 3 value changed if I manually switch on/off a switch, but I can not programmaticly set values.

Next time I run it will work as the first time...

Update

This has nothing to do with zwave.addNode(false) or AddDevice event. I get the same behavior when commenting out the addNode call.

robertsLando commented 4 years ago

You have to call zwave.removeAllListeners() after disconnecting and rebind all events on reconnect

wmmihaa commented 4 years ago

Thanks!