This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading battery level from peripheral BLE to central BLE to iOS app.

I have a BLE device acting as a central and a peripheral, relaying information between that peripheral and a custom iOS app. As a central, it reads (not notifications) the battery level of another BLE acting as a peripheral. This is working fine. I see the battery level of the peripheral being reported in RTT. On this relay BLE device, I have ble_bas_c related code working fine. However I can't seem to get the ble_bas related code working so that the iOS app can read that same battery level. There is another battery service that is working fine for the iOS app to read the BLE relay device battery level.

Parents Reply Children
  • In BluetoothGattService object you'll find getInstance() method. For Android version 4.3 - 6?? they return zero-based indexes, for more recent versions they return handle number. This is not documented what they return and this may change to something else again in the future. The important thing is, that each next instance of the same service (and characteristic) gets a different value of instance id.

    There is no such method for descriptors, for some reason.

    Also, instances don't work for local GATT configuration on the phone. Even if you add 5 services of the same UUID, they all get the same instance id = 0. If a packet is received for a characteristic inside one of them, it will be delivered ONLY to the first instance of the server. This might have changed in recent years, however, I would have to check.

Related