React-native-ble-plx: Base64

Created on 31 Jul 2017  路  2Comments  路  Source: Polidea/react-native-ble-plx

Hello, I have trouble understanding the characteristic value output. I'm working on genuno101 board, for testing purposes I simply increment an index to a 100 and update bluetooth with the value accordingly. As I understand the value is encoded in Base64 and needs to be decoded.
fx the number 4 encoded in base64 is _BA==_, but what I get is _BAAAAA==_ which is not exactly 4.
Do I need some library to decode or im I not understanding this at all? :D

Most helpful comment

Everything depends on your internal characteristic's value representation. From what you just wrote I assume that it is 4 byte integer encoded as little endian. So to increment value you could do:

let value = Buffer.from("BAAAAA==", "base64")
let number = value.readInt32LE()
let newNumber = number + 1
let newValue = Buffer.alloc(4)
newValue.writeInt32LE(newNumber)
let base64 = newValue.toString('base64')

All 2 comments

Everything depends on your internal characteristic's value representation. From what you just wrote I assume that it is 4 byte integer encoded as little endian. So to increment value you could do:

let value = Buffer.from("BAAAAA==", "base64")
let number = value.readInt32LE()
let newNumber = number + 1
let newValue = Buffer.alloc(4)
newValue.writeInt32LE(newNumber)
let base64 = newValue.toString('base64')

Thank you, worked like a charm :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfacommunication-alessandro picture alfacommunication-alessandro  路  4Comments

biks152207 picture biks152207  路  3Comments

kevinmeyvaert picture kevinmeyvaert  路  4Comments

haohcraft picture haohcraft  路  5Comments

paulclark94 picture paulclark94  路  3Comments