第一个坑就是连接蓝牙设备之后无法获取到serverUUid和蓝牙特征uuid 的坑
解决办法加个定时器延迟获取serverID 就可以获取
第二个坑就是调试的时候一直是按照我们前端思路去调试回调的数据value一直都是空的
就一直认为为什么没有回调数据实际蓝牙设备返回的是二进制数据根本无法打印出来
将二进制数据转换一下打印即可
ab2hex(buffer) {
const hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function (bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('')
},
下面是连接蓝牙设备的全部代码
<template>
<view class="content-box">
<top-bar></top-bar>
<view class="data-box">
<view class="img-box flex-wrap justify-content-center">
<image src="/static/images/lianjie.png" mode=""></image>
</view>
<view class="ft-48 ft-weight-900 text-align-center m-t-52">
PAIRING
</view>
<view class="ft-32 width-100 text-align-center">
<view class="width-100">Please long press on theGREENHILL Robot</view>
<view class="width-100">button to turn it on. Then pressonce again</view>
<view class="width-100 m-t-48">the button to pair yourRobot</view>
</view>
<view class="width-100 text-align-center" style=""></view>
<view class="width-100 text-align-center m-t-52">
<view class="iconfont icon-xiala2-01 ft-color-grey"></view>
</view>
<view class="width-100 text-align-center ft-36 ft-weight-700 m-t-52">
MANUAL PAIRING
</view>
<view class="pd-f-r-40 width-100 flex-nowrap align-items-center m-t-24">
<view>SEARCHING PIQ ROBOT</view>
<view class="m-lt-auto iconfont icon-jiazai ft-color-grey"></view>
</view>
<view class="ft-32 pd-f-r-40 m-t-24">
Ensure yourGREENHILL is turned ON and
thatyour phone Bluetooth is ON. No need
to enterany code for pairing, just select
your Robot inthe list below.
</view>
<view></view>
<view style="height: 84upx;line-height: 60upx;" class="pd-f-r-40 border-bt12 ft-28 ft-color-grey">
Discovery equipment
</view>
<view class="pd-f-r-36">
<view class="">
蓝牙设备服务uuid
</view>
<view v-for="item in serverList" :key="item.uuid" class="">
<view class="ft-color-red">
uuid : {
{item.uui