【问题标题】:Utilising bluetooth on Mac with Python使用 Python 在 Mac 上使用蓝牙
【发布时间】:2017-11-06 13:19:43
【问题描述】:

我几乎搜索了整个网络(比喻地说),试图找到一种在 Mac 上通过 Python 使用蓝牙的方法。 PyBluez 不兼容,Lightblue 没有得到维护(无论如何都尝试过),安装了 PyObC 框架(包括蓝牙框架),并尝试在我的 2.7.6 和 3.6.1 环境中使用 MacOS 10.10.5。

我经常遇到类似以下的错误:

    Traceback (most recent call last):
  File "/Users/***/PycharmProjects/Bluey/main.py", line 1, in <module>
    import bluetooth
  File "build/bdist.macosx-10.10-intel/egg/bluetooth/__init__.py", line 47, in <module>
  File "build/bdist.macosx-10.10-intel/egg/bluetooth/osx.py", line 1, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/__init__.py", line 160, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/_lightblue.py", line 31, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/_macutil.py", line 169, in <module>
objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector sleep of BBCocoaSleeper at 0x103cdc030>

Process finished with exit code 1

我还尝试为这两种环境重新安装所有上述模块。

我只是希望能够在一个项目中使用蓝牙而无需更改操作系统。我确定我错过了一些东西,因为我怀疑没有人在 Mac 上使用 Python 的蓝牙代码。如果存在固有的兼容性问题,是否还有我尚未发现的其他模块?

【问题讨论】:

  • macOS 上没有完整的 BLE 库。

标签: python macos bluetooth python-module


【解决方案1】:

没有任何功能完整、更新且完全正常工作库用于 macOS 上 Python 中的 BLE。唯一有效的(但功能非常有限且未更新)是 Adafruit 库:https://github.com/adafruit/Adafruit_Python_BluefruitLE

您可能想尝试使用 PyObjC(这是 Adafruit 库使用的)来查看是否可以构建自己的 BLE 库/脚本。

我建议(如果您必须使用 macOS)是 Node.js 库 Noble:https://github.com/sandeepmistry/noble。功能齐全,效果很好,并且不断更新。

【讨论】:

    【解决方案2】:

    tabchas 的回答已过时。此库已被 Adafruit 弃用,转而支持 https://github.com/adafruit/Adafruit_Blinka_bleio,这不适合一般消费。

    但是,它是基于https://github.com/hbldh/bleak 构建的,它是活跃的跨平台的,但仅支持 BLE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-31
      • 2018-07-08
      • 2020-03-08
      • 2012-12-08
      • 1970-01-01
      • 2016-12-06
      • 2022-01-08
      • 2013-10-16
      相关资源
      最近更新 更多