iOS Question BLR range and reconnect

fbritop

Active Member
Licensed User
Longtime User
If a BLE device goes out of range and the app is in background. Should it reconnect automatically upon coming into range? If thats the case, shall we use connect directly or scan will do the job automatically?

Thanks
FBP
 

fbritop

Active Member
Licensed User
Longtime User
OK I get the idea, It works fine when the APP goes to foreground. But how can a reconnect event be fired when the APP is in background? It does not fire scan event when it comes into range.

Thanks
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
Erel,
After some tests during the following procedure:
1- Open APP, connects to BLE Device
2- Test action on BLE Device (Push button)
3- Press home button on phone, so APP goes to background
4- Walk away from the device until it disconnects (double beep on my BLE Device, indicating a disconnection)
5- Walk close again to phone range
6- App still in background, gains connection to BLE device again, and when BLE device button is pressed, the action executes OK in the phone.

The key (I assume) to gain reconnection while in background, is that the SCAN mode should not be NULL, but with the list of services taht my BLE device publishes.

I hope this helps other BLE users.

Cheers.
FBP
 
Upvote 0

julio lutjens

Member
Licensed User
Longtime User
Hi Reservame,
"reservame" is a spanish word, where are you located ?? by the way I am working with BLE devices (ibeacons), can you share with us some example code ?? would be great, gracias mil.
 
Upvote 0

julio lutjens

Member
Licensed User
Longtime User
hola reservame, vi que estas en santiago de chile, podrĂ­as darme detalles de como llamar a SCAN estando en modo background ??? Can you give me details about how can call SCAN function in background mode ??
 
Last edited:
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
Hi Julio,
I will write in English as it could help anyone else.

When you perform tests with your device, there al some "PUBLIC" UUID's that the device will broadcast. Be sure to list all those UUIDS and take note. You can log them out from the Connected event. (Services as Map)

In our case we are using V.BTTN device from vsnmobil.com. This device broadcasts UUID's 1802, 1803 and 1804. In iOS then we should call the scan as:

B4X:
Dim BLEM as BLEManager
BLEM.initialize("BLEM")
Dim UUID As List
UUID.Initialize
UUID.Add("1802")
UUID.Add("1803")
UUID.Add("1804")
BLE.Scan(UUID)

Once you have aquierd the device, you should connect to it. Depending on the type of devices, some requieres an activation key to be written as a characteristic in order to establish (booking) the BLE service. My BLE device waits for 30 seconds for the phone to write the characteristic and a key.

At this point, once connection (and verification key) has been done, Bluetooth Central takes care of the rest. If the device goes out of range, and the APP is in the background, it should reconnect automatically (watch for the BLE StateChanged and BLEConnected event to log when the device comes into range.

Forget about this if your phone is restarted, as the application cannot start as a service as we can acomplish in B4A. Phone restart, means the user MUST start the APP before iOS can take care of finding a "friend" BLE Device.

Whats projects are you developing? just iOS o Android too?

Cheers
FBP
 
Upvote 0
Top