Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Add Characteristic.READ | Characteristic.NOTIFY to BLE Batte
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Add Characteristic.READ | Characteristic.NOTIFY to BLE Batte

by madgrizzle on Sun Jul 05, 2020 9:44 pm

I'm trying to get my nRF52 to report battery level over BLE. After adding the battery service to my code and connecting to the board via Nordic's nRF Connect, it appears as a discovered service, but the permissions are empty and therefore I cannot read the value. It looks like the default "properties" value for the adafruit_ble BatteryService is 0. If I edit the int.py source code to change the IntCharacteristics' properties=0 to properties=Characteristic.READ | Characteristic.NOTIFY, it appears in nRF Connect and I can read the battery value. I think there must be a way to set this value from my code rather than modifying the library source code and I'm sure it's embarassingly simple, but for the life of me I can't figure out how to do so.

madgrizzle
 
Posts: 5
Joined: Tue Feb 05, 2019 4:14 pm

Re: Add Characteristic.READ | Characteristic.NOTIFY to BLE B

by madgrizzle on Sun Jul 05, 2020 10:11 pm

I also found if I modified the source code of the BatteryService itself, I can set the properties.

Code: Select all | TOGGLE FULL SIZE
+ from ...characteristics import Characteristic


class BatteryService(Service):
    """Provides battery level information"""

    uuid = StandardUUID(0x180F)
-   level = Uint8Characteristic(max_value=100, uuid=StandardUUID(0x2A19))
+   level = Uint8Characteristic(max_value=100, properties=Characteristic.READ | Characteristic.NOTIFY, uuid=StandardUUID(0x2A19))

madgrizzle
 
Posts: 5
Joined: Tue Feb 05, 2019 4:14 pm

Re: Add Characteristic.READ | Characteristic.NOTIFY to BLE B

by tannewt on Mon Jul 06, 2020 1:18 am

Please make a pull request! I may have broken it when I reorganized things.

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: Add Characteristic.READ | Characteristic.NOTIFY to BLE B

by madgrizzle on Mon Jul 06, 2020 9:19 am

Which solution is appropriate? I notice that some of the generic characteristics have permissions set within their class. For example, StringCharacteristic has "properties=Characteristic.Read" but, as mentioned before, IntCharacteristic has "properties=0". What's different between a StringCharacteristic and an IntCharacteristic to warrant one have a permission set and the other not? I suspect (don't know) that its inadvertent and I think setting the permissions within the service class, such as BatteryService, is "more" correct. If so, I'm happy to do a PR for it

madgrizzle
 
Posts: 5
Joined: Tue Feb 05, 2019 4:14 pm

Re: Add Characteristic.READ | Characteristic.NOTIFY to BLE B

by tannewt on Mon Jul 06, 2020 1:30 pm

I think setting it at the service level is best. I'm not sure why StringCharacteristic has a permission setting. It probably shouldn't. :-)

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.