【问题标题】:How to get scan info from bluetooth with python? RPi3如何使用python从蓝牙获取扫描信息? RPi3
【发布时间】:2018-06-08 17:36:42
【问题描述】:

我想将 bluetoothctl 与 Python 一起使用,以获取有关通过 scan on 扫描的所有内容的信息,但我无法获得正确的代码来执行此操作。它们只是显示一个列表,其中包含可以找到的设备的名称和地址。

我目前正在使用带有 sudo bluetoothctl 的 BlueZ 5.47,当我在终端窗口中为 BLE 设备使用 scan on 时,我正在从传感器获取数据,我想将此输出保存在 Python 中,我该怎么做在 Python 中?

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:47:AE:DD Discovering: yes
[CHG] Device 04:B3:EC:00:1E:65 RSSI: -76
[CHG] Device 04:B3:EC:00:1E:65 UUIDs: 0000fbb0-0000-1000-8000-00805f9b34fb
[CHG] Device 04:B3:EC:00:1E:65 ManufacturerData Key: 0x00ac
[CHG] Device 04:B3:EC:00:1E:65 ManufacturerData Value:
  b2 00 52 01 12 17 0c 15 0e 65 1e 00 ec b3 04     ..R......e..... 
[CHG] Device 04:B3:EC:00:1E:65 AdvertisingFlags:
  06                                               .               
[CHG] Device 04:B3:EC:00:1E:65 ManufacturerData Key: 0x00ac
[CHG] Device 04:B3:EC:00:1E:65 ManufacturerData Value:
  b2 2e 52 01 12 45 0c 15 0e 65 1e 00 ec b3 04     ..R..E...e..... 

我看到 PyBluez 可以提供帮助,但它似乎只会在scan on 期间为我提供可用 BLE 设备的名称和信息。您知道另一种可以提供帮助的工具吗?谢谢!

【问题讨论】:

    标签: python bluetooth raspberry-pi3 sensors


    【解决方案1】:

    我对 PyBluez 不熟悉,但如果您只想存储 bluetoothctl 输出,您可以使用 Python 3 check_output 这样的函数。

    from subprocess import check_output
    
    ouput = check_output(['bluetoothctl'])
    

    然后你可以按照你想要的方式解析和使用它。

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      相关资源
      最近更新 更多