This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Auto-connection on the nRF Blinky app

Hello,

I downloaded the nRF Blinky app (for Android) here : github.com/.../Android-nRF-Blinky

I'm looking to modfy the code to have an auto connection. For this, I would like to go directly on the second page, and do a filtering by name. If the phone isn't conneted to my board (called ABCDEF for example), the app search BLE devices, and if it found a device called ABCDEF, the app auto-connect to it, and it is possible to control the board with the app.

How can I do it, please ? I've been searching for 3 weeks, and I'm still failing to do this.

Thanks a lot for helping me !

  • Hi Raven,

    Have you had a look at where we process the scan result ? First you need to scan , then you check in the scan result if the device name of the result(s) is "ABCDEF" If you have in the code, we catch the scan result in onBatchScanResults() in MainActivity.java.

    From the result, you can call mBluetoothDevice.getName(); or result.getScanRecord().getDeviceName(); if scan record is not null. This is done in ExtendedBluetoothDevice.java

    Then if the device name matches, you can send the device address and start controlBlinkIntent as in onItemClick() in MainAcitivity.java

  • Hello, It works perfectly, thanks a lot !! Now, I have an other question : is it possible to concatenate MainActivity.java and ControlBlinkyActivity, in order to have only one activity ?

    And also, when I power off my board, th disconnection is notified on the app more than 20 seconds later : how can I reduce this time ?

  • Hi,

    Yes it's possible to integrate into one file. I would suggest you to have a look at the basic example from Android here or you can have a look at nRF UART example here.

    To set the connection supervision timeout , you need to change it in the application firmware . Please look for CONN_SUP_TIMEOUT in the firmware. Note that there could be the chance that the phone doesn't accept it.

    For further question, please create a new case.

  • Thank you for the links. In the firmware, I have 4 seconds for CONN_SUP_TIMEOUT. But the Android app detect the deconnection after 20 seconds : is it normal ? Ok no problem, I will create an other case if needed, thanks a lot again !

Related