kevincar / bless

Cross-platform Bluetooth Low Energy Server Python Library
MIT License
111 stars 30 forks source link

Ability to write `Descriptors` in advertizement #118

Open vikramdattu opened 11 months ago

vikramdattu commented 11 months ago

Describe the solution you'd like BlueZ already does have this support, and Bleak supports read descriptors property

Additional context Many of the applications, use characteristics descriptors. Having the method for this exposed will help a ton.

mklemarczyk commented 6 months ago

@vikramdattu still interested? I was thinking on the improvements to bless. If @kevincar you agree, I will take the subject ;)

kevincar commented 6 months ago

@mklemarczyk Absolutely!

mklemarczyk commented 5 months ago

@kevincar I have some prototype, I plan to share a PR soon so others can check it for different platforms. I primary work on linux.

mklemarczyk commented 5 months ago

I send you first proposal in PR #134 Who wish to help testing on other platforms ? I will need some data to complete implementation.

mklemarczyk commented 2 months ago

@vikramdattu @kevincar Simple example with descriptor for service. You can define descriptors for different characteristics and services. As many you like. I use them mostly for static data to notify about unit or refresh rate. Those should not be updated too often.

You can use predefined guid from Bluetooth standard, or define your guid for custom descriptors.

    # Simple advertisement service with descriptor.
    gatt: Dict = {
        weather_service_id: {
            temperature_characteristic_id: {
                'Properties': (
                    GATTCharacteristicProperties.read
                    | GATTCharacteristicProperties.write
                ),
                'Permissions': (
                    GATTAttributePermissions.readable
                    | GATTAttributePermissions.writeable
                ),
                'Value': None,
                'Descriptors': {
                    '2901': { # Bluetooth descriptor guid, or your custom 128bit guid
                        'Properties': (
                            GATTDescriptorProperties.read
                            | GATTDescriptorProperties.write
                        ),
                        'Permissions': (
                            GATTAttributePermissions.readable
                            | GATTAttributePermissions.writeable
                        ),
                        'Value': b'millis', # Static value for descriptor.
                    }
                }
            }
        }
    }