This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[nRF Connect SDK] How can I find out if HID is connected while BLE advertise NUS.

Target nRF52832(nrf52dk_nrf52832)
SDK NCS v1.9.1

Base source
1. C:\Users\user\ncs\v1.9.1\nrf\samples\bluetooth\peripheral_hids_keyboard
2. C:\Users\user\ncs\v1.9.1\nrf\samples\bluetooth\peripheral_uart

My project require two mode(HID and NUS).
I made new project that support two mode.(User can select mode, and each mode will begin at boot time).

Steps.
1) If a Android device( was connected as HID role.
2) Reboot BLE. BLE started with NUS. BLE is waiting NUS client.
3) Android device try to connect BLE again automatically. It connected as HID.
To avoid this, I have to turn off BT. My client have lots of devices & Androids, and use them at the same time.
So I need to prepare solution not to have this situation.

Question.
I want to detect if connected device is using HID. so that I can disconnect HID connection manually, then can wait new connection as NUS.

Do you have any good idea?

Parents
  • Hello,

    It sounds like your phone is chaching the Bluetooth services (as most phones do). There is something called "service changed service", which you can look into, but it may not be straight forward if you are not using it as intended. I is supposed to be used with bonding, in cases where you add new services. However, this requires the phone to enable indications on the  service changed service. 

    It may be that it is easier to use the old trick of changing the device address instead of using this service changed service, because you will be switching back and forth between two sets of services, it may be easier to pretend that you are two different devices. 

    See this answer form Einar on how to change BLE addresses in NCS:

    Best regards,

    Edvin

Reply
  • Hello,

    It sounds like your phone is chaching the Bluetooth services (as most phones do). There is something called "service changed service", which you can look into, but it may not be straight forward if you are not using it as intended. I is supposed to be used with bonding, in cases where you add new services. However, this requires the phone to enable indications on the  service changed service. 

    It may be that it is easier to use the old trick of changing the device address instead of using this service changed service, because you will be switching back and forth between two sets of services, it may be easier to pretend that you are two different devices. 

    See this answer form Einar on how to change BLE addresses in NCS:

    Best regards,

    Edvin

Children
  • Thanks for update.

    1) For "service changed service", I add following option but it was not effective for me.

    CONFIG_BT_GATT_SERVICE_CHANGED=y

    2) For multiple mac address.

    Only one address is allowed for me.

    So I decide to remove bonding at every mode change and test it.

    Thanks anyway.

Related