Python的code蓝牙抛出错误之后,我不得不重置适配器 [英] Python code for Bluetooth throws error after I had to reset the adapter

查看:2369
本文介绍了Python的code蓝牙抛出错误之后,我不得不重置适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Python编程蓝牙。这是工作的罚款,直到昨天。今天上午,有一个停电,由于某种原因,蓝牙模块了禁用,它不能被打开。于是,我做了一个须藤hciconfig hci0重置,然后打开它。从这一点开始,最简单的程序都不能运行。就拿<一个href=\"https://$c$c.google.com/p/pybluez/issues/attachmentText?id=53&aid=530000001&name=RFCOMM+Server.py&token=vnVPKroCQumF9hq0AwD6ea74DyE%3A1327666192157\"相对=nofollow>比如这一个。它得到蓝牙模块停留在 advertise_service 并引发以下错误(FYI:virtualenv中不是一个问题在这里。全系统还蟒蛇做同样的事情)。

I was trying out bluetooth programming in python. It was working fine till yesterday. This morning, there was a power outage and for some reason, the bluetooth module got disabled and it could not be turned on. So, I did a sudo hciconfig hci0 reset and then turned it on. From that point onwards, the simplest of the programs are failing to execute. Take this one for example. It gets stuck at advertise_service in bluetooth module and throws the following error (FYI: virtualenv was not a problem here. The systemwide python also does the same thing).

Traceback (most recent call last):
  File "bt.py", line 17, in <module>
    advertise_service( server_sock, "SampleServer", service_id = uuid, service_classes = [ uuid, SERIAL_PORT_CLASS ], profiles = [ SERIAL_PORT_PROFILE ])
  File "/home/machinename/.virtualenvs/py27/local/lib/python2.7/site-packages/bluetooth/bluez.py", line 242, in advertise_service
    raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')

有时候,我得到了一个不同的错误,当我重新编译和安装配合bluez 驱动程序:

Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/bluetooth/bluez.py", line 268, in advertise_service
  bluetooth.btcommon.BluetoothError: error no advertisable device.

但所有这些工作就像之前在机器的魅力;其实在我写这篇所有程序的运作方式与我的其他的Ubuntu(14.04LTS)机器的罚款。我检查了源$ C ​​$ c和追踪到 _bluetooth.so 文件 - 这是一个编译code,所以我想不出做什么了。

But all of these worked like a charm before in that machine; in fact all of the program works just fine with my other ubuntu (14.04LTS) machine as I write this. I inspected the source code, and traced to a _bluetooth.so file - which is a compiled code, hence I couldn't figure out what to do anymore.

任何指针将是非常美联社preciated。

Any pointer will be highly appreciated.

推荐答案

此错误是由于不兼容的BlueZ 5和SDP的问题与 bluetoothd

This error is due to incompatibility issues with BlueZ 5 and SDP with bluetoothd

确认,运行浏览的sdptool当地给出了以下错误:

Make sure, running sdptool browse local gives following error:

Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory

事实证明,罪魁祸首是 bluetoothd ,蓝牙守护进程。使用SDP与 bluetoothd 需要去precated功能对于一些愚蠢的理由,所以要解决这个问题,守护进程必须在兼容模式下使用 bluetoothd开始-C (或蓝牙--compat )。

As it turns out, the culprit is bluetoothd, the Bluetooth daemon. Using SDP with bluetoothd requires deprecated features for some silly reason, so to fix this, the daemon must be started in compatibility mode with bluetoothd -C (or bluetooth --compat).

查找 bluetooth.service 的位置:

systemctl status bluetooth.service

然后修改 bluetooth.service ,并查找

ExecStart=/usr/libexec/bluetooth/bluetoothd

追加 - COMPAT 在这行的末尾,保存,然后运行

Append --compat at the end of this line, save, and then run

service bluetooth start

如果一切顺利的话,你应该能够成功运行。

If all goes well, you should be able to successfully run

sudo sdptool browse local

最后,重置适配器:

Finally, reset the adapter:

sudo hciconfig -a hci0 reset

事情应该很好地工作,现在

Things should work fine now

只是为了让人们知道,我相信最新的 的BlueZ 建立在我的系统在某种程度上打破。我下载,编译和安装href=\"http://www.kernel.org/pub/linux/bluetooth/bluez-5.35.tar.xz\" rel=\"nofollow\"> 5.35 版的 5.34 ,还是一样。我还注意到,蓝牙适配器使用使其3-4分钟后自动下降,

Just to let people know, I believe the latest BlueZ build was somehow broken in my system. I downloaded, compiled and installed the 5.35 version, and nothing was working. I dialed down to 5.34, still same. I also noticed that the bluetooth adapter was going down automatically 3-4 minutes after enabling it using,

sudo hciconfig hci0 up # hci0 is the bt adapter

我使用了一个USB蓝牙适配器进行测试。它没有自动转到下来像内置的适配器,但仍然存在的问题。然后我用 apt-get的重新安装的bluez

apt-get install --reinstall bluez

和突然一切就恢复正常了。

and all of a sudden everything came back to normal.

这篇关于Python的code蓝牙抛出错误之后,我不得不重置适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