0
votes

i am implementing an android app using BLE technology. the bluetooth device has been designed to measure the temperature. it uses cc2541 from TI.the hardware test using BTool Bluetooth low Energy Pc application v1.40.5 is interacting fine withe the device: we write in characteristic value 0x2f and start command 0100 and for inputing downstream command(23 53 54 00 6e 00 00 ... FE) we use as characteristics value 0x2b. the question is how to realise the same test in my android app .i 'm able to connect to the ble devise , read the available services and characteristics, don't know where to write commands or read characteristics.

1

1 Answers

3
votes

To write a new value to a characteristic using the Android BLE API you need to first update the value of the characteristic locally, then write that characteristic to the remote device and then wait for the callback onCharacteristicRead to be called.

Example, to write a value to the characteristic of a remote BLE device:


1) Connect to remote BLE device
2) Discover services and characteristics
3) Find from the BluetoothGatt the BluetoothGattservice that you are looking for
4) Find from the BluetoothGattservice the BluetoothGattCharacteristic that you want to update its value
5) Set the new value locally to the BluetoothGattCharacteristic by using the mCurrentCharacteristic.setValue(value) method
6) Write the updated characteristic to the remote BLE device by using the mBluetoothGatt.writeCharacteristic(mCurrentCharacteristic) method
7) Then wait for the callback onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) to be called to make sure if the characteristic was written successfully to the remote BLE device

To read a characteristic value from a remote BLE device:


1) Connect to remote BLE device
2) Discover services and characteristics
3) Find from the BluetoothGatt the BluetoothGattservice that you are looking for
4) Find from the BluetoothGattservice the BluetoothGattCharacteristic that you want to read its value
5) Call the readCharacteristic(BluetoothGattCharacteristic characteristic) method
6) Then wait for the callback onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) to be called to retrieve the characteristic from the remote BLE device
7) Use the characteristic.getValue() to get the data from the characteristic

Also have a look at the following link