1

I am new to BLE and I need help with Battery Service notifications. I am using nrf52840dk, nrf sdk 17.1.0 and I am using ble_app_proximity example which already uses Battery Service. I need to send a pop up notification from device to nRF Connect mobile app when battery level reaches 40%. Whenever battery level reaches 40%, a notification should pop up in nRF Connect app telling us that battery level has reached 40% and please charge.

Can anyone please help me with this?

I have tested the ble_app_proximity code and it is showing battery level only when I Read it, but I need it to display a pop up notification on nRF Connect app when battery level reaches 40%.

Thanks, Kanthi Deep.

1 Answers1

0

There are two steps required in order to achieve what you want:-

  1. Enable the notifications from the nRF Connect app (GATT client).
  2. Send the notification from the nRF52840dk (GATT server).

Let's go through each one in details:-

Enable notifications from the nRF Connect app

Given that your phone is the GATT client, it needs to subscribe to the battery characteristic notifications. This way, when the nRF52840dk sends out a new battery notification, the nRF Connect app will receive it. In order to do this, connect to the devkit using the nRF Connect app, browse through the services and click on the Battery Service to reveal the characteristics. When you do that, you will see the battery level characteristic with a downward (read), upward (I'm not sure if this exists but maybe it doesn't) and multiple downward (enable notification) arrows. The downward arrow is for reading the battery value, the upward arrow (if it exists) is for writing to the battery value, and the multiple downward arrows are for subscribing to notifications. In your case, you want to click on the multiple downward arrows. I have attached a picture below of what the arrows should look like:-

enter image description here

Please note that in your case, this should be the battery value characteristic and not an unknown characteristic.

Send the notification from the nRF52840dk (GATT server)

In your code, you should be continuously monitoring the value of your battery to check if it has reached 40%. If you're using the SDK's libraries, you can have a look at this function that specifically does what you need in that it sends the battery value as a notification when you call it. There are a few posts on Nordic DevZone on how to read the battery voltage, and these are a few examples (link1 and link2).

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
  • Hello Youssif, Thanks for replying. Everything that you have mentioned is good and helpful but in the 2nd step you have told me to use a function and added a link to it. The problem is that the link is not taking me to that function but rather to nRF 17.1.0 SDK page. Can you send me the link to the function or tell me what that function name is? – Kanthi Deep Nov 28 '22 at 07:06
  • I've updated the link but in case that doesn't work or the link gets removed in the future, the function is ble_bas_battery_level_update() – Youssif Saeed Nov 28 '22 at 07:24
  • Does this function only send notifications when there is a change in battery level? – Kanthi Deep Nov 29 '22 at 07:54