发数剧的时候启用notify失败
发布于 6 年前 作者 kfang 8396 次浏览 来自 问答

给蓝牙设备发送数据的时候,启用notify失败

var that = this;

wx.notifyBLECharacteristicValueChange({

    state: true, // 启用 notify 功能

    // 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取

    deviceId: that.data.deviceId,

    // 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取

    serviceId: that.data.wifi_data.service.uuid,

    // 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取

    characteristicId: that.data.wifi_data.characteristic.uuid,

    success: function (res) {

        console.log(‘notifyBLECharacteristicValueChange success’, res.errMsg)

    

    },

    complete: function (res) {

        console.log(res)

    }

})

wx.onBLECharacteristicValueChange(function (res) {

    console.log(‘特征值变化’, res);

    const CharacteristicVal = that.buf2hex(res.value);

    if (res.characteristicId == that.data.wifi_uuid) {

        that.setData({

            device_char: CharacteristicVal

        });

    }

});

写数据是在上述两个接口执行后,间隔2s执行的,启用notify的特征值查看明确是是支持notify的,执行的时候直接是走到fail的 ,咋回事???

7 回复

你们的特征值是不是notify和indicate都支持?

同样的问题,解决了么?

indicate不支持的,如果成功的话监听特征值变化的接口应该会触发啊,但是并没有

对于一个设备的一个特征值 多次启用notify没影响吧???

可以验证一下,之前遇过这种情况,其实是 notify 成功的

在android手机上没有错误码,在IOS手机上看是1008 :the attribute could not be found  但是我可以确定的是

开启notify的特征值notify:true

fail 回调返回的错误码是什么呢?

回到顶部