This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to send the voltage value via BLE?

Hi guys,

I am using Zephyr RTOS and trying to enable my device to send the voltage data via BLE. I use two nRF52832 boards, one of them is peripheral for which I use peripheral_ht example from Zephyr documentation, and the second one is central for which I use central_ht example. For now, I can send the temperature values without problems, but my goal is to enable my peripheral device to send the measured voltage to the central board. I need this because I use the external power source for my peripheral board and I want to see if the voltage readings are correctly.

Thanks in advance and I hope that you can help me!

Best regards,

Adnan.

Parents Reply Children
  • Hi Sigurd,

    Thanks a lot for this information. Can I find somewhere the rules how to define a new GATT service because I found already that some of them were already defined? I am now interested to know how to define my own service, are there some special rules or you have some samples to show me that?

    Best regards,

    Adnan.

  • Hi Adnan,

    The Bluetooth Special Interest Group (Bluetooth SIG) has predefined certain services. For example they have defined a service called Heart Rate service. The reason why they have done this is to make it easier for developers to make apps and firmware compatible with the standard Heart Rate service. However, this does not mean that you can't make your own heart rate sensor based on your own ideas and service structures. Sometimes people mistakenly assumes that since Bluetooth SIG has predefined some services they can only make applications abiding by these definitions. This is not the case. It is no problem to make custom services for your custom applications.

    If the predefined service suits your needs, then I recommend using them. If you see that they don’t suit your use-case, and you want to make some modifications, then you should create your own custom service.

    Here is a list over the predefined services/profiles: https://www.bluetooth.com/specifications/gatt/

    The Bluetooth SIG Battery Service defines a Battery Level characteristic where the battery level is presented as a percentage from 0% to 100%. Since you want to send the battery level as voltage instead, it does not suit your use-case, and you should create a custom service instead.

    The LBS(LED Button Service) implements a basic/minimalistic custom service. You might want to take a look at that:

    https://github.com/nrfconnect/sdk-nrf/tree/v1.3.1/samples/bluetooth/peripheral_lbs

    https://github.com/nrfconnect/sdk-nrf/blob/v1.3.1/subsys/bluetooth/services/lbs.c

    Let me know if you need more help setting up your "battery voltage" service.

  • Hi Sigurd,

    Thanks again for this advice. I will try to set up my own "battery voltage" service using functions from the battery voltage sample. This is okay when I need to set up this service to the peripheral device, but what to do when I need to configure the central device to read that value...should I need also for central device to define how to read this value?

    Best regards,

    Adnan.

  • Aduka_27 said:
    should I need also for central device to define how to read this value?

     Yes, that is also needed. The central would need to discover the service, and enable the notification, and when the notification is received, it would need to parse the value.

    We have a battery service central implementation in NCS, see this link: https://github.com/nrfconnect/sdk-nrf/blob/master/subsys/bluetooth/services/bas_c.c

    Since battery voltage and percentage is related, you could actually convert the voltage to percentage , use the predefined battery service to send the percentage value,  and on the central side convert it from percentage back to voltage again. It's up to you. 

  • Hi Sigurd,

    I tried this example, but I use the Zephyr standalone and I was not able to run it. Now, I am trying to figure out how to do that with libraries inside the Zephyr documentation. They also create this bas service, but I am not sure how to define the central node to discover the service and enable the notification. If you have any example related to this with some explanations of functions and other parameters, I will really appreciate that.

    Best regards,

    Adnan.

Related