Android的BLE onCharacteristicChanged不叫 [英] Android BLE onCharacteristicChanged not called

查看:2889
本文介绍了Android的BLE onCharacteristicChanged不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目,该项目包括蓝兆BLE113模块和Android应用程序。
在蓝兆模块我已经建立了几个特点。
对于一个最大的特点我定义了一个描述符激活客户端通知(在我的情况下,客户端是Android应用程序)。
在BLE113模块的特征定义是这样的:

I'm working on a project which includes a Bluegiga BLE113 module and an Android app. On the Bluegiga module I've set up several characteristics. For one characteristic I defined a descriptor to activate the client notification (in My case, the client is the Android app.). The characteristic definition of the BLE113 module looks like this:

:
<characteristic uuid="dcfa2671-974d-4e4a-96cd-6221afeabb62" id="ez1_flow_data_out">
  <!-- org.bluetooth.descriptor.gatt.characteristic_user_description -->
  <description>Data to transmit to Android device</description>
  <properties write="true" read="true" />
  <value variable_length="true" length="255" type="hex" />
  <!-- org.bluetooth.descriptor.gatt.client_characteristic_configuration -->
  <descriptor uuid="2902">
    <properties write="true" read="true" const="false" />
    <!-- Bit 0 = 1: Notifications enabled -->
    <value type="hex">0001</value>
    </descriptor>
:
:
</characteristic>

在Android端我已经设置了根据Android的蓝牙低能耗导 onServicesDiscovered(...)回调内部通知:

characteristic = gatt.getService(BLEuuids.DATAFLOW_SERVICE).getCharacteristic(BLEuuids.DATAFLOW_OUT_CHARACT);
//Enable local notifications
gatt.setCharacteristicNotification(characteristic, true);
//Enabled remote notifications
BluetoothGattDescriptor desc = characteristic.getDescriptor(BLEuuids.DATAFLOW_OUT_DESCRIPT);
boolean test;
test = desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);  // return value = true
test = gatt.readDescriptor(desc);  // return value = true
test = gatt.writeDescriptor(desc);  // return value = true

不过,如果我改变DATAFLOW_OUT_C​​HARACT特点UUID的值,使用蓝兆模块的串行接口,预期回调 onCharacteristicChanged(...)不是触发我的Andr​​oid应用。

However, if I change the Value of the DATAFLOW_OUT_CHARACT characteristics UUID, using the serial interface of the Bluegiga Module, the intended callback onCharacteristicChanged(...) isn't triggered on My Android app.

推荐答案

尽量不要读取的描述符。
不要写描述符中设置之后。
正确读取将覆盖你的设置和你相同的值写入了?

Try not to READ descriptor. Do write descriptor right after set. Properly the read will overwrite your set and you write the same value back?

这篇关于Android的BLE onCharacteristicChanged不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