小程序 蓝牙API使用全流程

其中需要注意的是消息格式

发送的信息应该转成相应的格式

javascript 复制代码
const combineData = (arr: any[]) => {
    const buffer = new ArrayBuffer(5)
    const dataView = new DataView(buffer)
    // 声明16进制数值 数组
    // 循环数组 并求和
    arr.forEach((item, index) => {
        dataView.setUint8(index, item)
    })
    const sum = arr.reduce((prev, curr) => {
        return prev + curr
    })
    dataView.setUint8(4, sum)
    return buffer as unknown as any[]
}

返回的信息也需要转换

javascript 复制代码
            const hex = Array.prototype.map
                .call(new Uint8Array(res.value), (bit) => {
                    return `00${bit.toString(16)}`.slice(-2)
                })
                .join('')
相关推荐
hello kitty w8 小时前
2. 微信开发工具快捷键
小程序
计算机毕设指导68 小时前
基于微信小程序的丽江市旅游分享系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·旅游
1024小神8 小时前
浏览器或小程序限制字体最小12px解决办法
小程序
内存不泄露9 小时前
酒店预订管理平台及小程序
小程序
2501_915918419 小时前
除了 Perfdog,如何在 Windows 环境中完成 iOS App 的性能测试工作
android·ios·小程序·https·uni-app·iphone·webview
weixin_lynhgworld10 小时前
[特殊字符]短剧小程序开发:开启娱乐新纪元的钥匙[特殊字符]
小程序
qq_124987075311 小时前
基于Spring Boot的“味蕾探索”线上零食购物平台的设计与实现(源码+论文+部署+安装)
java·前端·数据库·spring boot·后端·小程序
m0_4711996311 小时前
【小程序】订单数据缓存 以及针对海量库存数据的 懒加载+数据分片 的具体实现方式
前端·vue.js·小程序
難釋懷12 小时前
微信小程序案例 - 自定义 tabBar
微信小程序·小程序·notepad++
2501_9151063213 小时前
常见 iOS 抓包工具的使用方式与组合思路
android·ios·小程序·https·uni-app·iphone·webview