我目前有一个正常工作的Android应用程序(下面发布的代码段),该程序可扫描BLE设备,但使用硬编码的UUID仅可用于1个特定设备。当应用程序成功连接并读取具有读取权限的数据时,似乎我想要的数据仅带有NOTIFY和WRITE NO RESPONSE,因此无法正常读取。我正在寻找解决此障碍的解决方案。我已经尝试从所有其他服务及其各自的特征中读取信息,以查看我想要的数据是否存在并且到目前为止没有运气。
我已扫描设备以获取其所有服务和特征(提供的所有服务的屏幕截图):
https://imgur.com/a/mYWnAwO
请记住,我知道我在展示设备的mac地址。但是,知道这是什么类型的设备并不重要。
,以及放在一起使用android应用程序以读取这些服务中的信息。目前,我已将UUID硬编码并连接到可读服务/特征,但是其值始终为0100(显然不是我想要的值)。
public void readCustomCharacteristic() {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
/*check if the service is available on the device*/
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
if(mCustomService == null){
Log.w(TAG, "Custom BLE Service not found");
return;
}
/*get the read characteristic from the service*/
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa12-0000-1000-8000-00805f9b34fb"));
if(mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false){
Log.w(TAG, "Failed to read characteristic");
}
}
public void writeCustomCharacteristic(int value) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
/*check if the service is available on the device*/
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
if(mCustomService == null){
Log.w(TAG, "Custom BLE Service not found");
return;
}
/*get the read characteristic from the service*/
BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa11-0000-1000-8000-00805f9b34fb"));
mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
Log.w(TAG, "Failed to write characteristic");
}
}
出现在我的服务器(外围设备)上的数字必须是通过BLE捕获的值,并且最肯定应该属于这些服务之一和一项特定特征。但是,找到并解密它只是一个问题,这样它就可以在我的终端上变得可读(Android App)。