在线看毛片视频-国产免费av在线-欧美日韩一区二区三区-国产成人无码av在线播放无广告-亚洲人va欧美va人人爽-国产第一草草-西班牙黄色片-四虎在线网站8848-最新av片免费网站入口-东京热无码中文字幕av专区-日本大人吃奶视频xxxx-欧美精品一区二区三区四区五区-国产片天天弄-国产免费内射又粗又爽密桃视频-欧美爱爱网站-日韩v欧美

當(dāng)前位置:雨林木風(fēng)下載站 > 應(yīng)用軟件教程 > 詳細(xì)頁(yè)面

微信小程序--Ble藍(lán)牙

微信小程序--Ble藍(lán)牙

更新時(shí)間:2025-10-03 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

導(dǎo)微信小程序,簡(jiǎn)稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應(yīng)用,它實(shí)現(xiàn)了應(yīng)用“觸手可及”的夢(mèng)想,用戶掃一掃或搜一下即可打開應(yīng)用。小程序是一種不用下載就能使用的應(yīng)用,也是一...
微信小程序,簡(jiǎn)稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應(yīng)用,它實(shí)現(xiàn)了應(yīng)用“觸手可及”的夢(mèng)想,用戶掃一掃或搜一下即可打開應(yīng)用。小程序是一種不用下載就能使用的應(yīng)用,也是一項(xiàng)門檻非常高的創(chuàng)新,經(jīng)過將近兩年的發(fā)展,已經(jīng)構(gòu)造了新的小程序開發(fā)環(huán)境和開發(fā)者生態(tài)。
本文主要介紹了微信小程序--Ble藍(lán)牙的實(shí)現(xiàn)方法。文中附上源碼下載,具有很好的參考價(jià)值。下面跟著小編一起來看下吧

有一段時(shí)間沒有。沒有寫關(guān)于小程序的文章了。3月28日,微信的api又一次新的更新。期待已久的藍(lán)牙api更新。就開始擼一番。

源碼地址

1.簡(jiǎn)述

藍(lán)牙適配器接口是基礎(chǔ)庫(kù)版本 1.1.0 開始支持。

iOS 微信客戶端 6.5.6 版本開始支持,Android 客戶端暫不支持

藍(lán)牙總共增加了18個(gè)api接口。

2.Api分類

搜索類

連接類

通信類

3.API的具體使用

詳細(xì)見官網(wǎng):

https://mp.weixin.qq.com/debug/wxadoc/dev/api/bluetooth.html#wxgetconnectedbluethoothdevicesobject

4. 案例實(shí)現(xiàn)

4.1 搜索藍(lán)牙設(shè)備

/**
 * 搜索設(shè)備界面
 */
Page({
 data: {
 logs: [],
 list:[],
 },
 onLoad: function () {
 console.log('onLoad')
var that = this;
// const SDKVersion = wx.getSystemInfoSync().SDKVersion || '1.0.0'
// const [MAJOR, MINOR, PATCH] = SDKVersion.split('.').map(Number)
// console.log(SDKVersion);
// console.log(MAJOR);
// console.log(MINOR);
// console.log(PATCH);

// const canIUse = apiName => {
// if (apiName === 'showModal.cancel') {
//  return MAJOR >= 1 && MINOR >= 1
// }
// return true
// }

// wx.showModal({
// success: function(res) {
//  if (canIUse('showModal.cancel')) {
//  console.log(res.cancel)
//  }
// }
// })
  //獲取適配器
  wx.openBluetoothAdapter({
  success: function(res){
  // success
  console.log("-----success----------");
   console.log(res);
   //開始搜索
  wx.startBluetoothDevicesDiscovery({
 services: [],
 success: function(res){
 // success
  console.log("-----startBluetoothDevicesDiscovery--success----------");
  console.log(res);
 },
 fail: function(res) {
 // fail
  console.log(res);
 },
 complete: function(res) {
 // complete
  console.log(res);
 }
})

  },
  fail: function(res) {
   console.log("-----fail----------");
  // fail
   console.log(res);
  },
  complete: function(res) {
  // complete
   console.log("-----complete----------");
   console.log(res);
  }
 })

  wx.getBluetoothDevices({
  success: function(res){
   // success
   //{devices: Array[11], errMsg: "getBluetoothDevices:ok"}
   console.log("getBluetoothDevices");
   console.log(res);
   that.setData({
   list:res.devices
   });
   console.log(that.data.list);
  },
  fail: function(res) {
   // fail
  },
  complete: function(res) {
   // complete
  }
  })

 },
 onShow:function(){

 },
 //點(diǎn)擊事件處理
 bindViewTap: function(e) {
  console.log(e.currentTarget.dataset.title);
  console.log(e.currentTarget.dataset.name);
  console.log(e.currentTarget.dataset.advertisData);

 var title = e.currentTarget.dataset.title;
 var name = e.currentTarget.dataset.name;
  wx.redirectTo({
  url: '../conn/conn?deviceId='+title+'&name='+name,
  success: function(res){
   // success
  },
  fail: function(res) {
   // fail
  },
  complete: function(res) {
   // complete
  }
  })
 },
})

