Hello I'm trying to communicate between my bluetooth sensor and my phone using BLE Manager.
I'm trying to create a React-Native app.
async function onlyWrite(){
let command = ['XX', 'XX', 'XX', 'XX', 'XX', '00','00','00','00','00','00','00','00','00','00','00','00','00', 'XX','XX'];
let data = command.map(x => {return parseInt(x, 16);});
const writeBuffer = await BleManager.write(
"XX:XX:XX:XX:XX:XX",
'XXXXXXXX-0000-XXXX-XXXX-XXXXXXXXXXXX',
'XXXXXXXX-0000-XXXX-XXXX-XXXXXXXXXXXX',
data,
35
)
.then(async() => {
console.log(`*******************************Sent ${data}`);
console.log("*******************************ONLYWRITE Response From Slave(peripheral)="+JSON.stringify(writeBuffer));
})
.catch((error) => {
console.log(error);
});
console.log("writeBuffer:"+ writeBuffer);
return writeBuffer;//The respond this is the output
}
HERE I CALL THE FUNCTION WITH A BUTTON
<View style={{margin: 10}}>
<Button title=" OnlyWrite " onPress={ () => console.log("OnlyWriteResponse:"+onlyWrite()) } />
</View>
!!!THE OUTPUT HERE!!!: PICTURE The Log of the function.
There was a function I didn't saw here is the solution. Just get the data.value into a variable.
const handleUpdateValueForCharacteristic = (data) => {//Just LOG
console.log('Received data from ' + data.peripheral + ' characteristic ' + data.characteristic, data.value);
writeBuffer=data.value;
}