AmirFar
Posts: 7
Joined: Sat Sep 23, 2017 10:19 am

HC-08 module - Can't connect RFCOMM Socket : Host is down

Sun Sep 24, 2017 9:10 am

Hi
I am trying to implement communication between RPi3 (Jessie) and Arduino board over BLE (HC-08). I have searched a lot but without any success. I can pair and connect them through Bluetoothctl. Even there is no problem to use light blue (ios) to connect to HC-08 and Arduino (i.e turn on/off a LED). But when I try to connect from RPi3 to Arduino ( Sudo rfcomm connect 0 **:**:**:**:**:** 1) I get "Can't connect RFCOMM Socket: Host is down" error. hci0 is up running and have bound them successfully beforehand ( Sudo rfcomm bind 0 **:**:**:**:**:** 1. The rfcomm0 is created on /etc/bluetooth/rfcomm.conf and /dev/rfcomm0). Thanks

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

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Sun Sep 24, 2017 1:38 pm

The HC-08 is a BLE device. Rfcomm is strictly for use with classic Bluetooth devices. To communicate with an HC-08, you'll need to either connect another HC-08 to the Pi, or do some BLE programming.

AmirFar
Posts: 7
Joined: Sat Sep 23, 2017 10:19 am

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Sun Sep 24, 2017 5:03 pm

Thank you, your posts are really helpful.
can you please tell me where can I read some related examples !? I am new to this technology and have a little experience.
I used Gatttool and successfully connected to HC-08 and somehow communicate with it.

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

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Sun Sep 24, 2017 9:58 pm

Here's some Python code I used to successfully write to an Arduino with an HM-10 attached, once I got bluepy installed and built.

Code: Select all

import bluepy.btle as btle
 
p = btle.Peripheral("AA:BB:CC:DD:EE:FF")
s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb")
c = s.getCharacteristics()[0]
 
c.write(bytes("Hello world\n", "utf-8"))
p.disconnect()
Connect to the HM-10, get the proprietary serial comms service by its UUID, get the first (and only) characteristic, and write to it (the HC-08 will likely use a different UUID, you should be able to find it using bluetoothctl or gatttool). Reading is a bit trickier; you'll need to create a delegate with a callback handler to receive notifications, but there's some sample code on the bluepy website.

AmirFar
Posts: 7
Joined: Sat Sep 23, 2017 10:19 am

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Mon Sep 25, 2017 8:44 am

Thanks again... I actually used your code (with the same UUID) and connected to arduino and successfully turned on/off a led.
But I am curious about something...by using "primary" and "char-desc" in Gatttool I could see a long list of attr handles and UUIDs but I don't know which services they are representing. I saw HC-08 documentation but couldn't find any help. For example, in another guide, the author said 0x000e is for reading battery level... how can I understand or find this handles?!

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

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Mon Sep 25, 2017 9:56 am

What I do is to Google the UUID. Some services, like battery level, are defined in the Bluetooth specification and you can read about them in the official documentation. Others are defined by manufacturers, and will be described in data sheets or other manufacturer specs.

AmirFar
Posts: 7
Joined: Sat Sep 23, 2017 10:19 am

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Mon Sep 25, 2017 10:35 am

I will also use this method.
Now I am going to try receiving data from Arduino.
regards

AmirFar
Posts: 7
Joined: Sat Sep 23, 2017 10:19 am

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Thu Oct 05, 2017 1:20 pm

Ok... after a few days I'm still struggling to read data from Arduino. For now, Arduino just simply sends a string every 5 seconds. when I use Gatttool, I can see Raspberry received the message on notification handle 0x0036 or UUID 0xffe1. But when I try to read handle ( char-read-hnd 0x0036), the value is 00.
Also, I have updated bluez to version 5.43 but when I type attributes-list it shows nothing.
Any suggestions?!
Regards

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

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Thu Nov 09, 2017 12:35 am

OK, I know this is disreputably late, but I finally got around to writing some Python 3 code for reading from an HM-10 / HC-08 (connected to an Arduino). Tested with an HM-10.

Code: Select all

import bluepy.btle as btle
 
class ReadDelegate(btle.DefaultDelegate):
    def handleNotification(self, cHandle, data):
        print(data.decode("utf-8"))
 
p = btle.Peripheral("AA:BB:CC:DD:EE:FF")
p.withDelegate(ReadDelegate())
 
while True:
    while p.waitForNotifications(1):
        pass
 
p.disconnect()
 


Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: HC-08 module - Can't connect RFCOMM Socket : Host is down

Tue Jan 09, 2018 7:39 pm

Hello,
i'm playing with a CC41-A module (something like the HC-10) and with the magnificient bluepy it's as easy as hell, but i'd like to ask if you are having some issues with the module going to sleep and becoming no more responsive at all (via BT) after a while.
with "a while" i mean also one day.
The only way to wake it up is through the UART interface, not something i'd like to use on remote devices..
any secret? :)

Return to “Troubleshooting”