4.2連接 獲取數(shù)據(jù)

/**
 * 連接設(shè)備。獲取數(shù)據(jù)
 */
Page({
 data: {
  motto: 'Hello World',
  userInfo: {},
  deviceId: '',
  name: '',
  serviceId: '',
  services: [],
  cd20: '',
  cd01: '',
  cd02: '',
  cd03: '',
  cd04: '',
  characteristics20: null,
  characteristics01: null,
  characteristics02: null,
  characteristics03: null,
  characteristics04: null,
  result,

 },
 onLoad: function (opt) {
  var that = this;
  console.log("onLoad");
  console.log('deviceId=' + opt.deviceId);
  console.log('name=' + opt.name);
  that.setData({ deviceId: opt.deviceId });
  /**
   * 監(jiān)聽設(shè)備的連接狀態(tài)
   */
  wx.onBLEConnectionStateChanged(function (res) {
   console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
  })
  /**
   * 連接設(shè)備
   */
  wx.createBLEConnection({
   deviceId: that.data.deviceId,
   success: function (res) {
    // success
    console.log(res);
    /**
     * 連接成功,后開始獲取設(shè)備的服務(wù)列表
     */
    wx.getBLEDeviceServices({
     // 這里的 deviceId 需要在上面的 getBluetoothDevices中獲取
     deviceId: that.data.deviceId,
     success: function (res) {
      console.log('device services:', res.services)
      that.setData({ services: res.services });
      console.log('device services:', that.data.services[1].uuid);
      that.setData({ serviceId: that.data.services[1].uuid });
      console.log('--------------------------------------');
      console.log('device設(shè)備的id:', that.data.deviceId);
      console.log('device設(shè)備的服務(wù)id:', that.data.serviceId);
      /**
       * 延遲3秒,根據(jù)服務(wù)獲取特征 
       */
      setTimeout(function () {
       wx.getBLEDeviceCharacteristics({
        // 這里的 deviceId 需要在上面的 getBluetoothDevices
        deviceId: that.data.deviceId,
        // 這里的 serviceId 需要在上面的 getBLEDeviceServices 接口中獲取
        serviceId: that.data.serviceId,
        success: function (res) {
         console.log('000000000000' + that.data.serviceId);
         console.log('device getBLEDeviceCharacteristics:', res.characteristics)
         for (var i = 0; i < 5; i++) {
          if (res.characteristics[i].uuid.indexOf("cd20") != -1) {
           that.setData({
            cd20: res.characteristics[i].uuid,
            characteristics20: res.characteristics[i]
           });
          }
          if (res.characteristics[i].uuid.indexOf("cd01") != -1) {
           that.setData({
            cd01: res.characteristics[i].uuid,
            characteristics01: res.characteristics[i]
           });
          }
          if (res.characteristics[i].uuid.indexOf("cd02") != -1) {
           that.setData({
            cd02: res.characteristics[i].uuid,
            characteristics02: res.characteristics[i]
           });
          } if (res.characteristics[i].uuid.indexOf("cd03") != -1) {
           that.setData({
            cd03: res.characteristics[i].uuid,
            characteristics03: res.characteristics[i]
           });
          }
          if (res.characteristics[i].uuid.indexOf("cd04") != -1) {
           that.setData({
            cd04: res.characteristics[i].uuid,
            characteristics04: res.characteristics[i]
           });
          }
         }
         console.log('cd01= ' + that.data.cd01 + 'cd02= ' + that.data.cd02 + 'cd03= ' + that.data.cd03 + 'cd04= ' + that.data.cd04 + 'cd20= ' + that.data.cd20);
         /**
          * 回調(diào)獲取 設(shè)備發(fā)過來的數(shù)據(jù)
          */
         wx.onBLECharacteristicValueChange(function (characteristic) {
          console.log('characteristic value comed:', characteristic.value)
          //{value: ArrayBuffer, deviceId: "D8:00:D2:4F:24:17", serviceId: "ba11f08c-5f14-0b0d-1080-007cbe238851-0x600000460240", characteristicId: "0000cd04-0000-1000-8000-00805f9b34fb-0x60800069fb80"}
          /**
           * 監(jiān)聽cd04cd04中的結(jié)果
           */
          if (characteristic.characteristicId.indexOf("cd01") != -1) {
           const result = characteristic.value;
           const hex = that.buf2hex(result);
           console.log(hex);
          }
          if (characteristic.characteristicId.indexOf("cd04") != -1) {
           const result = characteristic.value;
           const hex = that.buf2hex(result);
           console.log(hex);
           that.setData({ result: hex });
          }

         })
         /**
          * 順序開發(fā)設(shè)備特征notifiy
          */
         wx.notifyBLECharacteristicValueChanged({
          deviceId: that.data.deviceId,
          serviceId: that.data.serviceId,
          characteristicId: that.data.cd01,
          state: true,
          success: function (res) {
           // success
           console.log('notifyBLECharacteristicValueChanged success', res);
          },
          fail: function (res) {
           // fail
          },
          complete: function (res) {
           // complete
          }
         })
         wx.notifyBLECharacteristicValueChanged({
          deviceId: that.data.deviceId,
          serviceId: that.data.serviceId,
          characteristicId: that.data.cd02,
          state: true,
          success: function (res) {
           // success
           console.log('notifyBLECharacteristicValueChanged success', res);
          },
          fail: function (res) {
           // fail
          },
          complete: function (res) {
           // complete
          }
         })
         wx.notifyBLECharacteristicValueChanged({
          deviceId: that.data.deviceId,
          serviceId: that.data.serviceId,
          characteristicId: that.data.cd03,
          state: true,
          success: function (res) {
           // success
           console.log('notifyBLECharacteristicValueChanged success', res);
          },
          fail: function (res) {
           // fail
          },
          complete: function (res) {
           // complete
          }
         })

         wx.notifyBLECharacteristicValueChanged({
          // 啟用 notify 功能
          // 這里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中獲取
          deviceId: that.data.deviceId,
          serviceId: that.data.serviceId,
          characteristicId: that.data.cd04,
          state: true,
          success: function (res) {
           console.log('notifyBLECharacteristicValueChanged success', res)
          }
         })

        }, fail: function (res) {
         console.log(res);
        }
       })
      }
       , 1500);
     }
    })
   },
   fail: function (res) {
    // fail
   },
   complete: function (res) {
    // complete
   }
  })
 },

 /**
  * 發(fā)送 數(shù)據(jù)到設(shè)備中
  */
 bindViewTap: function () {
  var that = this;
  var hex = 'AA5504B10000B5'
  var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
   return parseInt(h, 16)
  }))
  console.log(typedArray)
  console.log([0xAA, 0x55, 0x04, 0xB1, 0x00, 0x00, 0xB5])
  var buffer1 = typedArray.buffer
  console.log(buffer1)
  wx.writeBLECharacteristicValue({
   deviceId: that.data.deviceId,
   serviceId: that.data.serviceId,
   characteristicId: that.data.cd20,
   value: buffer1,
   success: function (res) {
    // success
    console.log("success 指令發(fā)送成功");
    console.log(res);
   },
   fail: function (res) {
    // fail
    console.log(res);
   },
   complete: function (res) {
    // complete
   }
  })

 },
 /**
  * ArrayBuffer 轉(zhuǎn)換為 Hex
  */
 buf2hex: function (buffer) { // buffer is an ArrayBuffer
  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
 }
})


