首页 > 解决方案 > 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”

标签: ionic-frameworkbluetooth-lowenergy

解决方案


您可以尝试以下方法:

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])))

推荐阅读