微信小程序的蓝牙搜索不到HC-06蓝牙模块
发布于 5 年前 作者 taomao 14706 次浏览 来自 问答

- 当前 Bug 的表现(可附上截图)

搜索不到蓝牙模块HC-06,我的蓝牙模块HC-06的mac值是:00:14:03:05:66:FC。

同时打开手机的蓝牙和订位功能,在微信小程序中真机调试,运行微信蓝牙程序后,页面展示只搜索得到其他的蓝牙设备,没有HC-06。

- 预期表现

搜索得到蓝牙模块HC-06

- 复现路径

给蓝牙模块HC-06上电,打开微信蓝牙,搜索周围蓝牙设备,界面上会出现搜索到的蓝牙设备。

- 提供一个最简复现 Demo

//搜索设备
 lanya3: function () {
   var that = this;
   wx.startBluetoothDevicesDiscovery({
     success: function (res) {
       that.setData({
         msg: "搜索设备" + JSON.stringify(res),
       })
       //监听蓝牙适配器状态
       wx.onBluetoothAdapterStateChange(function (res) {
         that.setData({
           sousuo: res.discovering ? "在搜索。" : "未搜索。",
           status: res.available ? "可用。" : "不可用。",
         })
       })
     }
   })
 },
 // 获取所有已发现的设备
 lanya4: function () {
   var that = this;
   wx.getBluetoothDevices({
     success: function (res) {
       //是否有已连接设备
       wx.getConnectedBluetoothDevices({
         success: function (res) {
           console.log(JSON.stringify(res.devices));
           that.setData({
             connectedDeviceId: res.deviceId
           })
         }
       })
       
       that.setData({
         msg: "搜索设备" + JSON.stringify(res.devices),
         devices: res.devices,
       })
          
       //监听蓝牙适配器状态
       wx.onBluetoothAdapterStateChange(function (res) {
         that.setData({
           sousuo: res.discovering ? "在搜索。" : "未搜索。",
           status: res.available ? "可用。" : "不可用。",
         })
       })
     }
   })
 },
1 回复

解决了哈。微信小程序蓝牙的开发是指基于蓝牙4.0的低功耗蓝牙开发。只能与4.0协议设备通信,适应节能且仅收发少量数据的设备(如手环、智能体温计)。HC-06是基于蓝牙2.0协议的。

回到顶部