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); }); } }); }