ionic-framework - Ionic BLE 制造商特定数据
问题描述
使用@ionic-native/ble
我能够扫描并发现具有制造商特定数据的 BLE 设备。
根据库(https://github.com/don/cordova-plugin-ble-central#ios-1),这是获取此数据的方法
const mfgData = new Uint8Array(device.advertising.kCBAdvDataManufacturerData);
console.log('Manufacturer Data: ', mfgData);
const hex = Buffer.from(mfgData).toString('hex');
console.log(hex);
编码为十六进制的结果是2604 0504 386 55c0b
我不明白的是使用这个结果来解码制造商(公司)id的正确方法,它应该是“0x0426”
解决方案
您可以尝试以下方法:
const toHexString = bytes =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
console.log(toHexString(new Uint8Array([0, 1, 2, 42, 100, 101, 102, 255])))
推荐阅读
- java - 为什么从 Lock 创建条件,而不是使用“new”运算符?
- json - 如何解决 Odoo 控制器中的 SSL 错误分配键值
- sql - 在 Excel 公式中引用日期单元格时保持单元格格式
- javascript - 如何将包含符号的数组转换为字符串?
- python - Anaconda env 正在使用另一个 env 的站点包
- python - 关于 python argparse
- ios - JSC:致命:尝试释放访问权限,但 mutator 没有访问权限
- java - 运行 Eclipse 应用程序时的 log4j 警告
- botframework - 如何在 webchat react.js 中重置/清除对话?
- jenkins - Terraform 不会将本地目录绑定到容器的文件系统