首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能建立与自定义服务的连接

未能建立与自定义服务的连接
EN

Stack Overflow用户
提问于 2017-08-15 04:33:59
回答 1查看 357关注 0票数 0

我目前拥有一个LilyPad Simblee板- RFD77101,我试图用它建立一个自定义服务的连接,使用Simblee.customUUID命令在arduino 1.6.5IDE中定义该服务。

后来,我尝试使用我之前创建的UUID,使用BluetoothleGatt示例代码获取Android中的服务和特性。

问题是当我连接到Simblee时,应用程序无法识别该服务,并记录了以下错误。

未找到自定义BLE服务

代码有点长,所以我不会直接发布所有的代码。如果有人对我的问题和需求以及代码的一部分有一个解决方案,我显然非常乐意发布它。

感谢任何人事先。

这是我试图获得以下特征的公开空白:

代码语言:javascript
复制
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");
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-15 07:54:58

代码语言:javascript
复制
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("fe84-0000-1000-8000-00805f9b34fb"));

您提供的UUID格式不正确。根据文档,第一个连字符之前的部分应该由4个十六进制八进制组成(参见您提供的特征),但这里只有2个。应该在前面添加填充0,如下所示

代码语言:javascript
复制
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000fe84-0000-1000-8000-00805f9b34fb"));

编辑:这里漏掉了一点。你打电话给mBluetoothGatt.discoverServices()了吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45686539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档