- 如何解决函数里异步调用问题?
test:async function(){ var that=this; console.log('0'); const p=await new Promise(function(resolve,reject){ that.a(); resolve(); }) console.log('2'); }, a:function(){ wx.showModal({ showCancel: false, confirmText:'确定', content:'1', title:'提示', success:function(res){ if(res.confirm){ console.log('1'); } } }) 如何在函数里调用另一个函数?目的是按顺序执行输出012,我试过直接将wx.showModal放到Promise里是可以按顺序输出的。
2022-03-10 - ios11.1 wifi连接ESP32问题?
想通过小程序连接ESP32模块配网(AP模式),用AT指令已设置好,但小程序好像连不上,串口工具也没有显示相关信息? [图片] 手机->设置连上后串口会显示下图,但小程序什么都没有返回信息? [图片]
2021-05-14 - 蓝牙第二次搜索出来设备缺少?
求助大神帮助,现场有7-8蓝牙模块,第一次搜到一个能显示出来,第二次能显示两个,但后台显示有四个,为什么不能全部显示出来? Page({ data:{ devices:[], }, onPullDownRefresh:function(){ this.onBluetoothDeviceFound(); }, show_device:function(){ //初始化蓝牙模块 wx.openBluetoothAdapter({ success: (res) => { console.log('openBluetoothAdapter success',res); //获取本机蓝牙适配器状态 wx.getBluetoothAdapterState({ success:(res)=>{ console.log('getBluetoothAdapterState',res); //discovering是否在搜索 if(res.discovering){ this.onBluetoothDeviceFound(); //available蓝牙适配器是否可用 }else if(res.available){ wx.startBluetoothDevicesDiscovery({ allowDuplicatesKey: true, success:(res)=>{ console.log('startBluetoothDevicesDiscovery success',res); this.onBluetoothDeviceFound(); }, fail:(res)=>{ console.log('搜索蓝牙失败'); } }) } } }) }, }) console.log(this.data.devices); }, onBluetoothDeviceFound:function(){ var i=0; wx.getBluetoothDevices({ success: (res) => { console.log(res); res.devices.forEach((device)=>{ if(!device.name||!device.localName){ return; } var name=`devices[${i}].name`; var deviceId=`devices[${i}].deviceId`; var rssi=`devices[${i}].rssi`; var localName=`devices[${i}].localName`; this.setData({[name]:device.name,[deviceId]:device.deviceId,[rssi]:device.RSSI,[localName]:device.localName}); i=+1; }) }, }) }, stop_device:function(){ this.stopBluetoothDevicesDiscovery(); }, stopBluetoothDevicesDiscovery:function(){ wx.stopBluetoothDevicesDiscovery(); }, conn_event:function(e){ console.log(e); } }) [图片][图片]
2020-04-09 - 如何将字符串转换成16进带“0x”开头?
最近学习蓝牙模块,将字符串转换成16进制形式发到蓝牙模块,但转换出来开头缺少符号“0x”,如字符串"1234",转成 ["31", "32", "33", "34"],但蓝牙模块无法识别,只能识别[0x31, 0x32, 0x33, 0x34]这个形式,网上下载代码 stringToBytes:function(str){ var array = []; array.push("0x"); for (var i = 0; i < str.length; i++) { array.push((str.charCodeAt(i)).toString(16)); } array.join(""); console.log(array); let buffer = new Uint16Array (array).buffer; return array; }, 但结果["31", "32", "33", "34"]一样是无,求大神救助。
2020-02-18