How to connect to specified service when duplicate services discovered with same UUID in one peripheral?

Hello,

I am working on a  project that modified from ble_app_uart_c, with sdk v16.0, softdevice S140. The 52840 board as ble central and an android app as virtual NUS peripheral.

It should be straightforward work, but the board can only connect the service, discover the chars normally,  can not tx/rx data with the android app.

After 3 days debugging, I found a strange thing. When I use NRF Connect app to debug, after connected to the ANDROID VIRTUAL PERIPHERAL, many duplicate services with same UUID discovered. Different device with same android app got distinct result. My Samsung Galaxy got 6 duplicate services, but Google Nexus got 3 duplicate services, another MI branded phone got five. See the screenshot.

android app running on Samsung galaxy as peripheral, NRF Connect iOS version screenshot

Samsung galaxy as peripheral, NRF Connect iOS version screenshot

And only operations on the bottom one service take effect, other service can neither write data nor receive notifications.

I think it may be a bug of my android app,  so running NRF Connect APP on the Samsung phone, create a virtual peripheral using ADVERTISER function, then use another NRF Connect running in iOS,  scan and connect, 4 duplicate services discovered. Maybe it's a bug of ANDROID BLE framework ?!

Based on above situation and back to my question, how can I connect to the specified service(the bottom one) from the 52840 board?

Parents
  • Hi Weihe, 

    I would need to check with our Android experts to check if there is anything wrong. 
    But could you try to do a test to reset the phone (and turn off and on Bluetooth) and try again. I suspect that every time you run your app it will try to create a new UART service on the phone and it explain why you have so many duplicated. 

    We will need to look into how the service should be released after the app is closed. 

    The reason for that you can use only one single service and not able to choose between them when there are multiple duplicated is that the ble_app_uart_c or specifically the database discovery module was not designed to handle multiple instance of the same service on a server. So it basically return the first instance of the service in the table. And I don't think there is a straightforward way to continue discovery the next service except for manually start the discovery again using ble_db_discovery_start() with correct curr_char_ind and curr_srv_ind parameter. 

    I would suggest to focus on solving the issue on the Android app.

Reply
  • Hi Weihe, 

    I would need to check with our Android experts to check if there is anything wrong. 
    But could you try to do a test to reset the phone (and turn off and on Bluetooth) and try again. I suspect that every time you run your app it will try to create a new UART service on the phone and it explain why you have so many duplicated. 

    We will need to look into how the service should be released after the app is closed. 

    The reason for that you can use only one single service and not able to choose between them when there are multiple duplicated is that the ble_app_uart_c or specifically the database discovery module was not designed to handle multiple instance of the same service on a server. So it basically return the first instance of the service in the table. And I don't think there is a straightforward way to continue discovery the next service except for manually start the discovery again using ble_db_discovery_start() with correct curr_char_ind and curr_srv_ind parameter. 

    I would suggest to focus on solving the issue on the Android app.

Children
  • Hi Hung,

    Thanks for ur valuable advice. And yes,  after a power recyle, duplicate services gone, my board works. You saved my ass!!

    For others who may be interested in this topic, I'd like to share more information.

    Actually, restart the android APP will release the service. But if you terminate the APP by pushing te STOP DEBUG button in Android Studio, the zombie-service created.

Related