我正在运行一个
xbee
代码,其中有一个计划程序每 1 分钟运行一次。该调度程序查询网络并获取在线的 xbee
设备。下面是代码:
def search_devices_in_nw():
log_debug.error("Discovery process starting....")
net = device.get_network()
net.start_discovery_process(deep=True, n_deep_scans=1)
while net.is_discovery_running():
time.sleep(0.5)
active_nodes = net.get_devices()
print(active_nodes)
schedule.every(1).minutes.do(search_devices_in_nw)
while device.is_open():
schedule.run_pending()
我的
xbee
网络中有两台设备,运行此代码,给出 2 个正确的 MAC 地址。但如果我将其中一台 xbee 设备离线,它仍然会给出 2 个在线 mac 地址的结果,这是不正确的。
如果我停止我的代码并重新启动它,那么它会在线显示 1 个 mac 地址。我不确定为什么代码不能正常工作。任何人都可以帮助我吗?请帮忙。谢谢
文档页面:https://xbplib.readthedocs.io/en/latest/user_doc/discovering_the_xbee_network.html#discovernetwork
根据文档,“所有发现的 XBee 节点都存储在 XBeeNetwork 实例中。”
但是您也可以在启动新发现之前,使用 clear()
对象上的
XBeeNetwork
方法来清除节点列表:
[...]
# Instantiate a local XBee object.
xbee = XBeeDevice(...)
[...]
# Get the XBee network object from the local XBee.
xnet = xbee.get_network()
# Discover XBee devices in the network and add them to the list of nodes.
[...]
# Clear the list of nodes.
xnet.clear()
[...]