树莓派python蓝牙,我怎样才能让用Python树莓派和蓝兆WT11i蓝牙模块之间的连接?...

I'm trying to make a Connection betweet my RaspberryPi and a Bluegiga WT11i Bluetooth Module using Python.

Up to this point I come:

pi@raspberrypi ~ $ hcitool scan

Scanning ...

00:07:80:54:CA:E2 BGWT11i

next ...

pi@raspberrypi ~ $ python sdp-browse.py 00:07:80:54:CA:E2

found 1 services on 00:07:80:54:CA:E2

Service Name: Bluetooth Serial Port

Host: 00:07:80:54:CA:E2

Description: None

Provided By: None

Protocol: RFCOMM

channel/PSM: 1

svc classes: ['00001101-0000-1000-8000-00805F9B34FB']

profiles: []

service id: None

next ...

pi@raspberrypi ~ $ python rfcomm-client.py 00:07:80:54:CA:E2

searching 00:07:80:54:CA:E2 for service

connecting to "Bluetooth Serial Port" on 00:07:80:54:CA:E2

Traceback (most recent call last):

File "rfcomm-client.py", line 28, in

sock.connect((host, port))

File "", line 5, in connect

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

Here is the code (from PyBluez examples) ...

sdp-browse.py:

import sys

import bluetooth

if len(sys.argv) < 2:

print "usage: sdp-browser "

print " addr can be a bluetooth address, \"localhost\" or \"all\""

sys.exit(2)

target = sys.argv[1]

if target == "all" : target = None

services = bluetooth.find_service(address=target)

if len(services) > 0:

print "found %d services on %s" % (len(services), sys.argv[1])

print

else:

print "no services found"

for svc in services:

print "Service Name: %s" % svc["name"]

print " Host: %s" % svc["host"]

print " Description: %s" % svc["description"]

print " Provided By: %s" % svc["provider"]

print " Protocol: %s" % svc["protocol"]

print " channel/PSM: %s" % svc["port"]

print " svc classes: %s" % svc["service-classes"]

print " profiles: %s" % svc["profiles"]

print " service id: %s" % svc["service-id"]

rfcomm-client.py:

from bluetooth import *

import sys

addr = None

if len(sys.argv) < 2:

print "need address"

sys.exit(0)

else:

addr = sys.argv[1]

print "searching %s for service" % sys.argv[1]

uuid = "00001101-0000-1000-8000-00805f9b34fb"

service_matches = find_service( uuid = uuid, address = addr )

if len(service_matches) == 0:

print "couldn't find the service =("

sys.exit(0)

first_match = service_matches[0]

port = first_match["port"]

name = first_match["name"]

host = first_match["host"]

print "connecting to \"%s\" on %s" % (name, host)

sock=BluetoothSocket( RFCOMM )

sock.connect((host, port))

print "connected. type stuff"

while True:

data = raw_input()

if len(data) == 0: break;

sock.send("%s\n\r" % data)

sock.close()

What can I do?

解决方案

Got it!!

pi@raspberrypi ~ $ aptitude install bluetooth

pi@raspberrypi ~ $ hcitool dev

Devices:

hci0 00:07:80:54:CA:E2

pi@raspberrypi ~ $ hcitool scan

Scanning ...

00:07:80:54:CA:E2 BGWT11i

pi@raspberrypi ~ $ bluez-simple-agent hci0 00:07:80:54:CA:E2

Enter PIN Code: 1234

Now I can connect ...

pi@raspberrypi ~ $ python rfcomm-client.py 00:07:80:54:CA:E2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值