Read/Write characteristic using custom service BLE in Android

Viewed 307

I am trying to connect the Thermometer with an android device using BLE. I am getting proper results using Gatt characteristics specifications and services. but there is one custom service I am getting from the device.

CUSTOM service (UUID = 00001523-1212-EFDE-1523-785FEABCD123)

CUSTOM characteristic (UUID = 00001524-1212-EFDE-1523-785FEABCD123) [marked as WRITE/INDICATE/NOTIFY in smartphone app)

descriptor (UUID = 00002902-0000-1000-8000-00805F9B34FB marked as READ in smartphone app)

and listing several 8-byte commands to send to the meter waiting for an 8-byte response from it.

Commands are sent using a frame with this format below :

[0x51 0x26 0x00 0x00 0x00 0x00 0xA3 CHK-SUM]

where the checksum is the summation of 1..7 byte.

but How to send this command?

 byte[] buffer = new byte[8];
                     

    req_frame[0] = (byte) 0x51;
    req_frame[1] = (byte) 0x26;
    req_frame[2] = (byte) 0x00;
    req_frame[3] = (byte) 0x00;
    req_frame[4] = (byte) 0x00;
    req_frame[5] = (byte) 0x00;
    req_frame[6] = (byte) 0xA3;
    req_frame[7] = (byte) 0xE6;
                        characteristic.setValue(buffer);
                        characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
                        peripheral.writeCharacteristic(characteristic, buffer, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);

OnCharacteristicWrite gives response success. but onCharacteristicChanged not called.

How to work with this type of Protocol?

0 Answers
Related