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

Android Central connected to 2 peripherals

I have modified the Android Blinky App to connect two peripherals (nRF52 DK)

Scanning and Connecting to two peripherals works.. but when i want to start sending notifications of one of the peripherals the connection is terminated.

in the btsnoop.log I can see that the connection is terminated with "Connection Timeout"..

I am not sure if there is a problem with my implementation or device specific problem.

here is the source code:

        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mDatathroughputUpdateReceiver, makeGattUpdateIntentFilter());
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mDatathroughputUpdateReceiver2, makeGattUpdateIntentFilter());
    Bundle extras = getArguments();
    mDeviceName = extras.getString(DatathroughputService.EXTRA_DEVICE_NAME);
    mDeviceAddress = extras.getString(DatathroughputService.EXTRA_DEVICE_ADDRESS);
    mDeviceName2 = extras.getString(DatathroughputService.EXTRA_DEVICE_NAME2);
    mDeviceAddress2 = extras.getString(DatathroughputService.EXTRA_DEVICE_ADDRESS2);


    mIntentDatathroughput = new Intent(getActivity(), DatathroughputService.class);
    mIntentDatathroughput.putExtra(DatathroughputService.EXTRA_DEVICE_ADDRESS, mDeviceAddress);
    getActivity().startService(mIntentDatathroughput);
    boolean flag = getActivity().bindService(mIntentDatathroughput, mServiceConnection, 0);

   mIntentDatathroughput2 = new Intent(getActivity(), DatathroughputService.class);
    mIntentDatathroughput2.putExtra(DatathroughputService.EXTRA_DEVICE_ADDRESS, mDeviceAddress2);
    getActivity().startService(mIntentDatathroughput2);
    boolean flag2 = getActivity().bindService(mIntentDatathroughput2, mServiceConnection2, 0);
  • Hi schoensn,

    I tested with 2 peripheral pretty long ago and it worked on my phone ( was samsung galaxy S4 at that time). I haven't seen how you connect and attach Bluetooth Gatt Services to each connection in the code snippet . Maybe you want to make a simple app that connect to say an peripheral example in the SDK (hrs for example) so that I can test here for you just to check if it's the issue with your Android device.

  • I have modified the application. now it uses the HRS.. You can download my source code here:

    HRS_DEMO

    to connect to the peripherals you have to select both devices and push the connect button.

    now the connection is not terminated, but i only recieve data from one device.

    is it possible to have a look at my code and tell me if there is a problem in my implemention?

  • @schoensn: Have you check if both of the devices got a write command to enable notification ? (Write 0x01 to the CCCD characteristic ? ). You need to do that from the app. Also you have to check if the notifications are sent from both device but for some reason the app only update the notification from one device. You can check that with a sniffer.

  • the write command to enable notification has not been sent for both devices (I have checked this with the sniffer) , but on the android monitor I have seen: BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: truefor both devices.

    at the moment i am debuggin my app to find the reason, why the descriptor is not written for both devices.

    is there anything I have to take care when I want to connect to multple devices? delay after connecting to a device etc.?

  • I don't think there could be any trouble with that. But you wrote earlier that you still can receive data from one device ?

    My suggestion is to test by trying to write to a characteristic (by writeCharacteristic not setCharacteristicNotification ). You can test and check if it works with one device before testing with two, concurrently. You can also check if it's the issue with Android phone by using our nRFMaster Control Panel app. It should work with more than 1 peripheral.

Related