iOS Question BLR range and reconnect

Discussion in 'iOS Questions' started by fbritop, Aug 8, 2015.

  1. fbritop

    fbritop Active Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    If the Disconnected event was fired then you need to call Scan again and then when the device is found call connect with the device id.
     
  3. fbritop

    fbritop Active Member Licensed 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It will not work when the app is in the background.
     
  5. fbritop

    fbritop Active Member Licensed 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
     
    Erel likes this.
  6. julio lutjens

    julio lutjens Member Licensed 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.
     
    fbritop likes this.
  7. julio lutjens

    julio lutjens Member Licensed 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: Sep 1, 2015
  8. fbritop

    fbritop Active Member Licensed 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:

    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice