【问题标题】:Send over bluetooth python commands to another Raspberry Pi通过蓝牙 python 命令发送到另一个 Raspberry Pi
【发布时间】:2019-05-16 13:58:44
【问题描述】:

我想通过蓝牙将两个 Raspberry Pi 相互连接。 接下来,我想向另一个 Raspberry Pi 发送一个命令(在 Python 中)。

我想将它用于一些家庭自动化的事情,例如通过蓝牙将温度从一个 pi 发送到另一个,而无需 Wi-Fi。

我已经在谷歌上搜索了很长时间,但找不到适合我的好教程。 谢谢。

【问题讨论】:

    标签: python bluetooth raspberry-pi


    【解决方案1】:

    要先连接两个树莓派设备,您需要安装以下软件包:

    • 康曼
    • pi-蓝牙
    • 蓝牙
    • 蓝色
    • python-bluez

    使用命令“hciconfig -a”检查是否启用了蓝牙。 蓝牙关闭时的示例输出:

    hci0:   Type: Primary  Bus: UART
            BD Address: B8:27:EB:9D:51:6B  ACL MTU: 1021:8  SCO MTU: 64:1
            DOWN
            RX bytes:668 acl:0 sco:0 events:34 errors:0
            TX bytes:423 acl:0 sco:0 commands:34 errors:0
            Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
            Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
            Link policy: RSWITCH SNIFF
            Link mode: SLAVE ACCEPT
    

    您可以使用命令“connmanctl enable bluetooth”来启用它。现在,当您再次使用“hciconfig -a”检查时,您应该会看到类似这样的内容

    hci0:   Type: Primary  Bus: UART
            BD Address: B8:27:EB:9D:51:6B  ACL MTU: 1021:8  SCO MTU: 64:1
            UP RUNNING
            RX bytes:1385 acl:0 sco:0 events:75 errors:0
            TX bytes:1193 acl:0 sco:0 commands:75 errors:0
            Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
            Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
            Link policy: RSWITCH SNIFF
            Link mode: SLAVE ACCEPT
            Name: 'raspberrypi'
            Class: 0x6c0000
            Service Classes: Rendering, Capturing, Audio, Telephony
            Device Class: Miscellaneous,
            HCI Version: 4.1 (0x7)  Revision: 0x8b
            LMP Version: 4.1 (0x7)  Subversion: 0x6119
            Manufacturer: Broadcom Corporation (15)
    

    要配对两个覆盆子,请按照this site上“使用命令行”部分的说明进行操作

    如果你想用python交流可以看this repository中的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 2014-07-12
      • 2016-05-08
      • 2016-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多