Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isConnected returns true on Android after disconnect #16

Open
sjrcgtek opened this issue Jul 18, 2016 · 7 comments
Open

isConnected returns true on Android after disconnect #16

sjrcgtek opened this issue Jul 18, 2016 · 7 comments

Comments

@sjrcgtek
Copy link

EASYBLE isConnected() method stills returns true after device is disconnected on android. Works as expected on iOS. I call isConnected() immediately after receiving a connectErrorCallback with "EASYBLE_ERROR_DISCONNECTED" (which i forced by pulling the batteries on my BLE device)

Not sure what other info might be helpful. If there is something else that, please let me know.

@sjrcgtek
Copy link
Author

I misspoke a bit above. The connectErrorCallback gets a value of 8 on Android. I get EASYBLE_ERROR_DISCONNECTED on IOS

@ghost
Copy link

ghost commented Jul 26, 2016

Some more details:

"if I pull the batteries in my BLE device, I get EASYBLE_ERROR_DISCONNECTED in my Connection Error Callback as suspected, but if I call isConnected() immediately after that, it returns true on Android. iOS correctly returns false."

@ghost ghost self-assigned this Jul 26, 2016
@ghost ghost added the in-progress label Jul 26, 2016
@ghost
Copy link

ghost commented Jul 29, 2016

Saving this note from Gitter here as a memo to be super clear: "The disconnect on android does NOT return EASYBLE_ERROR_DISCONNECTED. Instead I get an error code of 8. Looks like EASYBLE won't interpret that 8 as a simple disconnect and thus not set __isConnected to false."

@ghost
Copy link

ghost commented Aug 12, 2016

@sjrcgtek Hi,

I have made various tests and cannot reproduce the situation of error code 8.

I consistently get connectInfo.state == 0 on disconnect. When removing the battery from the BLE device, it takes some time before disconnect occurs however. When resetting the BLE device (tested with TI SensorTag CC2650) the disconnect happens much quicker. Also tested to turn off BLE on the phone, which results is a quick disconnect event.

On which BLE device/devices have you seen this? Do you get code 8 in the connectInfo.state variable in the success callback, or in the errorCode in the error callback?

Made an update to set __isConnected = false also in the error handler.

See this commit: https://github.com/mikaelkindborg/evothings-libraries/commit/b0575975629236c9a9d2526438782e469745915a

The commit diff is not very readable, here is the source of the updated function: https://github.com/mikaelkindborg/evothings-libraries/blob/b0575975629236c9a9d2526438782e469745915a/libs/evothings/easyble/easyble.js#L1243

If you wish to test, here is the easyble.dist.js file: https://github.com/mikaelkindborg/evothings-libraries/blob/master/libs/evothings/easyble/easyble.dist.js

@sjrcgtek
Copy link
Author

The device is a contact sensor built with BlueGiga's BLE112 i believe. I
am connecting from an older Galaxy phone (SAMSUNG-SGH-I537) running android
5.0.1. I can try with a more recent android device and see if there is any
difference. I will also retest with this one using the new code.

I was getting the code 8 in the error callback.

On Fri, Aug 12, 2016 at 8:47 AM, Mikael Kindborg [email protected]
wrote:

@sjrcgtek https://github.com/sjrcgtek Hi,

I have made various tests and cannot reproduce the situation of error code
8.

I consistently get connectInfo.state == 0 on disconnect. When removing the
battery from the BLE device, it takes some time before disconnect occurs
however. When resetting the BLE device (tested with TI SensorTag CC2650)
the disconnect happens much quicker. Also tested to turn off BLE on the
phone, which results is a quick disconnect event.

On which BLE device/devices have you seen this? Do you get code 8 in the
connectInfo.state variable in the success callback, or in the errorCode in
the error callback?

Made an update to set __isConnected = false also in the error handler.

See this commit: mikaelkindborg@b057597
https://github.com/mikaelkindborg/evothings-libraries/commit/b0575975629236c9a9d2526438782e469745915a

The commit diff is not very readable, here is the source of the updated
function: https://github.com/mikaelkindborg/evothings-libraries/blob/
b057597/libs/evothings/
easyble/easyble.js#L1243

If you wish to test, here is the easyble.dist.js file: https://github.com/
mikaelkindborg/evothings-libraries/blob/master/libs/
evothings/easyble/easyble.dist.js


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACpRckkzQYtW4_dLK1ciaul-QFChDBa5ks5qfHl8gaJpZM4JO_Li
.

@sjrcgtek
Copy link
Author

Mikael,

I just tested again with your new code. I am still getting that error code
8 (which I expected). I hit the following code in EASYBLE:

// Error callback.
function(errorCode)
{
// DEBUG LOG
console.log('BLE connect error: ' + errorCode);
// Set isConnected to false on error.
device.__isConnected = false;
internal.connectedDevices[device.address] = null;
fail(errorCode);
});
};

The new device.__isConnected = false, solves my problem since the app now
recognizes that we have disconnected. Still not sure why we get that 8,
but at least i can recognize the disconnect.

Thanks.
Steve

On Fri, Aug 12, 2016 at 8:47 AM, Mikael Kindborg [email protected]
wrote:

@sjrcgtek https://github.com/sjrcgtek Hi,

I have made various tests and cannot reproduce the situation of error code
8.

I consistently get connectInfo.state == 0 on disconnect. When removing the
battery from the BLE device, it takes some time before disconnect occurs
however. When resetting the BLE device (tested with TI SensorTag CC2650)
the disconnect happens much quicker. Also tested to turn off BLE on the
phone, which results is a quick disconnect event.

On which BLE device/devices have you seen this? Do you get code 8 in the
connectInfo.state variable in the success callback, or in the errorCode in
the error callback?

Made an update to set __isConnected = false also in the error handler.

See this commit: mikaelkindborg@b057597
https://github.com/mikaelkindborg/evothings-libraries/commit/b0575975629236c9a9d2526438782e469745915a

The commit diff is not very readable, here is the source of the updated
function: https://github.com/mikaelkindborg/evothings-libraries/blob/
b057597/libs/evothings/
easyble/easyble.js#L1243

If you wish to test, here is the easyble.dist.js file: https://github.com/
mikaelkindborg/evothings-libraries/blob/master/libs/
evothings/easyble/easyble.dist.js


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACpRckkzQYtW4_dLK1ciaul-QFChDBa5ks5qfHl8gaJpZM4JO_Li
.

@ghost
Copy link

ghost commented Aug 15, 2016

@sjrcgtek Thanks a lot for testing! Merged the update into the main Evothings repository now.

The callbacks for connect/disconnect should be designed in a clearer way, will look into this. Let me know if you have any ideas. Perhaps the error callback should cause a "disconnect event" to be sent. Currently the connect success callback has this function. It can be called on error with connectInfo.state disconnect. There could be better ways.

Do you have any idea when the error code 8 stands for? I have been searching the Android docs for BLE but not found any error code 8 yet.

Best, Mikael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant