How to show battery level in iOS and Android using BLE?
Posted: Fri Jan 21, 2022 1:15 pm
Hey,
I want to show my battery level in iOS and Android, like headphones tpiycaly do.
My code looks something like this, with nRF I do get the correct results, but nowhere in Android or iOS can I see my battery status.
Has anybody managed to show the battery level in iOS or Android?
I want to show my battery level in iOS and Android, like headphones tpiycaly do.
My code looks something like this, with nRF I do get the correct results, but nowhere in Android or iOS can I see my battery status.
Has anybody managed to show the battery level in iOS or Android?
- uint8_t battery_level = 42;
- int gatt_svr_chr_access_battery_level(uint16_t conn_handler, uint16_t attr_handler, struct ble_gatt_access_ctxt *ctxt, void *arg) {
- os_mbuf_append(ctxt->om, &battery_level, sizeof(battery_level));
- return 0;
- }
- {
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = BLE_UUID16_DECLARE(0x180F),
- .characteristics = (struct ble_gatt_chr_def[]) {
- {
- .uuid = BLE_UUID16_DECLARE(0x2A19),
- .access_cb = gatt_svr_chr_access_battery_level,
- .flags = BLE_GATT_CHR_F_READ
- },
- {
- 0 /* No more characteristics in this service */
- }
- }
- },