问题
While developing an application for IOT tried communicating with a BLE peripheral device. Using BLE Lollipop API.
Each BluetoothGattService can provide different BluetoothGattCharacteristic, each representing a certain value which can be Read, Write or Notified.
Value is communicated in various formats. But there is no way to know which format a particular Characteristic is encoded in.
I thought this mKeySize could be a solution but, it is neither accessible nor being used inside BluetoothGattCharacteristic to determine any value output.
/**
* Returns the deisred key size.
* @hide
*/
/*package*/ int getKeySize() {
return mKeySize;
}
I made use of following functions to check out desired output.
String getStringValue (int offset)
getIntValue(int formatType, int offset)
getFloatValue(int formatType, int offset)
But they were only useful in certain cases where communicated data was not complex e.g
DeviceName -> (getStringValue)
BatteryLevel ->(getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,0))
They were easy bait but characteristics like Peripheral Preferred Connection Parameters nowhere to be recognized.
I have already used a static hashmap to retrieve Specification Name based on their assigned number which seems to grow bigger in size to include all adapted BLE profile.
I would like to know are there any better methods available to fetch BluetoothGattCharacteristics value appropriately?
Also, there are different ways to write characteristic value and at certain places specific value, how should I approach this uncertainty?
Check out this android application BLEScanner, to a major extent can perform Read and Write.
来源:https://stackoverflow.com/questions/37432958/how-to-get-bluetoothgattcharacteristic-value-format-type