首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >raspberry-pi:如何配置hc-05

raspberry-pi:如何配置hc-05
EN

Stack Overflow用户
提问于 2015-01-23 17:00:14
回答 1查看 4.1K关注 0票数 0

我想把我的android手机连接到我的覆盆子,变形蓝牙连接。我在我的树莓里插入了一个hc-05模块,它可以工作。我可以从我的智能手机上读取一些设备信息,如果我修改这些文件

/boot/cmdline.txt /etc/inittab

对于使用蓝牙终端接入智能手机,它是可行的。如果我用:

  • hcitool dev我得到了Devices:
  • /etc/init.dbluetooth status我得到了[ ok ] bluetooth is running.

我无法用python脚本访问蓝牙模块。例如:

代码语言:javascript
运行
复制
from bluetooth import *

targetName="Madlollo"
targetAddress=None
port=2
def searchService():
    mServices=find_service(uuid="00001101-0000-1000-8000-00805F9B34FB")
    if len(mServices)==0:
        print"can't find available service"
    else:
        first_match=mServices[0]
        mPort=first_match["port"]
        mName=first_match["name"]
        mHost=first_match["host"]
        print"Discovered %s on %s at port %s",(name,host,port)

def searchPhone():
    global targetAddress
    nearbyDevices=discover_devices()
    for address in nearbyDevices:
        if targetName==lookup_name(address):
            targetAddress=address
            break
    if targetAddress is not None:
        print"found target Phone with address: ", targetAddress
    else:
        print"can't find target Phone"

def sendMsg(msg):
    sock=BluetoothSocket(RFCOMM)
    sock.connect((targetAddress,port))
    a=sock.send(msg)
    if(a>0):
        print"inviati %d byte" %a
    sock.close()

def readData():
    server_sock=BluetoothSocket(RFCOMM)
    #rport=get_available_port(RFCOMM)
    rport=0
    server_sock.bind(("",rport))
    server_sock.listen(1)
    print"listening on port %d" %rport
    #advertise_service(server_sock,"00001101-0000-1000-8000-00805F9B34FB")
    client_sock,address=server_sock.accept()
    data=client_sock.recv(1024)
    print"received[$s]"%data
    client_sock.close()
    server_sock.close()

如果使用searchPhone()searchService(),则会出现以下错误:

代码语言:javascript
运行
复制
File "blue.py", line 52, in <module>
    searchService()
File "blue.py", line 7, in searchService
    mServices=find_service(uuid="00001101-0000-1000-8000-00805F9B34FB")
  File "/usr/local/lib/python2.7/dist-packages/bluetooth/bluez.py", line 186, in find_service
    devices = discover_devices ()
  File "/usr/local/lib/python2.7/dist-packages/bluetooth/bluez.py", line 17, in discover_devices
    sock = _gethcisock ()
  File "/usr/local/lib/python2.7/dist-packages/bluetooth/bluez.py", line 226, in _gethcisock
    raise BluetoothError ("error accessing bluetooth device")
bluetooth.btcommon.BluetoothError: error accessing bluetooth device

我需要从hcitool找到蓝牙模块。有人知道如何用覆盆子控制hc-05吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-11-11 15:47:55

它应该工作,但它可能需要一个密码的HC-05模块。https://myraspberryandme.wordpress.com/2013/11/20/bluetooth-serial-communication-with-hc-05/

基本上,在连接之前,您需要提供HC-05模块的密码(1234)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28114927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档