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

periodic advertising and sleep mode

link text from this link i want to advertise for 10 second then i want to stop advertise for 20 second then again advertise for 10 second. i want this continuously. for that i have defined timer

static void timers1_init(void)
{
    uint32_t err_code;

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);

    // Create timers.
    err_code = app_timer_create(&abc,
                               APP_TIMER_MODE_SINGLE_SHOT,
                                timeout_handler);

//APP_TIMER_MODE_SINGLE_SHOT-The timer will expire only once.
//APP_TIMER_MODE_REPEATED-The timer will restart each time it expires.

    APP_ERROR_CHECK(err_code);
}

static void application_timers_start(void)
{
    uint32_t err_code;

    // Start application timers.
    err_code = app_timer_start(abc, INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}


static void timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
	sd_ble_gap_adv_stop ();
	//power_manage();
    
}
Parents
  • static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp;

        ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.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;
    
        err_code = ble_advdata_set(&advdata, &scanrsp);
        APP_ERROR_CHECK(err_code);
    }
    static void advertising_start(void)
    {
        uint32_t             err_code;
        ble_gap_adv_params_t adv_params;
    
        // Start advertising
        memset(&adv_params, 0, sizeof(adv_params));
    
        adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        adv_params.p_peer_addr = NULL;
        adv_params.fp          = BLE_GAP_ADV_FP_ANY;
        adv_params.interval    = APP_ADV_INTERVAL;
        adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
    
        err_code = sd_ble_gap_adv_start(&adv_params);
        APP_ERROR_CHECK(err_code);
        LEDS_ON(ADVERTISING_LED_PIN);
    }
    

    these are my advertising function

Reply
  • static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp;

        ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.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;
    
        err_code = ble_advdata_set(&advdata, &scanrsp);
        APP_ERROR_CHECK(err_code);
    }
    static void advertising_start(void)
    {
        uint32_t             err_code;
        ble_gap_adv_params_t adv_params;
    
        // Start advertising
        memset(&adv_params, 0, sizeof(adv_params));
    
        adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
        adv_params.p_peer_addr = NULL;
        adv_params.fp          = BLE_GAP_ADV_FP_ANY;
        adv_params.interval    = APP_ADV_INTERVAL;
        adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;
    
        err_code = sd_ble_gap_adv_start(&adv_params);
        APP_ERROR_CHECK(err_code);
        LEDS_ON(ADVERTISING_LED_PIN);
    }
    

    these are my advertising function

Children
No Data
Related