蓝牙BLE接收,苹果数据不一致,安卓数据正常
发布于 5 年前 作者 shiwei 1158 次浏览 来自 问答

蓝牙设备收到任何数据,返回对应的数据。

现在用安卓手机,

发送AA5504B10022B5

收到AA5504B10022B5

但是用苹果手机,

发送AA5504B10022B5

收到4552522b41540a

发送接口:

sendfun: function () {

var that = this;

var hex = ‘AA5504B10022B5’

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(buffer1)

wx.writeBLECharacteristicValue({

deviceId: that.data.deviceId,

serviceId: that.data.serviceId,

characteristicId: that.data.characteristicswrite,

value: buffer1,

success: function (res) {

// success

console.log(“success  指令发送成功”);

console.log(res);

},

fail: function (res) {

// fail

console.log(res);

},

complete: function (res) {

// complete

}

})

},

接收接口:

wx.onBLECharacteristicValueChange(function (characteristic) {

console.log(`characteristic ${characteristic.characteristicId} has changed, now is ${characteristic.value}`)

console.log(‘characteristic value comed:’, characteristic.value)

console.log(that.buf2hex(characteristic.value));

})

转换接口:

buf2hex: function (buffer) { // buffer is an ArrayBuffer

return Array.prototype.map.call(new Uint8Array(buffer), x => (‘00’ + x.toString(16)).slice(-2)).join(’’);

},

请帮忙看看!!!

回到顶部