Reputation: 21
I have the following working code:
const monitorMultipleCharacteristics = async () => {
try {
const monitorPromises = uuids.map(({ serviceUUID, characteristicUUID }) => {
return new Promise((resolve, reject) => {
BLEService.monitorCharacteristicForDevice(
serviceUUID,
characteristicUUID,
async data => {
case UUID:
const temperature = parse(data.value)
break
case UUID:
console.log('dispatch service')
break
default:
console.log('Unknown UUID', data.uuid)
}
setTimeout(resolve, 100, data)
console.info('success', new Date().getTime())
},
async error => {
console.error(error)
await BLEService.finishMonitor()
reject()
}
)
// Store the subscription so it can be cleaned up later
//subscriptions.push(subscription)
})
// Wait for each monitor to be set up
})
Promise.all(monitorPromises)
.then(data => {
console.log(data)
})
.catch(error => {
console.error('Error in one of the monitors:', error)
})
} catch (error) {
console.error('Error setting up characteristic monitoring:', error)
}
// Optionally return the subscriptions if you need to stop monitoring later
//return subscriptions
}
I am able to connect to the device. Also monitorCharacteristicForDevice for device works for one serviceUUID and characteristicUUID but I want to get it working for 5 services and charecteristics. Is this possible using the react-native-ble-plx library?
Upvotes: 0
Views: 30