• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android BLE write data on multiple BLE h/w simultaneously

I am working on an android app where I am using android BLE api for connecting to sensor devices.Things are going good but I am connecting 4 BLE h/w devices with my android app but when I try to write some data on all 4 BLe devices at same time it only writes data on a single device and I can't write data on all devices simultaneously.

Here is my code to write data on single BLE device:

if(btWriteGattChar == null)
return;
btWriteGattChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
btWriteGattChar.setValue(dat);
mBluetoothGatt[tabIndex].writeCharacteristic(btWriteGattChar);

The above code works find for single BLE device but it won't allow me to write the same data on all rest of devices.

Please let me know where I am doing wrong step to write same data on multiple BLE devices.
 
Last edited:
In order to write data to multiple BLE devices simultaneously, you will need to write to each device in turn using separate BluetoothGatt objects.

You can do this by creating a separate BluetoothGatt object for each device, and then using the writeCharacteristic method on each BluetoothGatt object to write data to the corresponding device.

Here is an example of how you might write data to multiple BLE devices simultaneously:

Code:
for (int i = 0; i < numDevices; i++) {
  BluetoothGatt gatt = mBluetoothGatt[i];
  BluetoothGattCharacteristic charac = btWriteGattChar[i];
  charac.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
  charac.setValue(dat);
  gatt.writeCharacteristic(charac);
}

Note that writing to multiple BLE devices simultaneously may take longer than writing to a single device, as each write operation will need to be performed in sequence. You may need to adjust your code to account for this.

It's also worth noting that some BLE devices may not support concurrent write operations, in which case you may need to implement some kind of queueing mechanism to ensure that writes are performed in the correct order.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones