我目前拥有一个LilyPad Simblee板- RFD77101,我试图用它建立一个自定义服务的连接,使用Simblee.customUUID命令在arduino 1.6.5IDE中定义该服务。
后来,我尝试使用我之前创建的UUID,使用BluetoothleGatt示例代码获取Android中的服务和特性。
问题是当我连接到Simblee时,应用程序无法识别该服务,并记录了以下错误。
未找到自定义BLE服务
代码有点长,所以我不会直接发布所有的代码。如果有人对我的问题和需求以及代码的一部分有一个解决方案,我显然非常乐意发布它。
感谢任何人事先。
这是我试图获得以下特征的公开空白:
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("fe84-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("2d30c083-f39f-4ce6-923f-3484ea480596"));
if(!mBluetoothGatt.readCharacteristic(mReadCharacteristic)) {
Log.w(TAG, "Failed to read characteristic");
}
}发布于 2017-08-15 07:54:58
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("fe84-0000-1000-8000-00805f9b34fb"));您提供的UUID格式不正确。根据文档,第一个连字符之前的部分应该由4个十六进制八进制组成(参见您提供的特征),但这里只有2个。应该在前面添加填充0,如下所示
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000fe84-0000-1000-8000-00805f9b34fb"));编辑:这里漏掉了一点。你打电话给mBluetoothGatt.discoverServices()了吗?
https://stackoverflow.com/questions/45686539
复制相似问题