This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Possibility to change advertising timeout

Hello,

I want to change the advertising timout during runtime. We have two use cases for our device:

  1. Batterie mode --> advertising timeout = 2min

  2. Power supply --> no advertising timeout (advertising timeout = 0)

Is it possible to change this sofdevice parameter during runtime? If yes, how to do that? ;-)

I am using S120 on a nRF51822.

Regards, BTprogrammer

  • Thank you very much! I was just searching for the wrong key words. So I didn`t find that thread. I will try it that way. BR

  • Hey, sorry, but I didn`t get it running with the suggested solution. This is my advertising_init() function:

    static uint32_t advertising_init(void){
    uint32_t      err_code;
    ble_advdata_t advdata;
    	ble_advdata_t scanrsp;
    	
    	ble_uuid_t adv_uuids[] = {{BLE_UUID_DEVICE_SERVICE, GRL_DEV_SERVICE_UUID_TYPE}};
    
    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type             = BLE_ADVDATA_FULL_NAME;
    	advdata.include_appearance      = true;
    advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    	
    	memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = adv_uuids;
    	//scanrsp.
    	
    	ble_adv_modes_config_t options = {0};
    options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
    	return err_code;}
    

    It is pretty much the same than in the ble_app_uart example. But if I set APP_ADV_TIMEOUT_IN_SECONDS to zero, the device isn`t accessible via BLE anymore...

    To switch between the two modes, I believe I will need the sd_ble_gap_adv_start() function. But in my current implementation, this is handled by the ble_advertising_start() function in ble_advertising.c So where do I get the needed adv_params during runtime? BR

  • Hmm that sounds strange. You are sure that your advertisement packet does not go over the size of 31 bytes (for example name too long), see here. adv_uuids should be declared outside the function or else the data might be destroyed when exiting the function (this may not be an issue, but to be on the safe side).

    ble_advertising_start(..) will call sd_ble_gap_adv_start(..) and loop through several modes (FAST, SLOW etc) when the advertisement times out.

  • Hello Ole, sorry for not closing that question. I changed the advertising parameters in function ble_advertising_start() in ble_advertising.c according to my needs. This works for me so far. So it is possible to set adv_params.timeout = 0;there and it works with no timeout. But it was not possible for me, to set adv_params.timeout = 0; in the advertising_init() function. Anyway for now it works as expected. Thanks for your reply. Regards, BTprogrammer

Related