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.
There are two steps required in order to achieve what you want:-
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:-
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).