- onBLECharacteristicValueChange返回ArrayBuffer一堆0 ?
[图片] [图片] 无论输入什么?监听到的都是一堆0,这是什么原因? // 【6】获取服务 getServices() { let that = this uni.getBLEDeviceServices({ deviceId: that.deviceId, success(res) { that.serviceId = res.services[0].uuid uni.showToast({ title: '获取服务成功' }) }, fail(err) { console.error(err) uni.showToast({ title: '获取服务失败', icon: 'error' }) } }) }, // 【7】获取特征值 getCharacteristics() { let that = this uni.getBLEDeviceCharacteristics({ deviceId: that.deviceId, serviceId: that.serviceId, success(res) { that.characteristicId = res.characteristics[0].uuid //微信小程序调试 uni.showToast({ title: '获取特征值成功' }) }, fail(err) { console.error(err) uni.showToast({ title: '获取特征值失败', icon: 'error' }) } }) }, // 【8】开启消息监听 notify() { let that = this uni.notifyBLECharacteristicValueChange({ deviceId: that.deviceId, // 设备id serviceId: that.serviceId, // 监听指定的服务 characteristicId: that.characteristicId, // 监听对应的特征值 state: true, type:'notification', success: (res) => { console.log(res); if (res.errMsg == "notifyBLECharacteristicValueChange:ok") { console.log("开启消息监听------", res); this.listenMessage() } }, fail(err) { console.error(err) uni.showToast({ title: '监听失败', icon: 'error' }) } }) }, // 16进制字符串转ArrayBuffer hex2ArrayBuffer() { let hex_str = '68656c6c6f20776f726c64' let typedArray = new Uint8Array(hex_str.match(/[\da-f]{2}/gi).map(function(h) { return parseInt(h, 16) })) let buffer = typedArray.buffer return buffer }, // 【9】监听消息变化 listenMessage() { let that = this console.log(9999999) uni.onBLECharacteristicValueChange((res) => { console.log("发送过来的数据---------", res) let resHex = that.ab2hex(res.value) console.log(resHex) that.messageHex = resHex let result = that.hexCharCodeToStr(resHex) console.log(String(result)) that.message = String(result) }) }, // ArrayBuffer转16进度字符串示例 ab2hex(buffer) { const hexArr = Array.prototype.map.call( new Uint8Array(buffer), function(bit) { return ('00' + bit.toString(16)).slice(-2) } ) return hexArr.join('') }, // 将16进制的内容转成我们看得懂的字符串内容 hexCharCodeToStr(hexCharCodeStr) { var trimedStr = hexCharCodeStr.trim(); var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr; var len = rawStr.length; console.log(len) if (len % 2 !== 0) { alert("存在非法字符!"); return ""; } var curCharCode; var resultStr = []; for (var i = 0; i < len; i = i + 2) { curCharCode = parseInt(rawStr.substr(i, 2), 16); resultStr.push(String.fromCharCode(curCharCode)); } console.log(resultStr) return resultStr.join(""); },
2022-06-17 - wx.compressImage压缩后的地址没有扩展名?
wx.compressImage({ src: item.url, quality: 80, success: function(res) { console.log('压缩', res) that.ReleaseTalkFormData.chooseImgPath.push({ url:res.tempFilePath, type:'image' }) } }) 压缩 {errMsg: "compressImage:ok", tempFilePath: "http://tmp/MIHjMKNw0jlH2c15de62a23625618a00d08249ac5b16"}
2021-01-12 - 微信小程序支持H5页面嵌入占当前页的一半吗?
在小程序里引入了外部H5页面,使用web-view只能在新的页面打开并且铺满整个屏幕,有没有办法让嵌入的链接不在新页面打开,让页面只是占用当前页规定的部分大小
2020-10-21 - received error code login 重启 重新安装都真机演示不了?
[图片]
2020-09-01