bleak icon indicating copy to clipboard operation
bleak copied to clipboard

RPi - BlueZ: client.services returning empty

Open Rxb2300 opened this issue 2 years ago • 2 comments

  • bleak version: 0.20.2
  • Python version: 3.9.2
  • Operating System: Linux (Raspbian running on Raspberry Pi 4)
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.55

Description

I am trying to run a GATT server on a raspberry pi 4 and have been using the following example to get me started: https://github.com/PunchThrough/espresso-ble. The only modification I made to this code was to comment out the content of the AurthorizeService method in the Agent class to automatically return without requesting a "yes" from the user when polled by another connected device.

This server seems to run alright, I can identify it using my Android device running nRF connect, I can connect with it, and read / write to the service / characteristics.

On a second raspberry pi I am trying to run a simple BLE central to scan, detect, connect, and read/write to the previously mentioned peripheral. I am utilizing bleak for this portion of the project.

On this Pi I am running the service_explorer.py example from this repository to connect with the other device running the Vivaldi service and request a list of services / characteristics.

While it does connect to the peripheral pi, and the peripheral pi does print out that it automatically granted service request to the central pi, I see nothing printed out to the terminal.

image

It seems as if though client.services is returning empty.

I tried the same but using the outdated BluePy module running this script:

from bluepy.btle import Peripheral, BTLEException

def main():
    
    device_mac_address = "D8:3A:DD:15:6A:87"

    
    try:
        
        print(f"Attemptingt to connect to device: {device_mac_address}")
        p = Peripheral(device_mac_address)

        
        for service in p.getServices():
            print(f"Service: {service}")
            
            for char in service.getCharacteristics():
                print(f"\tCharacteristic: {char}")
            
    except BTLEException as e:
        print(f"Unable to connect to device {e}")
        
    finally:
        
        print(f"Disconnecting form device: {device_mac_address}")
        p.disconnect()
        
        
if __name__ == "__main__":
    
    main()

And I got the following when it was able to successfully connect.

image

The service / characteristics at the bottom are what I was looking for.

Logs

Attached below is a portion of the BTMON log running on the central device (The pi running the bleak example).

central_btmon_log.txt

The central address is : D8:3A:DD:0C:AF:9F The peripheral address is : D8:3A:DD:15:6A:87 The service uuid of interest is : "12634d89-d598-4874-8e86-7d042ee07ba7".

If you search for uuid in the log of the central, you can find the service when it ran the bleak example.

Rxb2300 avatar Jul 04 '23 04:07 Rxb2300

the bluez implementation is connecting to dbus objects. The dbus objects are created via bluez. Bluez is only resolving known services & characteristics. So I guess your service is not resolved by the bluetoothd. Maybe there are some bugs at the GATT database or so. You can use "sudo btmon" to check for errors.

Older python modules like bluepy that are using hcitool etc directly. So you can resolve you GATT service directly there. To my knowledge is bleak not supporting the registration of user specific GATT profiles

StefJar avatar Jul 17 '23 13:07 StefJar

I cannot get https://github.com/PunchThrough/espresso-ble/blob/master/ble.py to run on Raspbian Bullseye. Can you please provide a working test case?

dlech avatar Jul 19 '23 01:07 dlech

This issue has been automatically closed because it has not had any activity for 100 days after being marked as stale.

github-actions[bot] avatar Oct 05 '25 02:10 github-actions[bot]