[英]Read Manufacturer data BLE device react-native-ble-plx
Hi I need to work with BLE integration using React-native.嗨,我需要使用 React-native 进行 BLE 集成。
I am using this package: https://polidea.github.io/react-native-ble-plx/我正在使用这个包: https : //polidea.github.io/react-native-ble-plx/
I have successfully searched a BLE device now I need to read it's manufacturer data and check for some values我已经成功搜索到一个 BLE 设备,现在我需要读取它的制造商数据并检查一些值
issue: I am getting manufacturer data in string (Base64) format and I converted into byte array with following code.问题:我以字符串 (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
}
which results as below.结果如下。
[xx, xx, xx, xx, xx, xx, xx, xx]
I am not sure how to go with it.我不知道如何去做。
in Native iOS i get output in DATA format which is given by Apple itself.在本机 iOS 中,我以 Apple 自己提供的 DATA 格式获得输出。 not sure how to handle in this不知道如何处理
Requirement I need to convert that subrange 2..<3 to Uint8 and check if Uint8 result contains some integeor要求我需要将该子范围 2..<3 转换为 Uint8 并检查 Uint8 结果是否包含一些整数
can anyone help me how I can parse such data ?谁能帮我解析这些数据?
Using buffer js library, it can be achieved using the following snippet:使用缓冲区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'
发现解决方案字符串是 base64 ENCODED 我必须先解码字符串然后转换为字节数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.