使用Python捕获传入的蓝牙数据包

时间:2015-04-11 15:59:22

标签: python macos bluetooth

这是一个相当复杂的问题。我在编写一些能够捕获来自某个设备的传入蓝牙数据包的代码时遇到了麻烦。我在Mac上使用lightblue,如果有人可以帮助我或指出我正确的方向,我将非常高兴。

以下是我正在使用的代码:

import bluetooth  
hostMACAddress = '00:1f:e1:dd:08:3d' #example address, not the real one
port = 3 
backlog = 1
size = 1024
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.bind((hostMACAddress, port))
s.listen(backlog)
try:
    client, clientInfo = s.accept()
    while 1:
        data = client.recv(size)
        if data:
            print(data)
            client.send(data) # Echo back to client
except: 
     print("Closing socket")
     client.close()
     s.close()

使用上面的代码,我试图捕获从外部设备发送的传入数据包。我收到错误,我相信我做得不对。 运行时出现此错误:

import bluetooth 
  File "/Library/Python/2.6/site-packages/bluetooth/__init__.py", line 36, in <module>
from osx import *
  File "/Library/Python/2.6/site-packages/bluetooth/osx.py", line 3, in <module>
    raise NotImplementedError
NotImplementedError

我从来没有做过任何沟通,我很困惑。

感谢您阅读

0 个答案:

没有答案