javascriptreact-nativebluetooth-lowenergyreact-native-ble-plx

Why cant i see any notifications when i send data to device over BLE?


I'm trying to make an app that sends commands to a BLE device and i cant get any feedback. I am using a library called ble.plx which has an option to monitor characteristics but it wont output anything for me. I need to read values from notifications to use later in my code. This is my first time working with BLE in general so i have no idea what i am doing wrong. I know serviceUUID and characteristicUUID are correct. I am out of ideas.

Here is my code:

function scanAndConnect() {
BLTManager.startDeviceScan(null, null, (error, device) => {
    if (error) {
        // Handle error (scanning will be stopped automatically)
        return
    }

    // Check if it is a device you are looking for based on advertisement data
    // or other criteria.
    if (device.name=='Audio PCM Streamer') {
        console.log(device.name);
        // Stop scanning as it's not necessary if you are scanning for one device.
        BLTManager.stopDeviceScan();

        device.connect()
        .then((device) => {
          return device.discoverAllServicesAndCharacteristics()
        })
        .then( (device) => {
          device.monitorCharacteristicForService(SERVICE_UUID,CHARACTERISTIC_UUID,(err,result)=>{
            if(err) {
              console.log(err)
              return;
            }
            console.log(result);
          }); Subscription  
          device.requestMTU(251)
          let data = Uint8Array(9);
          data[0]=0xA5;
          data[1]=0xA5;
          data[2]=0xA5;
          data[3]=0xA5;
          var b64encoded = btoa(decoder.decode(data));
          device.writeCharacteristicWithoutResponseForService(SERVICE_UUID,CHARACTERISTIC_UUID,b64encoded);

        
        })
        .catch((error) => {
    // Handle errors
        });

       }
    });

}


Solution

  • I did this completely wrong do not use this or try to fix this its just bad.