I'm new on Ble-Plx and React-Native, I'm working on a project where we should be able to connect to a device and change the behavior, just writing new characteristics and it should change... I used a Ble Starter that I found on the internet, and I was able to write the characteristics and change the behavior. So I know the peripheral can do it and that I only need to develop the code. I have something already but when I write the characteristics the device doesn't change as we spect, the device does NOTHING and I don't get any error or something Just the device does nothing. Here is a piece of code if someone can help would be amazing!
HERE IS THE MAIN PART OF THE CODE:
import { BleManager } from 'react-native-ble-plx';
const manager = new BleManager();
const Example=()=>{
useEffect(() => {
manager.onStateChange((state) => {
const subscription = manager.onStateChange((state) => {
if (state === 'PoweredOn') {
scanAndConnect();
subscription.remove();
}
}, true);
return () => subscription.remove();
});
}, [manager])
function scanAndConnect() {
console.log('Escanear')
manager.startDeviceScan(null,null,async(error,device)=>{
console.log(device.id)
if(device.id ==='D1:42:78:C8:AB:FB' || device.id ==='D1:42:BF:F1:D9:3C'){
manager.stopDeviceScan()
console.log("ID del dispositivo: ", device.id)
console.log("Nombre del dispositivo: ", device.name)
console.log("RRSI del dispositivo: ", device.rssi)
console.log("MTU del dispositivo: ", device.mtu)
device.connect()
.then((device) => {
const services = device.discoverAllServicesAndCharacteristics()
console.log(services)
})
.catch((error) => {
// Handle errors
console.log(error)
});
}
if (error) {
console.log(error)
return
}
})
}
const writeChar=async()=> {
var text = (Buffer.from("AA0100000200").toString('base64'));
manager.writeCharacteristicWithoutResponseForDevice(
'D1:42:BF:F1:D9:3C',
'aae0',
'aae1',
text,
)
.then(() => {
console.log("Write: " + text);
})
.catch((error) => {
console.log(error);
});
}
AND HERE IS WHAT THE CONSOLE.LOG GIVE ME BACK.
D1:42:BF:F1:D9:3C
LOG ID del dispositivo: D1:42:BF:F1:D9:3C
LOG Nombre del dispositivo: Bluetrum-MX
LOG RRSI del dispositivo: -73
LOG MTU del dispositivo: 23
LOG {"_U": 0, "_V": 0, "_W": null, "_X": null}
LOG Write: QUEwMTAwMDAwMjAw
BUT even that there is no error the device doesn't change so there is my problem, I'm NOT able to make the device change the behavior and start the vibration (just by writing the characteristics)