Changing Advertisement and connection intervals at run time? NCS

Hi all,

I have an BLE application where i wish to measure the devices power consumption. I am trying to measure the affect of changing the connection interval, MTU size and advertisement interval. I'd like to connect with default parameters, then once connected, write the new connection interval, advertisement interval and MTU size to characteristics. I then want to disconnect the device, for the device to go back into advertising mode, (with the new period set), ask for he newly set connection period on the next request, and have a different MTU size. Is this possible to do at runtime?

Using the NCS it's quite difficult to find where these values are passed in and initialised. for advertisement i see the following:

bt_le_adv_start(..) - Easy to set the initial configuration parameters...
But after that, once connected, i don't see a call to something to stop the advertising such as bt_le_adv_stop()? I see that once a connection is terminated it calls (conn.c) bt_le_adv_resume. Is there any way that i can have the resume function, take new parameters? Is there a data structure visible to me after the initial bt_le_adv_start function, that i can modify? if so, how to i get it? I see there are functions in the adv.c API to change the params, but they require a refence to an advertising object that i do not have a reference to when dealing with legacy mode.
I tried calling bt_le_adv_start, with new params while connected in the callback for setting a characteristic, in the hope that it might update the current params, but this caused a stack overflow.
As for connection, I am currently changing the connection interval in  the prj.conf file. I am not sure how i would go about changing this or calling the required sequence of functions in order to change this at runtime. Is this possible? It doesn't have to change immediately, could also be on reconnection.ble
Thanks

 
Parents
  • Thank you for the response.

    I forgot to mention that my device is a peripheral device. 

    Using Zephyr, bt_le_adv_resume() gets called in the Bluetooth stack as opposed to something that i can call. That's my problem here. Is how do i tap in to the stack to change these values. When the controller disconnects from my peripheral, bt_le_adv_resume() is called. I want to change the values it reads in t o set up the advertising. The only place i have seen user callable code from adv.c in any example is adv.c. If advertising is already occurring maybe i can call stop, and start again, but it seems a shame to when bt_le_adv_resume() gets called when the disconnection occurs. Seems rather hacky to the immediately call Stop and start functions. I assume it's resuming from already having been stopped (i cannot find the code when adv_stop is called when a connection occurs), so i should be able to change the values the adv.c resume function reads before restarting the advertisement, but i don't know how to access them...

  • Hi,

    After the connection is established, you could start the legacy advertiser again with default parameters by setting BT_ADV_PERSIST. The default connection parameters are defined in compile time and the behavior can be changed in host which is available as open source.

    Best regards,
    Dejan

Reply Children
No Data
Related