OpenZWave / openzwave-dotnet-uwp

An Open-ZWave wrapper for use with .NET or UWP apps
Apache License 2.0
45 stars 27 forks source link

how to correctly use AddNode() / RemoveNode() #13

Closed yesyesuk closed 7 years ago

yesyesuk commented 7 years ago

Hi, I have another question. I'm not really getting responses on the OpenZWave Google group, so I'm hoping someone here can help me, please?

I've made progress with implementing ZWave in my system. I'm at a point now where I want to implement adding (including) and removing (excluding) nodes without having to unplug the Z-Stick.

So I have a button that calls m_manager.AddNode(homeID, false) and one that calls m_manager.RemoveNode(homeID) to put the controller stick in inclusion/exclusion mode.

When I do that, I can add and remove a node. I get notifications of type ControllerCommand with the progress number in m_notification.Event. (by the way, did you not implement "enum OpenZWave::Driver::ControllerState" or can I just not find it?). Then I get a NodeNew notification.

So far so good. However, after including/excluding a node I get no further notifications at all.

Do I need to call anything to end the inclusion/exclusion mode and return to normal operation?

The OpenZWave API documentation for AddNode seems to imply that only one node can be added for each call to AddNode and then it would return to normal mode, but it's not quite clear. "Start the Inclusion Process to add a Node to the Network." - A node, as in one node...

dotMorten commented 7 years ago

I can't say for sure, but this part of the source code seems to indicate it will stop after the first one got added:

https://github.com/OpenZWave/open-zwave/blob/a1b24f962524c1940cc892e4af3791581c19d557/cpp/src/Driver.cpp#L3922

What were you expected in addition to the "NodeNew" notification?

yesyesuk commented 7 years ago

I would expect it to return to normal operation where I can communicate with all included nodes. Instead, after including a new node, I get no new notifications at all from any node. I need to restart the application to get things like ValueChanged or NodeEvent notifications at all.

It's quite possible that I'm doing something wrong, I just can't find what it is...

dotMorten commented 7 years ago

I don't get that. My network continues to operate fine while waiting for a node to get added.

yesyesuk commented 7 years ago

That's weird. I tested a bit more. When I call Manager.AddNode() or RemoveNode() notifications stop. When I then call Manager.CancelControllerCommand() (without including/excluding a node) it works again. If I actually include a node, the node gets added but Value related notifications do not resume. CancelControllerCommand() fails (returns true but the ControllerCommand notification has the Failed state in Event). When I tried to exclude a node after calling RemoveNode() the node got excluded and for some reason another node also got excluded.

After including or excluding a node this way I need to call RemoveDriver and AddDriver to make it all work again (or restart the app, which does the same thing).

Could this be related to the controller stick I'm using? Which one are you using? I have the Aeotec Z-Stick S2.