【问题标题】:How to get list of xbee devices in network using digi xbee Python如何使用digi xbee Python获取网络中的xbee设备列表
【发布时间】:2021-06-28 16:42:08
【问题描述】:

我有一个 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 address online,这是不正确的。

如果我停止我的代码并重新启动它,那么它会在线显示 1 个 mac 地址。我不确定为什么代码不能正常工作。任何人都可以在这方面帮助我。请帮忙。谢谢

文档页面:https://xbplib.readthedocs.io/en/latest/user_doc/discovering_the_xbee_network.html#discovernetwork

【问题讨论】:

    标签: radio xbee


    【解决方案1】:

    根据documentation,“所有发现的 XBee 节点都存储在 XBeeNetwork 实例中。”

    但您也可以在启动新发现之前对XBeeNetwork 对象使用clear() 方法clear the list of nodes

    [...]
    
    # 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()
    
    [...]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多