auto reconnect

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I was wandering if it's at all possible to have a peripheral automatically reconnect to a phone after it wakes up, similar to say how classic Bluetooth headphones work, usually reconnecting to the phone with no input required on the users part? 

0 Likes
6 Replies
Anonymous
Not applicable

Hi.

Yes there is. From the mobile side(at least on Android), there is API:

public  BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback);

The second parameter is for autoConnect. So when the peripheral advertises again and if the app is still running, then they will reconnect.

I'm pretty sure you can do this on iOS also.


On the firmware application side, you have to either start advertising undirected or directed upon wake up . If you want to broadcast directed advertisements, you must have saved the information of the previously connected device in NVRAM before.


Remember, the client(the mobile) is the one that initiates the connection. So your peripheral needs to be advertising.


Does this help? Please let us know.

Thank you.


James

Anonymous
Not applicable

It works for iOS also, although I don't know the details.  One thing to watch out for is the iOS app might stop scanning if it goes into some background mode.

0 Likes
Anonymous
Not applicable

I don't develop iOS apps, so I can't say for sure, but you can probably have a background service that is running. An analogy would be Android Service running in the background. That way your mobile can still scan if you wanted to. Although you probably don't want this behavior as it would drain your battery a lot.

James

Anonymous
Not applicable

I know it can be done in iOS because our iOS guys got it to work, but it can be tricky and sometimes iOS behavior is not always what you think it will be.  Bottom line, If you need the app to be connectable from background, be sure to test scenarios where you are browsing internet, listening to music, long periods of inactivity, etc.  to make sure it works the way you want it to.

0 Likes
Anonymous
Not applicable

I have an application that goes to sleep and after it wakes up I'd like it to alert an app that runs in the background as a service on Android. our android guy can listen to a connection being made with the phone, I would like to initiate this connection and if I'm not mistaken I would need to switch to a master role and try and  connect to the device? if this is the case can someone point me in the right direction with regards to switching between roles

0 Likes
Anonymous
Not applicable

Hello Sean,

1.  What you can do is force advertising and the client has to connect to you.

2.  There is no role switch in BLE.

3.  The Android App has to be scanning and scanning constantly.

4.  So when your peripheral is advertising, the background app has to initiate the connection request

Hope this helps.

JT

0 Likes