Reputation: 346
Hi I need to work with BLE integration using React-native.
I am using this package: 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
issue: I am getting manufacturer data in string (Base64) format and I converted into byte array with following code.
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. 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
can anyone help me how I can parse such data ?
Upvotes: 2
Views: 2059
Reputation: 51
Using buffer js library, it can be achieved using the following snippet:
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'
Upvotes: 2
Reputation: 346
Found solution string was base64 ENCODED I have to decode string first then convert to byte array
Upvotes: 0