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

Advertising restart after a disconnect event

Hi!

Using SDK 14, I am advertising and see my device on the phone with nRFConnect. The indication LED flashes (indication) properly and in fixed intervals. When I connect with my phone the LED lights up without flashing as expected. After I disconnect the device wont advertise anymore and the LED doesn't flash anymore. I can also not find the device with my phone.

I tried to put a advertising_start(false); in the disconnected event:

case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO("Disconnected, reason %d\r\n",
                          p_ble_evt->evt.gap_evt.params.disconnected.reason);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            advertising_start(false);
            break; // BLE_GAP_EVT_DISCONNECTED

This makes the LED flash again as if it was advertising but I can't find the device with my phone. Very sad. The boolean false just states that no bonds should be erased (I took this one from the examples)

So two questions:

  • How do I make this work (that I can connect and advertise over and over again)?
  • Sometimes after just some seconds the LED will light up as if it's in connected state. I cannot figure why ...

I would be very glad if someone could give me some advice ...

Best Noah

  • Hi Noah!
    Are you using the nRF52 DK? What example are you using? And did you make any changes to the code, besides the advertising_start(false)?

  • Hi Joakim

    I am using a custom board. But that does not have any impact. As the LED just works fine :) (I adjusted the BSP variables) I used the BAS example and ported it from SDK 12 to SDK 14 (as I already started the project in SDK 12 and then decided to switch to 14 (which was a huge mistake due to various reasons (Mesh being one))). Of course I had a look for different changes and I checked the few I had (I did a git bisect) but I am afraid it's a problem from after the SDK 14 port. So I am not sure if I missed something or if it's a bug in the SDK 14. The question is: do I have to restart advertising on my own? Because I was kind of 100% sure I didn't with SDK 12. If so, why doesn't an advertising_start() work?

  • I don't know what you mean by the BAS example, but did you take a look at the migration notes when porting your project? When porting from SDK12 to SDK14, it might be a good idea to look at the SDK13 migration document first, before migrating to SDK14.
    You can take a look at how the advertising is handled for the BLE_GAP_EVT_DISCONNECTED by taking a look at ble_advertising_on_ble_evt() in the ble_advertising.c file.

  • The BAS example is officially called like that, I didn't make the name ;) Ofc I followed the migration documents of SDK 14 but nut the ones of SDK 13. WIll try, thanks :) ble_advertising_on_ble_evt() is never called ... it's just defined in the SDK ...

Related