【问题标题】:Read Manufacturer data BLE device react-native-ble-plx读取制造商数据 BLE 设备 react-native-ble-plx
【发布时间】:2021-02-17 01:11:39
【问题描述】:

您好,我需要使用 React-native 进行 BLE 集成。

我正在使用这个包:https://polidea.github.io/react-native-ble-plx/

我已经成功搜索了一个 BLE 设备,现在我需要读取它的制造商数据并检查一些值

问题:我正在获取字符串 (Base64) 格式的制造商数据,并使用以下代码转换为字节数组。

convertStringToByteArray(str) {
        String.prototype.encodeHex = function () {
            var bytes = [];
            for (var i = 0; i < this.length; ++i) {
                bytes.push(this.charCodeAt(i));
            }
            return bytes;
        };
    
        var byteArray = str.encodeHex();
        return byteArray
    }

结果如下。

[xx, xx, xx, xx, xx, xx, xx, xx]

我不知道该怎么做。

在 Native iOS 中,我得到 Apple 自己提供的 DATA 格式的输出。这个不知道怎么处理

要求 我需要将该子范围 2..

谁能帮我解析这些数据?

【问题讨论】:

    标签: android ios react-native bluetooth bluetooth-lowenergy


    【解决方案1】:

    使用buffer js库,可以使用如下sn-p实现:

    var Buffer = require('buffer/').Buffer
    
    
    const strval = "base-64-encoded-string";
    const buffer = new Buffer(strval, 'base64');
    const bufStr = buffer.toString('hex'); //make sure to encode it as 'hex' and not 'string'
    

    【讨论】:

      【解决方案2】:

      发现解决方案字符串是 base64 ENCODED 我必须先解码字符串然后转换为字节数组

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-22
        • 1970-01-01
        • 2021-02-21
        • 2013-11-24
        • 1970-01-01
        • 1970-01-01
        • 2013-08-21
        • 1970-01-01
        相关资源
        最近更新 更多