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

scan_stop if no advertisers found

Greetings, Using the "central multilink" example project, how do I stop scanning if no advertisers are found? I see a case BLE_GAP_EVT_TIMEOUT in function on_ble_evt() but it isn't compiling. I'd like to scan on wakeup for ≈10 seconds and go back to sleep if no advertisers found. Thanks for the help, boz

Parents
  • There is a timeout in advertising parameters ble_gap_adv_params_t ->timeout; /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for High duty cycle directed advertising. */

    Similarly for scan parameters ble_gap_scan_params_t->timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */

    If you have not set any timeouts to it, then scanner and/or advertiser never times out and you will not get any BLE_GAP_EVT_TIMEOUT

Reply
  • There is a timeout in advertising parameters ble_gap_adv_params_t ->timeout; /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for High duty cycle directed advertising. */

    Similarly for scan parameters ble_gap_scan_params_t->timeout; /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */

    If you have not set any timeouts to it, then scanner and/or advertiser never times out and you will not get any BLE_GAP_EVT_TIMEOUT

Children
  • Thanks for the detailed answer that led here and is working now: /**

    • @brief Scan parameters requested for scanning and connection. */ static const ble_gap_scan_params_t m_scan_param = { 0, // Active scanning not set. 0, // Selective scanning not set. NULL, // White-list not set. (uint16_t)SCAN_INTERVAL, // Scan interval. (uint16_t)SCAN_WINDOW, // Scan window. 10 // Scan timeout in seconds, '0' = indefinite };
Related