2

Problem: A python based BLE central program, when run on a Raspberry Pi, failed to connect to BLE peripheral device (a custom board based on Nordic processor). The same python program successfully connected to the BLE peripheral device when run on a Linux Laptop.

I was expecting the python program will work the same way on both platforms.

Raspberry Pi image is bullseye.

To investigate the issue I used the following on the two platforms (Raspberry Pi and Linux Laptop):

  1. btmon for monitoring
  2. bluetoothctl as the central program to connect to BLE Device
  3. A NRF52 DK running the standard HR monitor example from Zephyr as the BLE peripheral device

I noticed the same behaviour i.e. Raspberry PI failed (connects and immediately disconnects) to connect while Linux Laptop connected successfully.

See btmon logs for the two platforms below.

Observations to note:

  1. On connect btmon log for Raspberry Pi shows Flags: 0x00000008 (unknown device flag)
  2. Some additional HCI events which are not seen in the Linux btmon logs

The above raises a few questions for which I still don't have answers:

  1. What are DEVICE FLAGS (I googled but found no reference to this - all I got was pointers to Advertisement Flags and this Flag seem different)
  2. Why does the value switch from 0x00000000 (in @MGMT Device found event) to 0x00000008 (HCI Device connected event). Note: The valid values for DEVICE FLAGS are 0(Confirm Name),1(LegacyPairing),2(Not Connectable) (got this information from btmon source file packet.c). I found one reference to "unknown device flag"
  3. Who is responsible for the change from 0x00000000 to 0x00000008 - BLE Peripheral or the Central program?

btmon output from Raspberry Pi

Bluetooth monitor ver 5.55
= Note: Linux version 5.15.61-v8+ (aarch64)                                                                                                              15:51:01.286532
= Note: Bluetooth subsystem version 2.22                                                                                                                     15:51:01.286533



@ MGMT Event: Device Found (0x0012) plen 25     {0x0001} [hci0] 16:11:04.518347
        LE Address: CA:13:47:69:08:05 (Static)
        RSSI: -36 dBm (0xdc)
        Flags: 0x00000000
        Data length: 11
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (complete): 3 entries
          Heart Rate (0x180d)
          Battery Service (0x180f)
          Device Information (0x180a)

< HCI Command: LE Create Co.. (0x08|0x000d) plen 25  #34 [hci0] 16:11:12.743104
        Scan interval: 60.000 msec (0x0060)
        Scan window: 60.000 msec (0x0060)
        Filter policy: White list is not used (0x00)
        Peer address type: Random (0x01)
        Peer address: CA:13:47:69:08:05 (Static)
        Own address type: Public (0x00)
        Min connection interval: 30.00 msec (0x0018)
        Max connection interval: 50.00 msec (0x0028)
        Connection latency: 0 (0x0000)
        Supervision timeout: 420 msec (0x002a)
        Min connection length: 0.000 msec (0x0000)
        Max connection length: 0.000 msec (0x0000)
> HCI Event: Command Status (0x0f) plen 4            #35 [hci0] 16:11:12.743617
      LE Create Connection (0x08|0x000d) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19            #36 [hci0] 16:11:12.846266
      LE Connection Complete (0x01)
        Status: Success (0x00)
        Handle: 64
        Role: Master (0x00)
        Peer address type: Random (0x01)
        Peer address: CA:13:47:69:08:05 (Static)
        Connection interval: 48.75 msec (0x0027)
        Connection latency: 0 (0x0000)
        Supervision timeout: 420 msec (0x002a)
        Master clock accuracy: 0x00
@ MGMT Event: Device Connec.. (0x000b) plen 24  {0x0001} [hci0] 16:11:12.846310
        LE Address: CA:13:47:69:08:05 (Static)
        Flags: 0x00000008
          Unknown device flag (0x00000008)
        Data length: 11
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (complete): 3 entries
          Heart Rate (0x180d)
          Battery Service (0x180f)
          Device Information (0x180a)
          
< HCI Command: LE Read Remot.. (0x08|0x0016) plen 2  #37 [hci0] 16:11:12.846451
        Handle: 64
> HCI Event: Command Status (0x0f) plen 4            #38 [hci0] 16:11:12.856641
      LE Read Remote Used Features (0x08|0x0016) ncmd 1
        Status: Success (0x00)
> HCI Event: Command Complete (0x0e) plen 14         #39 [hci0] 16:11:12.856698
      LE Read Remote Used Features (0x08|0x0016) ncmd 1
        Status: Success (0x00)
        00 00 00 00 00 00 00 00 00 00                    ..........      
> HCI Event: LE Meta Event (0x3e) plen 12            #40 [hci0] 16:11:13.186323
      LE Read Remote Used Features (0x04)
        Status: Connection Failed to be Established (0x3e)
        Handle: 64
        Features: 0x3f 0x00 0x00 0x08 0x00 0x00 0x00 0x00
          LE Encryption
          Connection Parameter Request Procedure
          Extended Reject Indication
          Slave-initiated Features Exchange
          LE Ping
          LE Data Packet Length Extension
          Remote Public Key Validation
