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);
Parents
  • 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.

  • if i only connect to one device my application works.. if i connect to two devices i sometimes recieve data from one device and it also happens, that i do not recieve any data.

    In the meantime I have found out that, setCharacteristicNotification() only enables the notification on the android device and gatt.writeDescriptor() writes the CCCD..

    and gatt.writeDescriptor() is only called for one device.

    here is a trace of the android monitor:

        D/BluetoothGatt: connect() - device: C5:7F:B0:8E:AA:91, auto: false
    D/BluetoothGatt: registerApp()
    D/BluetoothGatt: registerApp() - UUID=8c2e588c-697a-4d6c-86b6-49593dc9ea78
    D/BluetoothGatt: connect() - device: C5:87:1C:CC:95:68, auto: false
    D/BluetoothGatt: registerApp()
    D/BluetoothGatt: registerApp() - UUID=0291feac-df2d-47e3-acd4-12d533945892
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
    D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=C5:7F:B0:8E:AA:91
    D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=C5:87:1C:CC:95:68
    D/BluetoothGatt: discoverServices() - device: C5:7F:B0:8E:AA:91
    D/BluetoothGatt: onSearchComplete() = Device=C5:7F:B0:8E:AA:91 Status=0
    D/DeviceC5:7F:B0:8E:AA:91: Enable Notifications initGatt() 
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
    D/BluetoothGatt: discoverServices() - device: C5:87:1C:CC:95:68
    D/BluetoothGatt: onSearchComplete() = Device=C5:87:1C:CC:95:68 Status=0
    D/DeviceC5:87:1C:CC:95:68: Enable Notifications initGatt() 
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a19-0000-1000-8000-00805f9b34fb enable: true
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
    

    I think the problem is, that I connect to the second device, when service discovery, enable notification, write descriptor,.. have not finished..

    the nRFMaster Control Panel app works fine with 2 peripherals, so i dont think it is an issue regarding the android phone...

Reply
  • if i only connect to one device my application works.. if i connect to two devices i sometimes recieve data from one device and it also happens, that i do not recieve any data.

    In the meantime I have found out that, setCharacteristicNotification() only enables the notification on the android device and gatt.writeDescriptor() writes the CCCD..

    and gatt.writeDescriptor() is only called for one device.

    here is a trace of the android monitor:

        D/BluetoothGatt: connect() - device: C5:7F:B0:8E:AA:91, auto: false
    D/BluetoothGatt: registerApp()
    D/BluetoothGatt: registerApp() - UUID=8c2e588c-697a-4d6c-86b6-49593dc9ea78
    D/BluetoothGatt: connect() - device: C5:87:1C:CC:95:68, auto: false
    D/BluetoothGatt: registerApp()
    D/BluetoothGatt: registerApp() - UUID=0291feac-df2d-47e3-acd4-12d533945892
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
    D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=C5:7F:B0:8E:AA:91
    D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=C5:87:1C:CC:95:68
    D/BluetoothGatt: discoverServices() - device: C5:7F:B0:8E:AA:91
    D/BluetoothGatt: onSearchComplete() = Device=C5:7F:B0:8E:AA:91 Status=0
    D/DeviceC5:7F:B0:8E:AA:91: Enable Notifications initGatt() 
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
    D/BluetoothGatt: discoverServices() - device: C5:87:1C:CC:95:68
    D/BluetoothGatt: onSearchComplete() = Device=C5:87:1C:CC:95:68 Status=0
    D/DeviceC5:87:1C:CC:95:68: Enable Notifications initGatt() 
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a19-0000-1000-8000-00805f9b34fb enable: true
    D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
    

    I think the problem is, that I connect to the second device, when service discovery, enable notification, write descriptor,.. have not finished..

    the nRFMaster Control Panel app works fine with 2 peripherals, so i dont think it is an issue regarding the android phone...

Children
No Data
Related