I am trying to discover all services and characteristics for my connected device but I keep getting an error.
connectToDevice: {"message":"Operation timed out","errorCode":3,"attErrorCode":null,"iosErrorCode":null,"androidErrorCode":null,"reason":"GATT exception from MAC address 76:05:9F:C6:86:91, with type BleGattOperation{description='SERVICE_DISCOVERY'}","name":"BleError"}
The operation is timing out, I have tried extending the default time but I still get the same error. Any ideas as to why this doesn't discover services and characteristics first time?
const connectToDevice = async (deviceId:DeviceId) => {
try{
//stop scanning for devices
bleManager.stopDeviceScan();
//use BleManager to connect to device
const deviceConnection = await bleManager.connectToDevice(deviceId);
console.log('Connected To Device: ' + deviceId);
//monitor disconnections
deviceConnection.onDisconnected((error, disconnectedDevice) => {
console.log('onDisconnected Device disconnected: ' + disconnectedDevice.id);
//events.emit("connectionError", true)
});
if(await bleManager.isDeviceConnected(deviceId)){
//console.log('before ServiceDiscovery ' + deviceId + ' is connected ' + await bleManager.isDeviceConnected(deviceId));
console.log('discoverAllServicesAndCharacteristicsForDevice called');
//console.log('before ServiceDiscovery ' + deviceId + ' is connected ' + await bleManager.isDeviceConnected(deviceId));
await bleManager.discoverAllServicesAndCharacteristicsForDevice(deviceId);
//events.emit("connectionError", true)
console.log('Read Validation Char called');
readValidationChar(deviceId);
}
}
catch(error){
console.log("connectToDevice: " + JSON.stringify(error));
throw new Error("Failed to connect to device");
}
}
I have tried extending the default timeout and implementing other discovery methods.