0

I need to send AE A7 04 00 05 09 BC B7 command to BLE device. Can You help me to manage it ? I mean what and how have I to do after connection to device ?

public void WriteValue(String strValue)
    {
            mNotifyCharacteristic.setValue("AE A7 04 00 05 09 BC B7".getBytes());
            mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic);
            boolean sendStatus = mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic);"+mNotifyCharacteristic.getProperties());
    }

@Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                                        int status)
        {
            Log.d("TESTING","status !!!= "+status);
        }
abrutsze
  • 496
  • 1
  • 8
  • 24

1 Answers1

0

You need to convert your string properly to a byte array using a hex to byte array conversion rather than just taking the ascii value of each character.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Can You give an example, please ? Currently I am doing in this way: public void WriteValue(String strValue) { mNotifyCharacteristic.setValue(strValue.getBytes()); mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic); } – abrutsze May 10 '17 at 05:20
  • You have the answer here https://www.google.se/search?q=java+hex+to+byte+array. But make sure to remove the spaces in your string first. – Emil May 10 '17 at 07:13
  • I have changed the code to this one, but the result is the same: String s="AEA704000509BCB7"; byte[] b = new BigInteger(s,16).toByteArray(); mNotifyCharacteristic.setValue(b); mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic); – abrutsze May 10 '17 at 07:31