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

Cannot connect using Nougat 7.x #34

Open
scblason opened this issue Sep 12, 2017 · 9 comments
Open

Cannot connect using Nougat 7.x #34

scblason opened this issue Sep 12, 2017 · 9 comments

Comments

@scblason
Copy link

Hello,
I've been using the library without a problem in devices with Android OS 5.x and 6.x to connect to a custom IoT device. But If I use the library to connect, using a device with 7.x OS, it fails. The IoT device is found during scan, but unable to connect.
If I use a third party app (ie, Nordisk's nRF Connect app) to test the connection, I have no problems.

Do you know of any known issues in Nougat?
Thanks!

@tomazs
Copy link
Contributor

tomazs commented Sep 12, 2017 via email

@scblason
Copy link
Author

Do you have any idea why this is happening? Neatle uses native BLE libraries. If some devices have problems, it should be connecting to any Bluetooth device. I have no problem connecting the phone with Bluetooth speakers and other devices (using the standard Bluetooth from the OS).
Any help that you can point out in the code, would be much appreciate it. We can try to build a pull request to fix it, since it's a really important issue in our project and it would be very expensive to drop Neatle at this point.
Thank you very much!
Santiago.

@tomazs
Copy link
Contributor

tomazs commented Sep 13, 2017

Could you attached the neatle's LogCat outputs or at least the error you get?

We seen an error on OnePlus and it seems it all comes down to this line

if (device.getType() == BluetoothDevice.DEVICE_TYPE_UNKNOWN) {

Can you share on which phone you get the error?

@scblason
Copy link
Author

Thanks for pointing that out. I will take a look.
The phone is a Moto Z Play, with Android 7.1.1.
As soon as I manage to get the logcat output, I would post it here.

PS: With Android 7.0, there where times that I was able to connect...but the connection became very unstable and failed to reconnect. With 7.1.1, we weren't able to connect yet.

@scblason
Copy link
Author

Hi tomazs,
I found more information regarding the issue.
The line of code that you point out is exactly the problem. the device type is "unknown" (like I said, is a custom bluetooth device that we are building, using a Chinese manufacturer).
What we found out is that when we discover the device, it seems that it only has some information (like the MAC address, enough to make a connection) but it doesn´t have the name (device.getName() is null) and of course, the type. But if we search the device using Android's Bluetooth configuration, its get discovered and it shows the name. Once we do that, we go back to our application, we search the device, and this time, the BluetoothDevice has the information (the name) and it seems it has a valid type, because in this case, we can connect to the device.

I don't know is this helpful for you guys, but I just want it to share in case it can help some other developers using the lib.

Thank you!

@tomazs
Copy link
Contributor

tomazs commented Sep 19, 2017

Hey,

Could you please try with the latest version 0.9.4 and let me know if still experience that issue.

@scblason
Copy link
Author

Hi tomazs!
Thanx for the feedback. I tried the new version but the issue continues to exist.
The problem is the following:

  • When we scan for the device, we don´t use the Neatle scan. We use the Nordisc libirary:https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library
  • When we find the device, we use the mac address the get a "Neatle" device (Neatle.getDevice) and start a connection.
  • When reaching the connect() method, we get the issue that the device is "unknown" (like you point out previously), and Neatle, in that case, start a discovery of devices to try to find it.
  • In that discovery, it uses the startLeScan/stopLeScan methods. Here is the problem. Those methods, in OS 7.x, are deprecated (Since API 21, it changed the way for scanning devices, with the BluetoothLeScanner's methods startScan and stopScan). And it seems they don't work (the discover callback method "onLeScan" is never called). When running in a 5.x or 6.x device, that callback is called and the device gets discovered, so it continues the execution of the code by doing the "connectGatt" and everything works fine.

In order to keep using the library, we download the code and we commented the line checking the "unknown" device type in the "connect()" method. We were planning to add the Nordisc library for the scanning process inside of Neatle's code, but is not our priority right now.

Hope this help you with the development!
Regards,
Santiago.

@cavalihno
Copy link

Hi scblason !
Have You resolve Your problem ? Actually I am facing with thhe same problem in my apllication. Exacly my app couldn't connect to bootloader when using Android 7. In nRF sniffer we see that CONNECT_REQ is not sending whatever.

@scblason
Copy link
Author

Hi scblason !
Have You resolve Your problem ? Actually I am facing with thhe same problem in my apllication. Exacly my app couldn't connect to bootloader when using Android 7. In nRF sniffer we see that CONNECT_REQ is not sending whatever.

Hi @cavalihno,
In our case, we just fix the source code of this library by doing what I commented in the previous post:

"In order to keep using the library, we download the code and we commented the line checking the "unknown" device type in the "connect()" method. We were planning to add the Nordisc library for the scanning process inside of Neatle's code, but is not our priority right now."

Hoe that helps. Godd luck!

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

No branches or pull requests

3 participants