https://www.cnblogs.com/ckfuture/p/16450418.html
https://www.cnblogs.com/yangxiaobai123/p/16021058.html
字符串转base64:https://www.cnblogs.com/sunny3158/p/17312158.html
将 ArrayBuffer 对象转成 Base64 字符串:基础 - uni.arrayBufferToBase64 - 《uni-app API 文档》 - 书栈网 · BookStack
ArrayBuffer:https://zhuanlan.zhihu.com/p/655456833
最近在做一个项目,要求app通过蓝牙连接设备并将报文传输至设备中,在这个过程踩过了几个坑,总结如下:
根据uni-app官网API主要涉及到“蓝牙”和“低功耗蓝牙”两个部分。
主要步骤:
步骤1:初始化蓝牙模块 openBluetoothAdapter
$openBluetoothAdapter(){
uni.openBluetoothAdapter({
success: (res) => {
//初始化成功,搜索设备
console.log('openBluetoothAdapter success', res);
uni.showLoading({
title: '搜索设备中'
});
setTimeout(()=>{
this.baseList=[];//每次扫码清空设备列表,不然会导致重复
this.$startBluetoothDevicesDiscovery();//扫码蓝牙设备
},100);
//定时关闭搜索设备
setTimeout(()=>{
this.$stopBluetoothDevicesDiscovery();
uni.hideLoading();
},10*1000);
},
fail: (res) => {
uni.showToast({
title: '请打开蓝牙',
duration: 1000
});
if (res.errCode === 10001) {
//监听蓝牙适配器状态变化事件
uni.onBluetoothAdapterStateChange(function(res){
console.log('onBluetoothAdapterStateChange', res);
if (res.available) {
//开始扫描
this.$startBluetoothDevicesDiscovery()
}
})
}
}
})
},