Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android nRF-ToolBox multiple BLE services within a single Android Service

Hello all,

I've been working on creating a test app for a product that I've been developing for sometime. It has multiple BLE services such as Device information (DIS), Cycling Power (CP), Battery Service, DFU and a custom service. I've got no prior experience with Java or xml, so the answer might be obvious to the following questions.

I've adjusted the Cycling Speed and Cadence example in the nRF Toolbox application to receive and display the Cycling Power Measurement, the Cycling Power Feature, Sensor location and the DIS firmware, hardware, model number and serial number Characteristics.

I added all these characteristics in the Cycling Power Manager, but with so many services I'd like to implement this becomes quite a mess and I'd like to seperate each BLE service into a serperate manager/class(es).

I've noticed that the Battery service is already implemented by extension of the Cycling Power Manager (CSCManger in the original toolbox)

public class CPManager extends BatteryManager <CPManagerCallbacks>

From what I've attempted, failed and then read, I cannot extend this class further with other services like this. So what would be the best solution to extend the manager/service with more BLE services without putting all services and characteristics in a single class, while sending all handled BLE data to a single Activity?

Second question: I've removed all other BLE services in the first menu except the DFU and the Cycling Power services by removing the <service from the AndroidManifest.xml file as the template service readme file stated it would. However the Beacon service remains in the main menu, no matter which services I disable or remove. So where does the beacon service come from?

Thank you in advance for helping me out.

Parents Reply Children
  • Hello Simon,

    The BLE library with the profiled explanation does not really explain how to implement multiple services in different classes. For example in the Toolbox application the Battery service is implemented with it's own manager and callbacks. The battery service is added to all services by extending the Manager and the BLEmanager by <CPManagerCallbacks>.

    public class CPManager extends BatteryManager <CPManagerCallbacks>

    Since I can't do this:

    public class CPManager extends BatteryManager, extend DeviceInformation service <CPManagerCallbacks>
    or
    public class CPManager extends BatteryManager<CPManagerCallbacks>, extend DeviceInformation service<CPManagerCallbacks> 
    

    From what I found I would have to implement multiple extensions by adding hierachy:

    public class CPManager extends DeviceInformationManager service<CPManagerCallbacks> 
        public class DISManager extends BatteryManager service<DISManagerCallbacks> 
    

    If I want to add more services I would have to add them by extending another class.

    Am I correct that this is the best approach to implement different BLE serices and characteristics with their own Managers and callabck functions, in stead of putting all functionality in the CPManager class?

    In addtion to the previous question, could you tell me how to adapt the Toolbox application to remove the first tile-menu after the splashscreen and start the CSC service for example directly when the app start?

    I've tried the nRF_blinky example to see If I could port the functionality I've already created in the Toolbox to the blinky project so I would have a more simpler project to start with. However the scanner in the nRF_blink example cannot find the blinky device even though I can connect with with nRF Connect on the same smartphone (Samsung S10+). Do you know a work-around for that or should I try to implement the scanner from the Toolbox instead?

Related