Home/Support/Support Forum/Using xbee python library network modification callback function provided: how to get rid of ghost node

Using xbee python library network modification callback function provided: how to get rid of ghost node

0 votes
hello

From the xbee python library I am using the provided network modification callback function:


def my_callback(event_type, reason, node):
"""
Callback to notify about a new network modification event.

Args:
event_type (:class:`.NetworkEventType`): The type of modification.
reason (:class:`.NetworkEventReason`): The cause of the modification.
node (:class:`.AbstractXBeeDevice`): The node involved in the
modification (``None`` for ``NetworkEventType.CLEAR`` events)
"""


# Define the network modified callback.
def cb_network_modified(event_type, reason, node):
print(" >>>> Network event:")
print(" Type: %s (%d)" % (event_type.description, event_type.code))
print(" Reason: %s (%d)" % (reason.description, reason.code))

if not node:
return

print(" Node:")
print(" %s" % node)


xnet = local_device.get_network()

then add the callback:

xnet.add_network_modified_callback(cb_network_modified)


So, it prints out stuff accordingly when I add or update a device... so that's good. But my question is as follows:

How to have it also tell you when a device is powered off.. like I connect a device, then I unplug it's power cord... and it doesn't tell me about this event. I need to know that a device is shut off, retrieve that device's info, and remove it from the network in anticipation of a different device being connected in its place.

How to have the network modification callback function tell you when a device on the network just shut off.. it should right? because it is removed from the network.. but Im guessing that the program still see's that device in the xbeeNetwork object or cache or something...?

That's not useful to have a device that is not connected somehow remain in existence in the network object cache? A ghost node.

Let me know if I have explained my question well enough..

thanks
asked Aug 4 in XBee3 ZigBee by edunn106 New to the Community (24 points)

Please log in or register to answer this question.

1 Answer

0 votes
Edunn, No, there is no way to know that a radio has been powered off. The only thing I can think of is for you to run a Node discovery on a time table and compare the two.
answered Aug 4 by mvut Veteran of the Digi Community (13,472 points)
so even if it powers off... the network object stores the device as if it is still connected in cache?..
No, you would need to put the data into an array or file that you can compare it with.
yeah, gotchya.

what about having a button that you press just before you unplug the device? That button press would call a function that essentially does: device.remove_device(RemoteXBeeDevice)

but then in the documentation of that there function they have this note:

"Notice that this operation does not remove the remote XBee device from the actual XBee network; it just tells the network object that it will no longer contain that device. However, next time you perform a discovery, it could be added again automatically."

that right there confuses me absolutely. could you shed some light on how in the worldy world of worlds that works? it doesn't remove the device but instead tells the object that it will no longer contain that device? What?
You could use the Join notification instead of Node discovery. Then your function above would work. The reason being is that the Join notification occurs on power up and only then.
could you specify which function above? the .remove_device one?

Also how do you mean use join notification? that broadcasts a notification api frame for power-up and joining..
I am referring to your Removal node function.

Yes, that is what I was referring to.
ok thank you thank you.

anychance you could explain this note about the .remove_device function?

"Notice that this operation does not remove the remote XBee device from the actual XBee network; it just tells the network object that it will no longer contain that device. However, next time you perform a discovery, it could be added again automatically."

what does it mean to "remove a remote XBee device from the actual network" vs. "tells the network object that it will no longer contain that device"
also, which function are you referring to when you say "run a Node discovery"?
What it is saying is that this will remove the item from the list of devices. It is not really removing the radio from the network. You would have to remove it from the network or power it off to actually remove it.

I am referring to the Node Discovery (ND) command.
...