更新记录

1.0.5(2025-01-09) 下载此版本

1

1.0.4(2025-01-06) 下载此版本

增加设备过滤方式

1.0.3(2024-12-17) 下载此版本

1

查看更多

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 app-vue × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序 鸿蒙元服务
× × × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

x-bluetooth

蓝牙设备通信

示例

import { sleep } from '@/uni_modules/x-tools/tools/index.js'
import { bufferUtil, DeviceControl } from '@/uni_modules/x-bluetooth/index.js'

const deviceControl = new DeviceControl({
    // mode: 'name', // 通过设备名寻找
    // filter: 'xxx', // 设备名
    mode: 'fun', // 通过自定义函数过滤
    filter: device => {
        const { name, advertisData } = device

        const arr = bufferUtil.ab2hexArr(advertisData)

        // 设备广播数据第一字节等于 01, 同时设备名包含 xxx 通过过滤
        if (arr[0] === '01' && name.includes('xxx')) {
            device.advertisDataArr = arr
            return true
        }
    },
    serviceId: 'xxxxxxxx', // 服务 uuid
})

deviceControl.startFind(async (device, devices) => {
    console.log('找到目标设备', device);

    if (device.deviceId === deviceControl.connectedDeviceId) return

    await deviceControl.connect(device.deviceId)
    console.log('connect');

    await sleep(1000)
    await deviceControl.setNotify()
    console.log('notify');

    await sleep(1000)
    deviceControl.startListenerCharacteristicValueChange()

    await sleep(1000)
    const cmd = bufferUtil.arr2ab([0x1, 0x1, 0x2, 0x3])
    await deviceControl.execCmd(cmd).then(res => {
        console.log('执行结果', res);
    }).catch(console.log)

}).then(res => {
    console.log('startFind');
})

隐私、权限声明

1. 本插件需要申请的系统权限列表:

蓝牙相关权限

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问