This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

onCharacteristicChanged 回调问题

Other Parts Discussed in Thread: CC2541

Hello,各位:

        我在用官方样例的时候, 当客户端有数据发过来的时候,onCharacteristicChanged 该回调方法不是会被调用吗?无论是三星 note3还是LG l70 我都试过,还是不行,我是有调用 setCharacteristicNotification 方法的,如下是我的代码:请教各位是否知道这是怎么回事?

public void setCharacteristicNotification ( BluetoothGattCharacteristic characteristic, boolean enabled) {
           if (mBluetoothAdapter == null || mBluetoothGatt == null) {
              return;
           }
          mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

          BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);

         if (descriptor != null) {
             descriptor.setValue(enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });

             descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
             mBluetoothGatt.writeDescriptor(descriptor);
         }

}

  • mai,

    很简单,你可以在你的CC2541的代码上设置断点看一下,手机设置notification enable的时候有没有到那里。

    另外,你可以用packet sniffer看看空中的交互情况,比如notification 设置对不对,接着cc2541发notification的时候空中有没有发出来。

  • Yan,非常感谢你的解答,之前我调用的Characteristic 属性中不具备notification功能,所以即使设置了也没用,但是后来改用了具有notification功能的Characteristic,但还是不行,估计是模块那边禁用了此功能。