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

Automatic connection to nrf51 when in range.

Hi NordicSemiconductor's community,

I have a basic question about connection to a BLE peripheral. I use the SDK_10.0.0 and s110_v8.0.0.

I want to know how to implement a fonctionnality in my BLE product; I want the Android smartphone connect automatically to the device when he is in range.

Now i can connect to it, by doing a scan on my application and with my peripheral advertise. But i don't have any idea about how connect to my device automatically ??

Thanks for your help, Best regards.

Parents
  • Sure, but it's not that simple. It still has to be your app, but instead of an Activity, you have to write a service that will operate in the background. From a service you may do normal BLE operations. If you want your app (service) to be started when phone boots up, you also had to write a broadcast receiver that will listen for boot completed event. Please, read about services and broadcast receivers on Android website. In nrf toolbox we also connects in a service, for example in Proximity profile.

Reply
  • Sure, but it's not that simple. It still has to be your app, but instead of an Activity, you have to write a service that will operate in the background. From a service you may do normal BLE operations. If you want your app (service) to be started when phone boots up, you also had to write a broadcast receiver that will listen for boot completed event. Please, read about services and broadcast receivers on Android website. In nrf toolbox we also connects in a service, for example in Proximity profile.

Children
  • Thanks a lot, it's clear now,

    But it is not energy efficient from the smartphone point of view, to continually scanning in background ? I will test this design, and see if the smartphone battery is Ok^^.

  • If you will be at the house, you will be connected. It depends on your connection settings how impact would it have on your phone and device's battery. Some recommend to connect only when a packet needs to be sent (for example a user switches on a lamp), send command, and disconnect. It will not be that quick as if you were connected, but phone will save some battery. Also, when you are not at home and you'd like the phone to keep scanning and connecting when find, you should use connectGatt method with autoConnect param set to true. This way the device address will be passed to low energy controller in the phone and it will do most job notifying cpu only when the device gets connected. It's battery efficient.

Related