loginek0
Posts: 16
Joined: Fri Mar 13, 2015 7:11 am

Problem connecting to BLE 4.0 - disconnect after 2 seconds

Thu Oct 25, 2018 12:16 pm

Hello,
I have a problem with connecting to a specific bluetooth device (temperature sensor). The device is correctly detected:

Code: Select all

sudo hcitool lescan
LE Scan ...
AA:FD:1D:03:FF:15 (unknown)
AA:FD:1D:03:FF:15 Tr48
I am trying to connect with him (to download available services):

Code: Select all

 gatttool -t random -b aa:fd:1d:03:ff:15 -I
[aa:fd:1d:03:ff:15][LE]> connect
Attempting to connect to aa:fd:1d:03:ff:15
Error: connect error: Transport endpoint is not connected (107)
After executing the code hcidump -t:

Code: Select all

sudo hcidump -t
HCI sniffer - Bluetooth packet analyzer ver 5.43
device: hci0 snap_len: 1500 filter: 0xffffffff
2018-10-25 12:10:09.490484 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x00 (passive)
    interval 60.000ms window 30.000ms
    own address: 0x00 (Public) policy: white list only
2018-10-25 12:10:09.490862 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2018-10-25 12:10:09.490916 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
2018-10-25 12:10:09.491400 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2018-10-25 12:10:09.534114 > HCI Event: LE Meta Event (0x3e) plen 43
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr AA:FD:1D:03:FF:15 (Random)
      Flags: 0x06
      Unknown type 0xff with 26 bytes data
      RSSI: -77
2018-10-25 12:10:09.534177 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x00 (disabled)
2018-10-25 12:10:09.536343 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2018-10-25 12:10:09.536394 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr AA:FD:1D:03:FF:15 type 1
    interval 96 window 96 initiator_filter 0
    own_bdaddr_type 0 min_interval 24 max_interval 40
    latency 0 supervision_to 42 min_ce 0 max_ce 0
2018-10-25 12:10:09.537080 > HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
2018-10-25 12:10:11.596496 < HCI Command: LE Create Connection Cancel (0x08|0x000e) plen 0
2018-10-25 12:10:11.598396 > HCI Event: Command Complete (0x0e) plen 4
    LE Create Connection Cancel (0x08|0x000e) ncmd 1
2018-10-25 12:10:11.598538 > HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x02 handle 64, role master
      bdaddr AA:FD:1D:03:FF:15 (Random)
A simple python code:

Code: Select all

from bluepy.btle import UUID, Peripheral

mac = "aa:fd:1d:03:ff:15"

p = Peripheral(mac,"random")

services=p.getServices()
for service in services:
   print (service)
It also returns an error:

Code: Select all

bluepy.btle.BTLEException: Failed to connect to peripheral AA:FD:1D:03:FF:15 addr type: random
I've tried in a lot of ways and I still have mistakes. It does not help: "btmgmt le on" or anything else. Anyone have an idea?

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

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Thu Oct 25, 2018 1:57 pm

Have you tried removing the '-t random' flag from the gatttool command?

loginek0
Posts: 16
Joined: Fri Mar 13, 2015 7:11 am

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Thu Oct 25, 2018 8:09 pm

Return:

Code: Select all

Error: connect error: Connection refused (111)
Logs with sudo hcidump -t:

Code: Select all

sudo hcidump -t
HCI sniffer - Bluetooth packet analyzer ver 5.43
device: hci0 snap_len: 1500 filter: 0xffffffff
2018-10-25 19:49:31.511045 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x00 (passive)
    interval 60.000ms window 30.000ms
    own address: 0x00 (Public) policy: white list only
2018-10-25 19:49:31.511411 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2018-10-25 19:49:31.511456 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
2018-10-25 19:49:31.511850 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2018-10-25 19:50:11.996669 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x00 (disabled)
2018-10-25 19:50:11.998378 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
After sudo blescan:

Code: Select all

  Device (new): AA:FD:1D:03:FF:15 (random), -63 dBm
        Short Local Name: 'Tr48 '
        Flags: <06>
        Manufacturer: <920378012c680001ac04eeee0502010000000000000000000000>
I have no idea what to do next. I read that there is a timeout in the new Linux kernel (https://stackoverflow.com/questions/435 ... identifier), but unfortunately I do not know how I can change it at home - I can not compile the kernel yet . Can it help? If so, could someone write a detailed instruction on how to do it?

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

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Thu Oct 25, 2018 10:30 pm

I'm afraid I have no suggestions at this point. However, it would be interesting to know:
1. The make and model of the sensor.
2. Can you connect with hcitool: 'hcitool lecc --random <bdaddr>'?

loginek0
Posts: 16
Joined: Fri Mar 13, 2015 7:11 am

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Fri Oct 26, 2018 7:06 am

Device it: Bluetooth Temperature Data Logger.

Code: Select all

sudo hcitool lecc --random AA:FD:1D:03:FF:15
Connection handle 64
Last edited by loginek0 on Fri Oct 26, 2018 9:02 pm, edited 1 time in total.

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

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Fri Oct 26, 2018 1:27 pm

There are some reports of that error message on the Internet, although a lot of them seem to refer to Bluetooth 2.0 devices. Also reports of being able to connect with hcitool but not gatttool, like yourself. You might search for the error text and see for yourself. Just guessing, but it could be a proprietary connection protocol, or it could be problems with BlueZ 5.23 (which is a little old), or it may well be something else.

loginek0
Posts: 16
Joined: Fri Mar 13, 2015 7:11 am

Re: Problem connecting to BLE 4.0 - disconnect after 2 seconds

Fri Oct 26, 2018 9:03 pm

Code: Select all

dpkg --status bluez | grep '^Version:'
Version: 5.43-2+rpt2+deb9u2
However, I found a solution. You had to change the timeouts in include/net/bluetooth/hci.h and recompile the kernel. After that - the problem was solved. Thanks for the help!

Return to “Advanced users”