5.效果展示

發(fā)送校驗(yàn)指令。獲取結(jié)果

以上就是微信小程序--Ble藍(lán)牙的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


小程序是一種不需要下載安裝即可使用的應(yīng)用,它實(shí)現(xiàn)了應(yīng)用“觸手可及”的夢(mèng)想,用戶掃一掃或者搜一下即可打開應(yīng)用。

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

在线看毛片视频-国产免费av在线-欧美日韩一区二区三区-国产成人无码av在线播放无广告-亚洲人va欧美va人人爽-国产第一草草-西班牙黄色片-四虎在线网站8848-最新av片免费网站入口-东京热无码中文字幕av专区-日本大人吃奶视频xxxx-欧美精品一区二区三区四区五区-国产片天天弄-国产免费内射又粗又爽密桃视频-欧美爱爱网站-日韩v欧美
  • <li id="86scu"><menu id="86scu"></menu></li>
    <li id="86scu"></li>
    <button id="86scu"></button>
  • <s id="86scu"></s><button id="86scu"><menu id="86scu"></menu></button>
  • 久久久久久久高清| 蜜臀av.com| www.cao超碰| 中文字幕在线观看日 | 好吊妞无缓冲视频观看| 成熟了的熟妇毛茸茸| 干日本少妇首页| 手机免费看av网站| 国产毛片久久久久久国产毛片| 97中文字幕在线| 99热手机在线| 日韩成人手机在线| 久久精品网站视频| 18视频在线观看娇喘| 日本一本二本在线观看| www.51色.com| 成年人免费在线播放| 裸体裸乳免费看| 丰满少妇被猛烈进入高清播放| 国产精品一区二区小说| 欧美一级中文字幕| 国产aaaaa毛片| 国产日韩av网站| 伊人五月天婷婷| 免费午夜视频在线观看| 影音先锋成人资源网站| 欧美精品成人网| 国产欧美日韩小视频| 8x8x成人免费视频| 97xxxxx| 色婷婷777777仙踪林| 中文字幕永久视频| 日韩精品―中文字幕| 300部国产真实乱| 天堂av8在线| 日韩在线第三页| 国产91xxx| 东北少妇不带套对白| 51自拍视频在线观看| 国产视频在线视频| 成人久久久久久久久| 女人帮男人橹视频播放| 干日本少妇视频| 国产精品自拍视频在线| 日本www高清视频| 免费无码毛片一区二三区| 裸体大乳女做爰69| av不卡在线免费观看| 国模私拍视频在线观看| 中文字幕第21页| 日韩欧美黄色大片| 黑鬼大战白妞高潮喷白浆| 91九色在线观看视频| 日本在线xxx| 国产高清av在线播放| 日本一道在线观看| 四虎4hu永久免费入口| 四虎永久免费网站| 超碰在线免费av| 午夜av中文字幕| 欧美h视频在线观看| 黄瓜视频免费观看在线观看www| 日韩成人精品视频在线观看| 五月天激情播播| 免费看啪啪网站| 国产制服91一区二区三区制服| 超碰97在线看| 欧美精品自拍视频| 久草青青在线观看| 国产免费又粗又猛又爽| 午夜视频在线网站| 青娱乐精品在线| 福利在线一区二区| 日韩有码免费视频| www午夜视频| 亚洲五码在线观看视频| 僵尸世界大战2 在线播放| 午夜精品久久久久久久无码 | 欧美日韩一区二区三区69堂| 中文字幕永久视频| 99中文字幕在线观看| 亚洲国产成人精品无码区99| 日韩视频第二页| av污在线观看| 伊人再见免费在线观看高清版| 欧美午夜小视频| 热久久精品国产| 亚洲免费视频播放| 青青艹视频在线| 99re6在线观看| 妺妺窝人体色www看人体| 免费毛片小视频| 激情在线观看视频| 国产精品无码av在线播放| 午夜国产一区二区三区| 成人小视频在线观看免费| 国语对白做受xxxxx在线中国| 激情五月婷婷基地| 少妇av一区二区三区无码| 天天干天天草天天| 国产特级黄色大片| 超碰成人在线免费观看| 欧美两根一起进3p做受视频| 又色又爽又黄视频| 日韩精品一区二区三区久久| 欧美午夜精品理论片| 日韩精品xxxx| 肉大捧一出免费观看网站在线播放| 777米奇影视第四色| 国产尤物av一区二区三区| 亚洲图色中文字幕| av观看免费在线| 无码人妻aⅴ一区二区三区日本| 已婚少妇美妙人妻系列| 久久男人资源站| 无套内谢丰满少妇中文字幕 | 老司机午夜av| 日韩av高清在线看片| 四虎4hu永久免费入口| 亚欧激情乱码久久久久久久久| 精品中文字幕av| 污污污污污污www网站免费| 8x8x成人免费视频| 欧美一级视频在线| 国产又大又黄又粗又爽| 欧美v在线观看| 久久国产亚洲精品无码| 欧美又粗又长又爽做受| 国产大尺度在线观看| www亚洲国产| 国产成年人在线观看| 永久免费黄色片| 亚洲综合在线一区二区| 色黄视频免费看| 欧美视频国产视频| 中文字幕 日韩 欧美| 麻豆三级在线观看| 国产精品区在线| 亚洲黄色av片| 三级黄色片免费观看| 中文字幕在线观看日| 欧洲美女亚洲激情| 久久最新免费视频| 四虎精品欧美一区二区免费| 国产日产欧美一区二区| 欧美高清中文字幕| 免费无码不卡视频在线观看| 日本韩国欧美在线观看| 欧美xxxxx在线视频| 午夜欧美福利视频| 午夜激情影院在线观看| 欧美a级黄色大片| 日韩日韩日韩日韩日韩| 久章草在线视频| 九九九九九国产| 黄色特一级视频| 免费在线a视频| 国产九九在线观看| 熟妇熟女乱妇乱女网站| 日韩一级特黄毛片| 激情网站五月天| 在线观看日本www| 免费极品av一视觉盛宴| 久久免费视频3| www.午夜av| 欧美牲交a欧美牲交| 在线播放av中文字幕| 成人在线视频一区二区三区| 18禁男女爽爽爽午夜网站免费| 亚洲一级片网站| 国产手机免费视频| 午夜免费福利视频在线观看| 黄色录像特级片| 国产又大又黄又粗的视频| av动漫在线免费观看| 午夜免费福利在线| 亚洲 欧美 综合 另类 中字| 亚洲第一狼人区| 欧美一级免费播放| 在线一区二区不卡| 欧美精品99久久| 午夜久久久久久久久久久| 亚洲天堂av线| 美女日批免费视频| 日韩视频一二三| theporn国产精品| 男女曰b免费视频| 夜夜添无码一区二区三区| 成人不卡免费视频| 男人搞女人网站| 黄www在线观看| 国产精品入口芒果| 女女同性女同一区二区三区按摩| 日韩 欧美 高清| 欧美深夜福利视频| 黄色成人在线免费观看| 加勒比av中文字幕| www.com污| 日日噜噜噜噜久久久精品毛片| 男人靠女人免费视频网站 |