[Android] Error: Device ? is already connected
See original GitHub issueI’m using following, very simple, piece of boilerplate code.
...
manager.startDeviceScan(null, null, (error, device) => {
if (error) {
console.warn(error)
return
}
if (device.name === this.DEVICE_NAME) {
this.connectTo(device, false)
}
})
...
connectTo = (device, isLeft) => {
device.connect()
.then((device) => {
console.log("[Info][connectTo][success]", device)
})
.catch((error) => {
console.log('[Error][connectTo][error]: ', error)
})
}
...
The code runs as expected on iOS devices, but fails on Android devices.
Every-time I try to connect a device, I’m getting BleErrorCode.DeviceAlreadyConnected
error, viz.
[Error][connectTo]: Error: Device ? is already connected
at new BleError (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:114897:110)
at parseBleError (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:114917:18)
at BleManager._callPromise$ (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:115168:51)
at tryCatch (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17030:19)
at Generator.invoke [as _invoke] (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17203:24)
at Generator.prototype.(anonymous function) [as throw] (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17073:23)
at tryCatch (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17030:19)
at invoke (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17106:22)
at blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:17118:15
at tryCallOne (blob:http://192.168.86.39:19001/fed3bf61-e367-4015-871f-d29b37905b0e:16359:14)
[Error][connectTo]: Error: Operation was cancelled
at new BleError (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:114897:110)
at parseBleError (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:114917:18)
at BleManager._callPromise$ (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:115168:51)
at tryCatch (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17030:19)
at Generator.invoke [as _invoke] (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17203:24)
at Generator.prototype.(anonymous function) [as throw] (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17073:23)
at tryCatch (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17030:19)
at invoke (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17106:22)
at blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:17118:15
at tryCallOne (blob:http://192.168.86.39:19001/d1e699a5-985a-40dc-a7a0-7b2a4f49e47a:16359:14)
This sequence basically repeats until somehow devices reconnects on it’s own. I don’t handle reconnection from my side.
On the other hand, when I try to call
device.isConncted()
I’m getting false
.
As well as when I try to force device disconnect before I try connecting it back again via
device.cancelConnection()
I’m getting BleErrorCode.DeviceNotConnected
Is this a bug? Any suggestions how to bypass this for now?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11
Top Results From Across the Web
[Android] Error: Device ? is already connected #271 - GitHub
It seems there is no easy way to tell if the device is connected though. It would be ideal to write code like...
Read more >setupNotification returns "Error already connected" whereas ...
I establish a BLE connection with a specified device, later while connected I read and write characteristic with no problem, but when i...
Read more >Company portal enrolment issues: Your device is already ...
The error occuring for my users is "Your device is already connected to your ... From your android mobile Go to Settings >...
Read more >Not able to Register My Account - Android Enterprise ...
Whenever I try to register my account in google app device policy application it always shows the message that network error try again...
Read more >Why did I get a maximum devices error on my mobile app
This message indicates you have exceeded the maximum number of active devices. Please log out of a device to solve the issue.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You may check the connection before connect the device.
I don’t really understand why this this issue is closed… Any proper way to fix that error ?