I am developing an android application with BLE. The requirement of this application is to update the voltage variation in a specific hardware with various inputs.
So I am writing the characters to the BLE as 8-bit input. Each bit value contains its own representations. Based on each request hardware will respond and provide various output combinations. The output contains 24 bytes of information. Each byte position represents different value. eg: position 1& 2 represent current, 3 & 4 represent voltage etc. My problem here is, I am getting the output as 4 parts. Each message contains 6 bytes. Is it possible to get the same in a single message?
Implementation
public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) { //Check that we have access to a Bluetooth radio
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
int test = characteristic.getProperties(); //Get the properties of the characteristic
if ((test & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0 && (test & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) { //Check that the property is writable
return;
}
DebugLogs.writeToFile("BLE MODULE Before Write " + characteristic);
if (mBluetoothGatt.writeCharacteristic(characteristic)) { //Request the BluetoothGatt to do the Write
Log.v(TAG, "****************WRITE CHARACTERISTIC SUCCESSFULL**" + characteristic); //The request was accepted, this does not mean the write completed
DebugLogs.writeToFile("BLE MODULE AFTER Write SUCCESS " + characteristic);
} else {
Log.d(TAG, "writeCharacteristic failed"); //Write request was not accepted by the BluetoothGatt
DebugLogs.writeToFile("BLE MODULE AFTER Write FAIL " + characteristic);
}
}
And the response is getting in the Gatt callback
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
Log.w(TAG, "**ACTION_DATA_AVAILABLE**" + characteristic.getUuid());//Indication or notification was received
broadcastUpdate(BLEConstants.ACTION_DATA_AVAILABLE, characteristic); //Go broadc
ast an intent with the characteristic data }