Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement reconnection to ZWave serial stick (#979) #980

Closed
wants to merge 1 commit into from
Closed

Implement reconnection to ZWave serial stick (#979) #980

wants to merge 1 commit into from

Conversation

dottedmag
Copy link

Keep probing the port if the stick is not ready on startup or an error has been
received from the serial port.

@dottedmag
Copy link
Author

I haven't touched Java since 2002, so please let me know if something has changed since.

@cdjackson
Copy link
Collaborator

Thanks - just a few initial comments that will need to be resolved before proceeding.

I don't think this will work properly. How do you reinitialise the device once it is plugged in? There is a lot more to do than just to initialise the serial port. You probably need to close down the controller and restart it - or at leat ensure that the reinitialisation is completed. This could be quite messy to achieve (although I've not looked at it, so maybe it's not too hard).

Please sign your commit and PR.

Please ensure any PR is against the development branch, and not master.

@dottedmag dottedmag changed the base branch from master to development August 23, 2018 21:10
Keep probing the port if the stick is not ready on startup or an error has been
received from the serial port.

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
@dottedmag
Copy link
Author

I have signed my commit, and moved PR against "development" branch, but how do I sign PR?

When a serial port is closed, SerialPortConnectorThread kicks in, trying to connect until it succeeds. Once it succeeds it calls initializeNetwork() that cares about initialization of stuff.

In original PR I have missed that initializeNetwork() assigned some member variables in ZWaveControlerHandler. On a second initialization they were rewritten, and previous values were not canceled/deactivated/shutdown, so it created some resource leaks.

Updated PR calls dispose() on serial port error to close all resources used by both ZWaveControllerHandler and ZWaveSerialHandler.

@cdjackson
Copy link
Collaborator

cdjackson commented Aug 23, 2018 via email

@dottedmag
Copy link
Author

I don't see where ZWaveController ever removes ZWaveNodes from itself, so I'll work on it a little bit more to understand.

@cdjackson
Copy link
Collaborator

cdjackson commented Aug 24, 2018 via email

@bodiroga
Copy link
Contributor

bodiroga commented Dec 5, 2018

Hi @dottedmag!

Are you still interested in supporting this feature? It would be really cool if we could add it for the next version of openHAB (2.5, not 2.4, of course). I have implemented a reconnect feature in my "tcp_controller" branch (https://github.com/bodiroga/org.openhab.binding.zwave/tree/tcp-controller) and it is working great.

My suggestion is to also modify the ZWaveThingHandler's bridgeStatusChanged method like this:

ZWaveControllerHandler bridgeHandler = (ZWaveControllerHandler) getBridge().getHandler();

if (bridgeStatusInfo.getStatus() != ThingStatus.ONLINE) {
    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, ZWaveBindingConstants.OFFLINE_CTLR_OFFLINE);
    logger.debug("NODE {}: Controller is not online.", nodeId, bridgeStatusInfo.getStatus());
    synchronized (pollingSync) {
        if (pollingJob != null) {
            pollingJob.cancel(true);
            pollingJob = null;
        }
    }
    controllerHandler = null;
    if (bridgeHandler != null) {
        bridgeHandler.removeEventListener(this);
    }
    return;
}

logger.debug("NODE {}: Controller is ONLINE. Starting device initialisation.", nodeId);

This is necessary to stop all threads and pending jobs from each node when USB stick is disconnected. Otherwise, your changes look good.

Thanks for your work!

@dottedmag
Copy link
Author

@bodiroga I definitely am, though I don't have the time right now to really read all the code and understand what else might be needed as @cdjackson has explained.

I'll rebase the patch to the new version, add with your changes and let it hang here for a while until I or someone else figures the rest out.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/share-z-wave-dongle-over-ip-usb-over-ip-using-ser2net-socat-guide/34895/165

@cdjackson
Copy link
Collaborator

Closing as no changes for 8 months and also superceded by #1210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants