- wx.openAddress的Api报错,为啥用不了?
微信开发工具调试报错 [图片] $(function() { // 初始化微信接口 function initParams() { var url = getHost()+"/weChatWeb/webInitJs"; var parmas = { trType:"webInitJs", url:window.location.href.split('#')[0] }; $.ajax({ url:url, type:"POST", async:true, data:JSON.stringify(parmas), dataType:"json", contentType:"application/json", success:function(data){ // layer.msg(JSON.stringify(data)); if(data.retCode == '00'){ wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端layer.msg出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: data.appId, // 必填,公众号的唯一标识 timestamp: data.timestamp, // 必填,生成签名的时间戳 nonceStr: data.nonceStr, // 必填,生成签名的随机串 signature: data.signature,// 必填,签名,见附录1 jsApiList: ['openAddress', 'checkJsApi', 'editAddress'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); }else { layer.msg(data.retMsg); } } }); } // 初始化微信接口调用 initParams(); wx.ready(function() { console.log('进来微信'); wx.openAddress({ success: function (res) { alert(res, '成功') var userName = res.userName; // 收货人姓名 var postalCode = res.postalCode; // 邮编 var provinceName = res.provinceName; // 国标收货地址第一级地址(省) var cityName = res.cityName; // 国标收货地址第二级地址(市) var countryName = res.countryName; // 国标收货地址第三级地址(国家) var detailInfo = res.detailInfo; // 详细收货地址信息 var nationalCode = res.nationalCode; // 收货地址国家码 var telNumber = res.telNumber; // 收货人手机号码 }, error: (res) => { alert(res) console.log(res, '错误的res') } }); }) })
2022-03-31 - 利用wx.onBLECharacteristicValueChange监听的值来做应答但是只能接收?
/*蓝牙升级通讯协议(小程序与单片机的应答) ------------------------------------------------------------------------------------------------------------------ * 五、开始下载后小程序自动重复发送每一组数据,直到收到单片机应答信息后,开始连续下载; * 六、单片机每收到一组数据,计算校验和,如果正确则应答接收正确,否则应答接收错误; * 七、接收正确应答:2B 4F 4B CF 75 * 八、接收错误应答:2D 45 52 52 00 A4 * 九、全部下载结束后停止 ------------------------------------------------------------------------------------------------------------------ [图片] 就是我这边只能监听变化的值,却不能通过获取硬件发送过来这个值进行发送,求大佬们怎么解决这是我的部分代码 wx.onBLECharacteristicValueChange(function (res) { console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`, 99999999999999999999) console.log(ab2hex(res.value)) // ArrayBuffer转16进制字符串 console.log(res.value) that.setData({ valueChange: valueChangeData + "|" + ab2hex(res.value), //前端显示蓝牙接收数据 }) valueChangeData = valueChangeData + '|' + ab2hex(res.value); console.log("valueChangeData", valueChangeData) var a = []; a.push(valueChangeData) console.log(a, "A") var b = (a.toString()).split('|') console.log(b) valueChangeDataArray = b//定义的全局变量 // that.testSend1() // that.writePackageData1() var success = [43, 79, 75, 207, 117]; var successArrayBuffer = new Uint8Array(success).buffer; console.log(successArrayBuffer) var fail = [45, 45, 52, 52, 0, 164] var failArrayBuffer = new Uint8Array(fail).buffer; console.log(failArrayBuffer) if (ab2hex(res.value) == ab2hex(successArrayBuffer)) { console.log("接收正确应答") // that.testSend1() //that.package20Write() } else if (ab2hex(res.value) == ab2hex(failArrayBuffer)) { console.log("接收错误应答,重新回调") // that.testSend2() } }) }, testSend1() { this.writeRealData1(deviceIdConnected, serviceIdConnected, characteristicsIdConnected, sendFile) }, writeRealData1(deviceId, serviceId, characteristicId, packageData) { const arrays = packageData; console.log(arrays, "所有的1k") var valueChange = valueChangeDataArray; //监听的数组 var index; if (valueChange instanceof Array) { valueChange.splice(0, 1); if (valueChange.length % 57 == 0) { index = valueChange.length / 57 } else { index = parseInt(valueChange.length / 57) } } else if (valueChange == undefined) { index = 0 } console.log(valueChange) console.log(index, "长度") var success = "2b4f4bcf75" //监听成功的值 var fail = "2d4552520a4" //监听失败的值 const data = arrays[index] || null, self = this console.log("第", index, "包数据", data) self.writePackageData1(deviceId, serviceId, characteristicId, data) }, writePackageData1(deviceId, serviceId, characteristicId, Data) { /** hex2int(hex)字符串转16进制 */ /**concatenate(resultConstructor, ...arrays)合并arraybuffer */ /////////////////校检和 ////////////////////// function CRC(array) { var len = array.length, sum = 0; for (let i = 0; i < len; i++) { sum += array[i] } return sum.toString(16) } /////////////////////// //////////////////////// var valueChange = valueChangeDataArray; //监听的数组 console.log(valueChange) var valueChangeleng; if (valueChange instanceof Array) { valueChange.splice(0, 1); valueChangeleng = valueChange.length - parseInt(valueChange.length / 57) * 57 } else if (valueChange == undefined) { valueChangeleng = 0 } const array = Data; console.log(array, "array") var arr = [] for (let i = 0; i < array.byteLength; i += 18) { arr.push(array.slice(i, i + 18)) } var uintBuffer = new Uint8Array(arr[valueChangeleng]) console.log("uintBuffer", uintBuffer) var uintBuffers = concatenate(Uint8Array, Uint8Array.of(valueChangeleng), uintBuffer) console.log("uintBuffers", uintBuffers) var array1 = Array.from(uintBuffers) //console.log(CRC.ToCRC16(array1),"校检和") console.log(CRC(array1), "校检和") array1.push(hex2int(CRC(array1).slice(1, 3))) var arrayBuffer = new Uint8Array(array1).buffer; console.log("arrayBuffer", arrayBuffer) const data = arrayBuffer || null, self = this console.log("第", valueChangeleng, "次", "发送的数据为", data) var success = "2b4f4bcf75" //监听成功的值 var fail = "2d4552520a4" //监听失败的值 if (valueChangeleng == 0) { wx.writeBLECharacteristicValue({ deviceId, serviceId, characteristicId, value: data, success: function () { console.log("我是第一个数据包") } }) } else if (data && data instanceof ArrayBuffer && valueChange[valueChangeleng] == success) { wx.writeBLECharacteristicValue({ deviceId, serviceId, characteristicId, value: data, success: function () { console.log("success,成功") if (valueChangeleng < arr.length) { sleep(20) self.writePackageData1(deviceId, serviceId, characteristicId, Data) } } }) } else if (data && data instanceof ArrayBuffer && valueChange[valueChangeleng] == fail) { wx.writeBLECharacteristicValue({ deviceId, serviceId, characteristicId, value: data, success: function () { console.log("fail,失败") self.writePackageData1(deviceId, serviceId, characteristicId, Data, valueChangeleng - 1) } }) } },
2021-01-19 - wx.writeBLECharacteristicValue发送几十kb的数据怎么分成1k1k发送?
大佬们请帮帮忙解答一下,谢谢大佬了
2021-01-06 - 微信小程序连接蓝牙后发送几十k的数据后接收到的数据与发送的数据不一致?
wx.writeBLECharacteristicValue(Object object)我的代码是这样的,先获取读取文本内容保存在一个变量里,以hex格式保存。再通过Arraybuffer的slice方法分成0到1024为1k,for循环,每循环一次发送1k,但是这1k还要分20个字节发送,所以要给它设置延时20ms,这样能获取到数据,但每次获取的数据与读出文本的内容不一致,后面我就在每1k先加个帧头,其中有个帧头是代表发送的次数,后面测试发现,帧头少了就代表少发送1k,有的内容不全,因为每1k的长度是一样的,请问这个问题怎么解决求大佬教,可以私聊,有偿,谢谢啦 [图片]
2020-12-19 - received error code 1 on sync-0
[图片]
2020-12-15 - 微信小程序蓝牙发送数据分包后setuint8超过255个字节如何处理?
我是将一个1到1024的整数通过微信小程序蓝牙发送,它到255就终止了,256-1024的数没有发送出去,而且一直循环发送0-255?请问我该怎么办?还要在处理一次分255为一次再处理吗 ?求大佬教我 [图片]
2020-12-09