如何使用Digi XBee Python模块将API框架发送到远程XBee?

问题描述 投票:0回答:1

我正在将代码从Python XBee库移至Digi的Python XBee库,但是我无法在文档中找到有关如何将API框架发送到远程XBee的语法。我使用的是S1和S1 Pro设备,其中“本地”设备连接到Beaglebone,而“远程”设备则在野外独立运行。

我已经掌握了基本框架:

from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice, XBee64BitAddress

PORT = '/dev/ttyO1'
BAUD = 9600
API_FRAME = 'long-hex-string-here'

local_xbee = XBeeDevice(PORT, BAUD)
local_xbee.open()

# Instantiate a remote XBee device object.
remote_xbee = RemoteXBeeDevice(local_xbee, XBee64BitAddress.from_hex_string("0013A20040DD7DCD"))

# Transmit frame to remote_xbee - unsure of correct method and syntax
# perhaps XBeePacket.create_packet(hex string here)
# local_xbee.send_data(remote_xbee, "api frame here?")  ??

local_xbee.close()

但是我无法找到有关如何传输构造的API框架的语法。根据文档中的“简介”部分,我认为这是正确的方法。我对广播到网络上的所有设备都没有兴趣,而是单播通信。

python beagleboneblack xbee
1个回答
0
投票

当我可以使用它时,我有一些较旧的源模型。

我有一些WiFi Xbee模块,我使用了一些转换器板(基板)。我用它来将Xbee的通信从一台计算机连接到另一台计算机,例如通过USB(而非UART)将随机桌面随机连接到BeagleBone Black。因此,我将使用下面列出的源将我的USB加密狗连接到从BBB到另一个现场模块的Xbee通信中。

他们的I / O资料可以在这里找到:https://github.com/digidotcom/xbee-python/tree/master/examples/io

还...通过USB加密狗WiFi适配器板改变其源中的某些线路,这在向LED和其他传感器发出信号方面很有价值。

哦,您将需要他们现在所说的载板。这是我刚刚输入的适配器板。因此,如果您已经有了载板,请在Linux中使用lsusb作为命令来找到您的USB“名称”。

因此,例如,如果lsusb显示/dev/ttyUSB0,则为端口标识。

并且您可以使用lsusb中的该部分,然后在Digi的xtcu软件中更改xbee模块。

from digi.xbee.devices import XBeeDevice
from digi.xbee.io import IOLine, IOMode
import time
import threading

# TODO: Replace with the serial port where your local module is connected to.
PORT = "/dev/ttyUSB0"
# TODO: Replace with the baud rate of your local module.
BAUD_RATE = 9600

REMOTE_NODE_ID = "Xbee_B"

IOLINE_IN = IOLine.DIO2_AD2
IOLINE_OUT = IOLine.DIO4_AD4

def main():
    print(" +-----------------------------------------------+")
    print(" | XBee Python Library Get/Set Remote DIO Sample |")
    print(" +-----------------------------------------------+\n")

    stop = False
    th = None

    local_device = XBeeDevice(PORT, BAUD_RATE)

    try:
        local_device.open()
        print("local device: ", local_device.get_node_id())
        # Obtain the remote XBee device from the XBee network.
        xbee_network = local_device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if local_device is None:
            print("Could not find the remote device")
            exit(2)

        def io_detection_callback():
            while not stop:
                # Read the digital value from the input line.
                io_value = remote_device.get_dio_value(IOLINE_IN)
                print("%s: %s" % (IOLINE_IN, io_value))

                # Set the previous value to the local output line.
                local_device.set_dio_value(IOLINE_OUT, io_value)

                time.sleep(2)

        th = threading.Thread(target=io_detection_callback)

        remote_device.set_io_configuration(IOLINE_IN, IOMode.DIGITAL_IN)

        local_device.set_io_configuration(IOLINE_OUT, IOMode.DIGITAL_OUT_HIGH)

        time.sleep(1)
        th.start()

        input()

    finally:
        stop = True
        if th is not None and th.is_alive():
            th.join()
        if local_device is not None and local_device.is_open():
            local_device.close()


if __name__ == '__main__':
    main()

所以,请参见源代码的PORT =“ / dev / ttyUSB0”部分?

在这里,我将Xbee模块连接到载板,然后通过USB将载板连接到BBB。

嗯,这可能不会回答问题,但是会提供更多有关如何处理Digi设备/模块的见解。

我还认为,如果您想在带有Xbee和BeagleBone Black的UART通信方向上冒险,可能会更加复杂。我将继续搜索我的文本。

P.S。本书介绍了一些方法(实验10和实验16),“ BBB”与UART,Xbee的连接以及通信方法。本书中的所有交流思想都太深入了,仅此而已:

The Hands-on XBEE Lab Manual, Experiments that Teach you XBEE Wireless Communications – Jonathan A Titus
© www.soinside.com 2019 - 2024. All rights reserved.