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

BLE UART connection status

Hello Nordic Pro's,

We are developing a product based on the BLE UART peripheral.  We communicate heavily via NUS.  There are extended processes that continually send status messages over BLE via a central based device.  These processes need to continue if the system disconnects, but the messages need to resume once reconnected.  So, we need to be able to detect the connection status and not send any messages when not connected, then resume the message once connected.  I have read through most if not all of the related cases, but cannot decipher a straightforward answer.  How can I determine from within a peripheral app whether it is connected to a central device? Has anyone successfully done this? 

Thanks again,

Robin@TL

Parents
  • Hi Robin

    I'm having some trouble understanding what exactly you want.  Do you mean like a return value when the peripheral connects/disconnects to a central? Because this can be seen if connecting it to a terminal or something similar. You should also be able to implement an LED to turn on when connected and off when disconnected if that is what you are after.

    If I have misunderstood what you want to achieve, please try to explain it again.

    NOTE: Creating a public case would let the community come with suggestions as well, which increases the chance of someone providing I.E. a working example of what you want. We can also set this case to public mode if you'd like. Just give me the word.

    Best regards,

    Simon

  • Hello again Simon,

    Well I believe I have tracked this down to the fact that the advertising module puts the processor to sleep after a 3 minute timeout, presumably APP_ADV_TIMEOUT_IN_SECONDS   (180).  I can't see through the advertising module documentation well enough to understand how to properly and selectively, based on the state of our application, ignore the BLE_ADV_EVT_IDLE flag.  I have commented out the line that puts the cpu to sleep, and the code keeps running, but I cannot reconnect after the timeout.  

    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        uint32_t err_code;
    
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_FAST:
                err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
                APP_ERROR_CHECK(err_code);
                break;
            case BLE_ADV_EVT_IDLE:
     //           sleep_mode_enter();
                break;
            default:
                break;
        }
    }
    

    Any help is greatly appreciated,

    Robin@TL

  • the advertising module puts the processor to sleep after a 3 minute timeout,

    It's not actually the Advertising Module itself which does it;  it's "your" app - when it receives the Timeout event from the Advertising Module.

    Two options:

    1. Set the advertising to never time out - use BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED;

    2. Just re-start advertising on each timeout
      There'l be an "advertising start" function called somewhere early on - just call that again.

    I have commented out the line that puts the cpu to sleep, and the code keeps running, but I cannot reconnect after the timeout.  

    Indeed - with no advertising, your device cannot be seen and, therefore, you can't connect to it.

Reply
  • the advertising module puts the processor to sleep after a 3 minute timeout,

    It's not actually the Advertising Module itself which does it;  it's "your" app - when it receives the Timeout event from the Advertising Module.

    Two options:

    1. Set the advertising to never time out - use BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED;

    2. Just re-start advertising on each timeout
      There'l be an "advertising start" function called somewhere early on - just call that again.

    I have commented out the line that puts the cpu to sleep, and the code keeps running, but I cannot reconnect after the timeout.  

    Indeed - with no advertising, your device cannot be seen and, therefore, you can't connect to it.

Children
No Data
Related