I am using the bluetooth module for python import bluetooth which I believe is the PyBluez package. I am able to connect, send, and receive just fine from the bluetooth.BluetoothSocket class but my application is completely blind when it comes to the status of the connection.
I want my application to disable certain functionality when the device is disconnected but there does not seem to be any BluetoothSocket.is_connected() methods of any kind. I would like it to detect changes in the bluetooth status as soon as they occur.
Usually there are multiple topics about something as simple as this, so apologies if this is a duplicate. I have searched this site multiple times for an answer but found nothing specific to python.
解决方案
If you are using Linux, it's also possible to check whether the device is still available using BluetoothSocket's getpeername() method. This method (which is

使用Python的蓝牙模块PyBluez连接设备,但无法检测连接状态。解决方案是在Linux上利用BluetoothSocket的getpeername()方法来判断设备是否在线,通过捕获异常来确定设备是否断开连接。
最低0.47元/天 解锁文章
664

被折叠的 条评论
为什么被折叠?



