首页 > 解决方案 > 在 base64 中编码一个整数以通过 BLE 发送

问题描述

我正在开发这个应用程序,我正在使用蓝牙库(https://github.com/Polidea/react-native-ble-plx),我需要使用 base64 (https://github.com/eranbo /react-native-base64#readme ) 将一个整数作为状态保存到 BLE 模块。有没有办法使用base64发送整数?

根据文档,我们需要编写以下内容 -

device.writeCharacteristicWithResponseForService(

serviceUUID: UUID,

characteristicUUID: UUID,

valueBase64: Base64)

然后写入模块:

device.writeCharacteristicWithResponseForService('uuidServ', 'uuidCharc', base64Data) 

这是我到目前为止所尝试的:

const base64Data = base64.encode(bytes(this.state.totalSec)); 
console.log(base64Data); 

有没有办法获取 base64 数据以便我可以将其发送到 BLE 模块?

标签: javascriptreact-nativebase64bluetooth-lowenergy

解决方案


推荐阅读