This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2650STK: Android Application - can not connect with SensorTag due to BluetoothLeService null

Part Number: CC2650STK
Other Parts Discussed in Thread: CC2650, BLE-STACK, CC2540EMK-USB

Hi,

I am developing my own app for the CC2650 STK in Android Studio. To do this I've downloaded the Android Source Code from git.

However this is a version from 2015. Is there a newer one anywhere?

I have adapted the code slightly and the scanning for devices works fine. If I want to connect to the device, I get an error, saying that my BluetoothLeService is a null object, when I try to call the connect method. I don't really understand as I have the same code that is used in the Android source code from TI.

Did anyone have a similar problem before?

This is my onConnect() method, which is called from my MainActivity

void onConnect() {
if (mNumDevs > 0) {

int connState = btManager.getConnectionState(mBluetoothDevice,
BluetoothGatt.GATT);

switch (connState) {
case BluetoothGatt.STATE_CONNECTED:
mBluetoothLeService.disconnect(null);
break;
case BluetoothGatt.STATE_DISCONNECTED:
boolean ok = mBluetoothLeService.connect(mBluetoothDevice.getAddress());
if (!ok) {
setError("Connect failed");
}
break;
default:
setError("Device busy (connecting/disconnecting)");
break;
}
}
}

Thank you for you help!
Best, Claudia
  • Hi Claudia,

    The code you pulled from git is from git.ti.com/sensortag-android right?

    Then yes, it is the latest.

    In regards to your android question, I can't help much, our expertise lies with the TI BLE-Stack not the android one. I recommend posting your question on stack overflow or maybe wait a bit more to see if someone can help out.

    Regards,
    Rebel
  • Hi Claudia,

    I had some big problems with Android and BLE. There is one way to do it in Android <6 and another completely different way in Android => 6. I started my app in Android 5.5 and had to make some big changes to get it to work in 6. The problem is related to the way Android handles Bluetooth permissions. Since I have been using my own custom app for close to a year now I cant add more than that.

    One thing you can try is to find an Android device that is running 5.5 or whatever and see if it works there. At least then you will know if this is the issue you are seeing.

    They did update the sensortag app within the last year, download it from the play store and make sure it has the same user interface as the one you are using. If it doesn't then you did not download the latest repository.

    I wish I could add more.

    Regards
    JP
  • Hi,

    thanks for both of your replies!

    I am using Android 6 and 7 with my app and already encountered many problems when trying to scan for devices, but I fixed that already.

    Do you remember if there were problems when connecting too? I thought I had those problems fixed, when I got the scanning for devices running.

    Regards,

    Claudia

  • Hi Claudia,

    I did not have connection issues that I didn't figure out fairly quickly.  Most of the time it was typos in my code that caused the issues.  One thing I found to be extremely helpful was BTool, coupled with the CC2540EMK USB Dongle.  This combination lets you see all of the goings on with respect to BLE.  It allows you to scan and connect while watching the actual return values from each command.  It can also be set up as a packet sniffer, although I have never done that.

    The P/N is CC2540EMK-USB   Digikey has them for ~$50 and the Btool app comes as part of the BLE Stack.  It is probably installed on your machine already.

    Hope it helps,

    JP