> HCI Event: Disconnect Complete (0x05) plen 4       #41 [hci0] 16:11:13.186899
        Status: Success (0x00)
        Handle: 64
        Reason: Connection Failed to be Established (0x3e)
@ MGMT Event: Device Disconn.. (0x000c) plen 8  {0x0001} [hci0] 16:11:13.198822
        LE Address: CA:13:47:69:08:05 (Static)
        Reason: Unspecified (0x00)


btmon output from Linux

Bluetooth monitor ver 5.53
= Note: Linux version 5.4.0-131-generic (x86_64)                                                                                                                    0.388161
= Note: Bluetooth subsystem version 2.22                                                                                                                            0.388162


@ MGMT Event: Device Found (0x0012) plen 50                                                                                                         {0x0002} [hci0] 7.498178
        LE Address: CA:13:47:69:08:05 (Static)
        RSSI: -56 dBm (0xc8)
        Flags: 0x00000000
        Data length: 36
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (complete): 3 entries
          Heart Rate (0x180d)
          Battery Service (0x180f)
          Device Information (0x180a)
        Name (complete): Zephyr Heartrate Sensor
> HCI Event: LE Meta Event (0x3e) plen 19                                                                                                               #47 [hci0] 17.448221
      LE Connection Complete (0x01)
        Status: Success (0x00)
        Handle: 3585
        Role: Master (0x00)
        Peer address type: Random (0x01)
        Peer address: CA:13:47:69:08:05 (Static)
        Connection interval: 50.00 msec (0x0028)
        Connection latency: 0 (0x0000)
        Supervision timeout: 420 msec (0x002a)
        Master clock accuracy: 0x00
@ MGMT Event: Device Connected (0x000b) plen 24                                                                                                    {0x0002} [hci0] 17.448313
        LE Address: CA:13:47:69:08:05 (Static)
        Flags: 0x00000000
        Data length: 11
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (complete): 3 entries
          Heart Rate (0x180d)
          Battery Service (0x180f)
          Device Information (0x180a)

@ MGMT Command: Disconnect (0x0014) plen 7                                                                                                         {0x0001} [hci0] 28.148025
        LE Address: CA:13:47:69:08:05 (Static)
< HCI Command: Disconnect (0x01|0x0006) plen 3                                                                                                          #95 [hci0] 28.148111
        Handle: 3585
        Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4                                                                                                               #96 [hci0] 28.149253
      Disconnect (0x01|0x0006) ncmd 1
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4                                                                                                          #97 [hci0] 28.174302
        Status: Success (0x00)
        Handle: 3585
        Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Command Complete (0x0001) plen 10                                                                                                    {0x0001} [hci0] 28.174386
      Disconnect (0x0014) plen 7
        Status: Success (0x00)
        LE Address: CA:13:47:69:08:05 (Static)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                  {0x0002} [hci0] 28.174417
        LE Address: CA:13:47:69:08:05 (Static)
        Reason: Connection terminated by local host (0x02)

sudo cat /var/log/syslog provided some specific messages relating to disconnect but I don't know how I can use that to solve the problem I am facing.

Nov 18 11:17:31 kosha bluetoothd[883]: src/adapter.c:connected_callback() hci0 device D0:5F:64:52:00:01 connected eir_len 31
Nov 18 11:17:32 kosha bluetoothd[883]: src/device.c:att_connect_cb() connect to D0:5F:64:52:00:01: Function not implemented (38)
Nov 18 11:17:32 kosha bluetoothd[883]: src/adapter.c:dev_disconnected() Device D0:5F:64:52:00:01 disconnected, reason 0
Nov 18 11:17:32 kosha bluetoothd[883]: src/adapter.c:adapter_remove_connection()
Nov 18 11:17:32 kosha bluetoothd[883]: plugins/policy.c:disconnect_cb() reason 0

Note: when I use my Python program and custom hardware as the BLE device - I see the same things in the btmon log as above. Based on this I suspect the bluetoothd version could be the reason for the problem mentioned above.

I am yet to try keeping the version of bluetoothd the same on both platforms to see if that makes a difference.

UPDATE 19/Nov/2022

I downloaded and compiled the following versions of bluez 5.64, 5.55, 5.65, 5.66 - none of them helped to solve the problem I was facing.

2
  • There's another odd thing here. The Bluetooth spec for the Read Remote Used Features (Vol 4 Part E 7.8.21) states: Note: An HCI_Command_Complete event is not sent by the Controller to indicate that this command has been completed. Instead, the HCI_LE_Read_- Remote_Features_Complete event indicates that this command has been completed. But bluez is sending this reply, and the LE Meta event as well - so two replies with different answers.
    – petzval
    Commented Nov 18, 2022 at 11:37
  • On Linux, I used Bluez 5.53 and everything works very well. I was looking to try 5.63 on Raspberry Pi but could not find it - closest version was 5.64 but that failed to compile and install. Still trying to resolve that though.
    – ugmurthy
    Commented Nov 19, 2022 at 7:10

1 Answer 1

0

I re-imaged the Raspberry Pi with Ubuntu 22.10 and the problem was solved. Everything started to work as it worked on my laptop running Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.