Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

In nrf5_sdk examples, why are some errors accepted after calls ble_bas_battery_level_update(...)

I've looked in examples about battery update. I saw after call ble_bas_battery_level_update(..), the following error will be ignored. 

  • NRF_ERROR_INVALID_STATE
  • NRF_ERROR_RESOURCES
  • NRF_ERROR_BUSY
  • BLE_ERROR_GATTS_SYS_ATTR_MISSING

I have no idea, is there any reason behind to ignore when ble_bas_battery_level_update(..) return the error? 

if I want to implement battery service to update current battery percentage, shall I follow the same error checking condition?

Reference: nRF5_SDK_17.1.0_ddde560/examples/ble_peripheral/ble_app_hrs/main.c

Parents
  • Hello,

    Typically the battery measurement occurs asynchrous to the BLE connection, so in case there is no active link and battery service is not enabled by the peer, then simply ignore any errors from the ble_bas_battery_level_update() seems like a reasonable approach. It's only when in a connection and the peer have enabled receiving battery measurement that data can be sent in any case.

    Kenneth

Reply
  • Hello,

    Typically the battery measurement occurs asynchrous to the BLE connection, so in case there is no active link and battery service is not enabled by the peer, then simply ignore any errors from the ble_bas_battery_level_update() seems like a reasonable approach. It's only when in a connection and the peer have enabled receiving battery measurement that data can be sent in any case.

    Kenneth

Children
No Data
Related