本文实例为大家分享了微信小程序使用蓝牙小插件,供大家参考,具体内容如下
bluetooth.js
function BLE(options) { this.optiOns= options || { locator: {} }; } function ab2hex(buffer) { const hexArr = Array.prototype.map.call( new Uint8Array(buffer), function (bit) { return ('00' + bit.toString(16)).slice(-2) } ) return hexArr.join('-') }; BLE.prototype = { open: function (callback) {//打开适配器 成功 调用callback(); wx.openBluetoothAdapter({ success(res) { if (typeof callback != "undefined") { callback(); } }, fail(res) { console.log(res) } }) }, scan: function (callback) {//扫描设备 成功 调用callback(ls); wx.startBluetoothDevicesDiscovery({ success(res) { wx.getBluetoothDevices({ success(res) { console.log(res); var ls = []; for (var i = 0; i
index.js
const Ble = require('../../lib/bluetooch/bluetooch'); var ble = new Ble.BLE();
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。