读取制造商数据 BLE 设备 react-native-ble-plx

Read Manufacturer data BLE device react-native-ble-plx

嗨,我需要使用 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]

我不知道该怎么办。

在本机 iOS 中,我得到 Apple 本身提供的 DATA 格式的输出。不确定如何处理

要求 我需要将该子范围 2..<3 转换为 Uint8 并检查 Uint8 结果是否包含一些整数

谁能帮我解析这些数据?

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

使用buffer js库,可以使用以下代码片段实现:

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'