繁体   English   中英

python:蓝牙错误:(111,'拒绝连接')

[英]python: bluetootherror: (111, 'connection refused')

嗨,大家好!

通过蓝牙将手机连接到树莓派3似乎存在问题。 我认为我的代码有问题。

这是我的代码

import bluetooth

from bluetooth import  *

serverMAC = 'xx:xx:xx:xx:xx:xx'

port = 1

s = blutooth.BluetoothScocket(bluetooth.RFCOMM)

s.connnect((serverMAC, port)

我想从手机上获得Raspberry Pi的价值。

bluetooth.btcommon.BluetoothError: (111, 'Connection refused')

在尝试下面的代码之前,请确保脚本运行设备上的BT适配器已打开,并且目标Bluetooth设备处于可发现模式(它的适配器已打开并且在发现时具有广播功能)。

确保为目标设备使用正确的端口。 为此,您可以在可用设备上运行发现,然后将MAC与找到的设备之一匹配,然后在该地址上发出find_service。 来源: 通过python发送带有蓝牙的消息或数据

在本地计算机上尝试过此操作时,请注意MAC将会更改,配置文件也会更改,因此,如果您希望RFCOMM确保在尝试连接之前将设备公开,则:

from bluetooth import *
devices = discover_devices()
for device in devices:
    print([_ for _ in find_service(address=device) if 'RFCOMM' in _['protocol'] ])
# now manually select the desired device or hardcode its name/mac whatever in the script
bt_addr = ...
port = [_ for _ in find_service(address=bt_addr) if 'RFCOMM' in _['protocol']][0]['port']
s = BluetoothSocket(RFCOMM)
s.connect((bt_addr, port))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM