Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

The device.servicesUUIDs out the then.catch print but inside the value is null

$
0
0

I am using the library react-native-ble-plx to connect Bluetooth using my application, but I need some values, when I log console.log(device) returns me any values, and I found the servicesUUIDs, it is an array an the position zero, contains the id about the module chip I am using, but when I print inside the then().catch(), does not log the value that I need, but the out the then().catch(), print the ID.

Function scanAndConnect()

async function scanAndConnect() {    manager.startDeviceScan(null, null, async (error, device) => {      if (error) {        console.log('Error at if(error): ', error);        return null;      }      if (!device) {        console.log('Error at if(device === null)');        return null;      }      if (device.name === 'MLT-BT05') {        // manager.stopDeviceScan();        /* serviceUUID = 0000ffe0-0000-1000-8000-00805f9b34fb */        if (device.serviceUUIDs) {          console.log(device.serviceUUIDs);        }        // Proceed with connection.        device          .connect()          .then(async (d) => {            const servicesAndCharacteristics = await d.discoverAllServicesAndCharacteristics();            return servicesAndCharacteristics;          })          .then((d) => {            console.log('d.id: ', d.id);            console.log('d.name: ', d.name);            if (d.serviceUUIDs) {              console.log('d.servicesUUIDs[0]: ', d.serviceUUIDs[0]);            }            if (d.solicitedServiceUUIDs) {              console.log('d.solicitedServiceUUIDS: ',                d.solicitedServiceUUIDs[0],              );            }          })          .catch((err) => {            console.log(err);          });      }    });  }

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>