I have struggled for a few days to find a way to authenticate to my Mi Band 3 using React Native. I'm using react-native-ble-plx to make the connection. I can search for the nearby devices and I can even connect to the band, but when I try to call some service or characteristic, anything happens.
Upon a few hours of searching, I realized that the problem might be the authentication, so I started looking for that, but I can't find anything. I found a question similar to this one, but the only answer was to 'do some googling', which I did... a lot.
Here's what I have now
const connectToSelectedDevice = async() => {
try{
if(selectedDeviceId != 0 ){
manager.stopDeviceScan()
manager.connectToDevice(selectedDeviceId).then(async(device)=>{
const services = await device.discoverAllServicesAndCharacteristics()
device.monitorCharacteristicForService('0000fee0-0000-1000-8000-00805f9b34fb','0000ff0e-0000-1000-8000-00805f9b34fb',(error, characteristic) => {
if (error) {
console.error("Error at receiving data from device", error);
return
}
else {
console.log('monitor success')
console.log('monitor success' + characteristic.value);
this.state.messagesRecieved.push(characteristic.value)
}
})
device.writeCharacteristicWithResponseForService('0000fee0-0000-1000-8000-00805f9b34fb','0000ff0e-0000-1000-8000-00805f9b34fb','AQ==')
.then(characteristic => {
console.log("Successfully sent: " + characteristic.value)
return
})
.catch(err => {
console.log(err)
})
})
}
}
catch(error){
console.log(error);
}
}