苹果手机发送蓝牙指令失败,安卓可以成功
发布于 5 年前 作者 jing86 15794 次浏览 来自 问答

var that = this;

var hex = ‘01313233343536’

var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {

return parseInt(h, 16)

}))

console.log(typedArray)

console.log([0xAA, 0x55, 0x04, 0xB1, 0x00, 0x00, 0xB5])

var buffer1 = typedArray.buffer

console.log(wx.canIUse(‘writeBLECharacteristicValue’))

wx.writeBLECharacteristicValue({

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

deviceId: that.data.connectedDeviceId,

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

// serviceId: that.data.writeServicweId,

serviceId: ‘00008000-0101-0001-4A6F-796D65746572’,

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

// characteristicId: that.data.writeCharacteristicsId,

characteristicId: ‘00008004-0101-0001-4A6F-796D65746572’,

// 这里的value是ArrayBuffer类型  

value: buffer1,

success: function (res) {

wx.showLoading({

title: ‘入网中’,

})

6 回复

谢谢,不问真找不到问题在哪里。可以了,谢谢

fail write ValueToCharacteristics error 10004

serviceId , 和 characteristicId我是直接写死的 。

10004no service没有找到指定服务

麻烦在 write ValueToCharacteristics 前保证依次调用 wx.getBLEDeviceServices 与 wx.getBLEDeviceCharacteristics ,并在write时传入之前get获取到的 serviceId 与 characteristicId。

对的,iOS需要执行 wx.getBLEDeviceServices 与 wx.getBLEDeviceCharacteristics 来获取到蓝牙设备 服务 与 特征值 的实例,才能做后面的数据读写,没办法直接hardcode serviceId与characteristicId 就能执行读写操作的。

你好,失败的表现是什么,有错误信息或者错误码么?

回到顶部