Ionic BLE 制造商特定数据
Ionic BLE Manufacturer specific Data
使用 @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])))
使用 @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])))