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.

  • Hi

    Have you checked out our custom BLE service tutorial? It should explain how to add services to your project. You can also check out our BLE services beginner's tutorial for more information on BLE services. 

    The beacon is not a service of its own, it is just what the device is called when it is doing non-connectable advertising. So by setting the device to advertise connectable, you should be able to connect to it and thus remove the beacon "service".

    Best regards,

    Simon

  • Hello Simon,

    I've already implemented custom and BLE specified services in the nRF52832 and nRF52840 for different projects. My questions are related to the smartphone application development with the Android nRF-Toolbox application as a starting point.

    Regards,

  • Okay, sorry about the misunderstanding. For development on Android, we suggest reading up on the Android BLE Library (BLE manager) documentation. It explains how to use the BLE manager in your Android project and extend it with your own services and data if you'd like.

    Best regards,

    Simon

  • 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?

  • Hi

    How you add your services are entirely up to you, I talked to one of our Android experts to make sure, and there shouldn't be any problem with using the "hierarchy method" you're using here.

    Next, in order to remove the splash menu, replace FeaturesActivity.class with CSCActivity.class in line 44 here: https://github.com/NordicSemiconductor/Android-nRF-Toolbox/blob/master/app/src/main/java/no/nordicsemi/android/nrftoolbox/SplashscreenActivity.java#L44

    Best regards,

    Simon

Related