PlayRobotics
Posts: 1
Joined: Mon Jun 03, 2019 1:07 pm

Need help connecting bluetooth device

Mon Jun 03, 2019 1:19 pm

I'm trying to connect my Raspberry Pi 3B to an Arduino that has an HC-05 bluetooth chip to send commands.
I have successfully paired between the HC-05 and the Pi using bluetoothctl:

Code: Select all

Device 98:7B:F3:57:76:34
	Name: BT05
	Alias: BT05
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no
	UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
	UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
	UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
	UUID: Unknown                   (0000ffe0-0000-1000-8000-00805f9b34fb)
	Modalias: bluetooth:v000Dp0000d0110
Now I'm trying to use Python to send commands. My code is:

Code: Select all

import bluetooth

bd_addr = "98:7B:F3:57:76:34"

def connect ():
    port = 1
    sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
    print("Trying to pair to", bd_addr)
    sock.connect((bd_addr, port))
    a = "a"
    while a != 'quit':
        a = input("<<< ")
        sock.send(a)
    sock.close()

connect()
I get an exception while running the code, saying that the host is down, and I can't find the problem:

Code: Select all

python3 tests/bt.py 
Trying to pair to 98:7B:F3:57:76:34
Traceback (most recent call last):
  File "<string>", line 3, in connect
_bluetooth.error: (112, 'Host is down')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/bt.py", line 16, in <module>
    connect()
  File "tests/bt.py", line 9, in connect
    sock.connect((bd_addr, port))
  File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (112, 'Host is down')
I've tried:
[*]replacing the HC-05 device
[*]restarting the bluetooth service, and the Pi

Thanks to all helpers

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Need help connecting bluetooth device

Mon Jun 03, 2019 5:13 pm

The services that bluetoothctl is reporting on that device (GAP and GATT) seem odd to me. It looks to me like a BLE device.

Are you sure it is an HC-05 and not, say, an HM-10? Can you include a pic of the device? Or the source where you purchased it?

[EDIT: The device name ('BT05') and manufacturer (Hewlett-Packard) also suggest that this is a CC41-A module, which is an HM-10 clone. Also BLE, also won't work with RFCOMM sockets. Here's some interesting information on the CC41-A: https://blog.yavilevich.com/2017/03/mlt ... f-a-clone/]

Return to “Advanced users”