使用Xbee和RPI将串行端口输出重定向为bash命令

使用Xbee和RPI将串行端口输出重定向为bash命令,bash,raspberry-pi,serial-port,pyserial,xbee,Bash,Raspberry Pi,Serial Port,Pyserial,Xbee,我的设置是复杂的,我想我有一个明确的前进方向,但请让我知道,如果你看到一个更好的方法来完成我的最终状态使用终端窗口在Xbee上。我的使用案例是RPI#1具有互联网连接,但RPI#2没有,我希望通过RPI#1通过Xbee完全控制和访问RPI#2 我有2个Raspberry Pi 3B+和am,使用2个Xbee Pro S3B模块在RPI之间通过Xbee USB开发屏蔽进行通信。Xbees在RPIs上显示为/dev/ttyUSB0。我想使用Xbees作为RPI的传输层,就像802.11/15或普通的

我的设置是复杂的,我想我有一个明确的前进方向,但请让我知道,如果你看到一个更好的方法来完成我的最终状态使用终端窗口在Xbee上。我的使用案例是RPI#1具有互联网连接,但RPI#2没有,我希望通过RPI#1通过Xbee完全控制和访问RPI#2

  • 我有2个Raspberry Pi 3B+和am,使用2个Xbee Pro S3B模块在RPI之间通过Xbee USB开发屏蔽进行通信。Xbees在RPIs上显示为/dev/ttyUSB0。我想使用Xbees作为RPI的传输层,就像802.11/15或普通的老式以太网在bash的无头情况下使用一样。XBEE以115200波特率运行,通过X-CTU工具进行命名和设置。我对高速数据没有幻想,但希望“看到”RPI#1上的RPI#2终端,这与使用传统传输层实现SSH时相同
  • 我能够在透明模式下使用Xbees,并通过屏幕、Minicom、“echo”text here“>/dev/ttyUSB0”和“cat
  • 我已经找到了几个Xbee工具,但我不想把GPIO引脚连接起来然后采用那种方法;我想把Xbees用作简单的传输工具,仅此而已。如何将/dev/ttyUSB0中的文本作为命令传递给bash,并查看结果?如果没有更直接的途径,我正在考虑使用crontab和一个可执行文件来完成这项任务,该文件被删除并重新写入,但我觉得这是最后一种非常无效的方法
  • 有没有什么工具我已经错过了?我可以通过串行端口“屏蔽”命令行和串行I/O吗? 我找到了pyserial,它可以允许TCP绑定到/dev/ttyUSB0端口,但不确定这样做是否正确。到目前为止,我的代码非常简单
  • RPI#1:

    RPI#2:

    cat
    我能够从本地(虽然是远程的)XBee主机的命令行向远程(辅助的、离线的)XBee主机发送和接收命令。当我开始研究串行设备如何打开登录终端时,我找到了答案,并找到了getty工具。下面是我关于透明模式使用的设置说明,我仍在尝试让python xbee和其他工具工作,以允许使用相同的概念,但通过API模式。请注意,下面的说明是一个95%的解决方案,但应该让普通用户稳步前进。我不是以下步骤格式的原始作者,但我找到了每个步骤,并通过各种其他问答论坛将它们结合起来,以达成解决方案:

    首先,获取Digi Xbee X-CTU软件(不安装在Raspberry或Odroid等ARM设备上): 交大: 从以下Digi.com链接安装,但导航到相应的软件FTP链接:

    Linux 64位:

    Linux 32位:

    窗口:

    Mac:

    通过安装X-CTU

    sudo wget ftp://ftp1.digi.com/support/utilities/40002880_R.run
    sudo mv 40002881_R.run xctu_64bit.run
    sudo chmod +x xctu_64bit.run  
    sudo ./xctu_64bit.run
    
    查找X-Bee设备

    sudo wget ftp://ftp1.digi.com/support/utilities/40002880_R.run
    sudo mv 40002881_R.run xctu_64bit.run
    sudo chmod +x xctu_64bit.run  
    sudo ./xctu_64bit.run
    
    确保Xbee未插入集线器,电源将太小,可通过以下错误YMMV识别:

    dmesg | grep ttyUSB0 
    
    返回错误:[228.800021]ftdi_sio ttyUSB0:无法获取调制解调器状态:-32

    lsusb -v -d 0403:6001
    
    sudo nano /boot/cmdline.txt
    
    将控制台tty设备从AMA更改为USB,然后对于kgdboc(允许远程端监视引导过程),根据需要添加/制作匹配

    console=ttyUSB0,115200 kgdboc=ttyUSB0,115200
    
    sudo nano /etc/inittab
    
    确保取消注释(删除#),如果存在,将tty从AMA更改为USB

    T0:23:respawn:/sbin/agetty -L ttyUSB0 115200 vt100
    
    在Ubuntu x86系统上,通过使用X-CTU

    sudo ./XCTU.desktop
    
    将固件更新至最新版本 目前为8075,用于Pro S3B,然后在每个设备上将波特率设置为115200 通过X-CTU使用本地xbee,然后将api模式设置为“带转义的api模式”,可以更新附近的其他xbee。请注意,除非您具有使API模式工作的深入知识,否则应使用透明模式。我从透明模式开始演示以下工作,但后来改为API模式以获得增强的发送-接收控制功能(在撰写本文时等待工作版本)。
    对将在网络上使用的所有设备执行相同的步骤;本地设备完成后,如果可见(足够近),可以更新其他远程设备

    关闭X-CTU并通过以下方式将当前用户添加到拨号组:

    sudo usermod -a -G dialout root
    
    然后重新启动:

    通过以下方式设置Minicom:

    sudo aptitude install minicom
    minicom -s
    serial port setup   
    a, set to /dev/ttyUSB0, then hit enter
    e, set baud rate to 115200, then hit enter
    hit enter again to close the window and arrive at the configuration page of minicom
    select to save as dfl, followed by enter
    then move to exit, and hit return
    test connection to a locally connected device via
    three plus symbols without hitting return
    if it replies “ok” in a few seconds or less, all is well
    
    screen /dev/ttyUSB0
    
    sudo aptitude install coreutils && screen
    stty -F /dev/ttyUSB0 -a
    
    或屏幕:

    sudo aptitude install minicom
    minicom -s
    serial port setup   
    a, set to /dev/ttyUSB0, then hit enter
    e, set baud rate to 115200, then hit enter
    hit enter again to close the window and arrive at the configuration page of minicom
    select to save as dfl, followed by enter
    then move to exit, and hit return
    test connection to a locally connected device via
    three plus symbols without hitting return
    if it replies “ok” in a few seconds or less, all is well
    
    screen /dev/ttyUSB0
    
    sudo aptitude install coreutils && screen
    stty -F /dev/ttyUSB0 -a
    
    同样,如果您看到登录提示,则表明您已连接。请注意,屏幕可能是大多数用户的最佳选择;它具有易用性的内在品质(与Minicom相比),可以轻松处理低带宽连接,并且即使与远程主机断开连接,它仍然保持活动状态。Ctl+a和k将断开连接

    安装Coreutils以添加比Minicom更多的选项(也建议使用屏幕):

    sudo aptitude install minicom
    minicom -s
    serial port setup   
    a, set to /dev/ttyUSB0, then hit enter
    e, set baud rate to 115200, then hit enter
    hit enter again to close the window and arrive at the configuration page of minicom
    select to save as dfl, followed by enter
    then move to exit, and hit return
    test connection to a locally connected device via
    three plus symbols without hitting return
    if it replies “ok” in a few seconds or less, all is well
    
    screen /dev/ttyUSB0
    
    sudo aptitude install coreutils && screen
    stty -F /dev/ttyUSB0 -a
    
    这将检查串行端口功能和设置

    与您的设备通信:

    sudo aptitude install minicom
    minicom -s
    serial port setup   
    a, set to /dev/ttyUSB0, then hit enter
    e, set baud rate to 115200, then hit enter
    hit enter again to close the window and arrive at the configuration page of minicom
    select to save as dfl, followed by enter
    then move to exit, and hit return
    test connection to a locally connected device via
    three plus symbols without hitting return
    if it replies “ok” in a few seconds or less, all is well
    
    screen /dev/ttyUSB0
    
    sudo aptitude install coreutils && screen
    stty -F /dev/ttyUSB0 -a
    
    注意:您可以在插入X-Bee的本地计算机上与网络进行交互,也可以在通过internet SSH连接的远程设备上与网络进行交互,只要它连接了X-Bee。另外,请注意,rc.local的以下设置在重新启动后没有保留我的设置;这是一项正在进行的工作。在实现自动化之前,我一直在手动设置它们。 此外,我还手动将rc.local添加到RPI中,其操作方法就在下面的某个地方:

    sudo systemctl stop serial-getty@ttyAMA0.service
    sudo systemctl disable serial-getty@ttyAMA0.service
    sudo systemctl enable serial-getty@ttyUSB0.service
    
    sudo nano /etc/rc.local
    add the below before exit 0
    
    stty行是两行,因为已经注意到第一个实例将报告的波特率更改为9600,第二个实例更改为115200。如果要手动执行此操作,请执行“停止”,然后重新执行“启动”命令