Battery Service Notification

Hi, I am using a NCS v2.6.0.I created a custom zephyr project. Implemented custom ble service and added BLE DIS and BAS services from source. 3 out of 2 services working properly but in the battery service notification is not enable automatically. so I am not able to send battery percentage to client( Mobile). previously I'm working in nrf5 sdk in that code it is working properly.

In nrf connect app I enable notification manually. but I am using custom android application.I want to Implement features like if device connected with application battery percentage should be display in application.


how notifications are enable in zephyr??


For this Issue I have been checked below topics.

  • compared nrf5 sdk vs nrf connect sdk battery service
  • checked cccd value in bas service
  • CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=y
    service configuration.
    BT_GATT_SERVICE_DEFINE(bas,
    BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
    BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL,
    BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
    BT_GATT_PERM_READ,read_blvl,NULL,
    &battery_level),
    BT_GATT_CCC(blvl_ccc_cfg_changed,
    BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),

    Is there any another issue?
Parents
  • Hello,

    Normally the only thing you need to do to implement the battery service is to set a kconfig flag:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_BT_BAS

    You can find an example on how to send battery notifications here:
    \zephyr\samples\bluetooth\peripheral\src\main.c

    If this doesn't work natively in Android, but using nRF Connect app, then possible you have tried to manually setup battery service, and maybe not done it correctly. So try the above if that works.

    Kenneth

  • Thanks  for Reply.

    I have already enabled CONFIG_BT_BAS=y. I don't Know why blvl_ccc_cfg_changed is not called automatically. It is called when I enable notification manually from nrf connect app.

    Is there any solution available? from software side like config or api who enable notification forcefully?

  • Hello,

    Sounds to me like a problem in the custom android application, but what you can do is connect to the peripheral using the nRF Connect for Desktop Bluetooth Low Energy app, then you can take a screenshot of the full services and characteristics of the peripheral, maybe something is wrong that is difficult to see without a clear overview:
    https://docs.nordicsemi.com/bundle/nrf-connect-ble/page/service_discovery.html 

    Kenneth

  • Also, if the device support bonding, maybe delete the peripheral from the android phone, do a full power cycle of the phone to ensure all BT cache of the device is removed.

    Kenneth

Reply
  • Also, if the device support bonding, maybe delete the peripheral from the android phone, do a full power cycle of the phone to ensure all BT cache of the device is removed.

    Kenneth

Children
No Data