【问题标题】:Ionic BLE Manufacturer specific DataIonic BLE 制造商特定数据
【发布时间】:2020-05-19 16:22:40
【问题描述】:

使用 @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-framework bluetooth-lowenergy


    【解决方案1】:

    您可以尝试以下方法:

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

    【讨论】:

    • 谢谢,但似乎没有任何改变,Uint8Array(device.advertising.kCBAdvDataManufacturerData){"0":38,"1":4,"2":5,"3":4,"4":56,"5":101,"6":92,"7":11}
    • 你能给我device.advertising.kCBAdvDataManufacturerData的控制台
    • { CDVType = ArrayBuffer;数据=“JgQFBDhlXAs=”; }
    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多