Adverting is started, stopped and started ... over and over

Hi,

My advertising initial is as follow.

  manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
  manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;

  // Build and set advertising data.
  memset(&advdata, 0, sizeof(advdata));

  advdata.name_type     = BLE_ADVDATA_NO_NAME;
  advdata.flags   = flags;
  advdata.p_manuf_specific_data = &manuf_specific_data;

  // Initialize advertising parameters (used when starting advertising).
  memset(&m_adv_params, 0, sizeof(m_adv_params));

  m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
  m_adv_params.p_peer_addr   = NULL;  // Undirected advertisement.
  m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
  m_adv_params.interval  = NON_CONNECTABLE_ADV_INTERVAL;
  m_adv_params.duration  = 0;     // Never time out.

  err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
  APP_ERROR_CHECK(err_code);

  err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);

But, 10~11 packet are sent and stop.
After 7~8 sec. resent advertisement packet again.... and 10~10 packet send, 7~8 sec stop...

What is the problem?

BR
Paul

  • I have change 

    #define NON_CONNECTABLE_ADV_INTERVAL  MSEC_TO_UNITS(500, UNIT_0_625_MS) to
    #define NON_CONNECTABLE_ADV_INTERVAL  MSEC_TO_UNITS(50, UNIT_0_625_MS)
    500 to 50

    then, no stop...

    But I want  every 1 sec period advertisement for battery saving.
  • Hi,
    My test seems wrong.

    Test config is as follows.
    My custom H/W using 52840 is used for scanner to be receiving adv packets nearby.
    And 52840 DK is for generating adv packet, interval is 1 sec.

    I made scan f/w to receive all advertisement packet.
    And I though it was working well.
    Because, other adv packet nearby are received during my 52840 DK adv packet is not received.

    But, I installed wireshark plugin and did monitor. I found 52480 DK is sending adv packet every 1 sec well.

    So, I think my scanner F/W has something wrong.
    I have to check my scanner F/W first.

    It is possible to not receive specific packet? 

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
      ret_code_t      err_code;
      ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    
      switch (p_ble_evt->header.evt_id)
      {
        case BLE_GAP_EVT_ADV_REPORT:
          {
          int i;
          // pass all beacon
          if (tag_prefix[0] == 0xff && tag_prefix[1] == 0xff && tag_prefix[2] == 0xff &&
              tag_prefix[3] == 0xff && tag_prefix[4] == 0xff && tag_prefix[5] == 0xff)
            {
            app_uart_put ('$');
            app_uart_put (0x12);  // tag_info msg_id
            app_uart_put (17);    // len
    
            app_uart_put (p_gap_evt->params.adv_report.rssi);
            for (i = 0; i < 16; i ++)
              {
              app_uart_put (m_scan.scan_buffer.p_data[i + 9]);
              }
            }
          else
            {
            // compare prefix, if not match, then drop
            if (memcmp (&m_scan.scan_buffer.p_data[9], tag_prefix, 6) != 0)
              {
              // not my tag
              break;
              }
            app_uart_put ('$');
            app_uart_put (0x12);  // tag_info msg_id
            app_uart_put (11);    // len
    
            app_uart_put (p_gap_evt->params.adv_report.rssi);
            for (i = 0; i < 10; i ++)
              {
              app_uart_put (m_scan.scan_buffer.p_data[i + 15]);
              }
            }
    
          nrf_gpio_pin_toggle (OP_LED_1_PIN);
          }
          break;
    
        case BLE_GAP_EVT_CONNECTED:
          break;
    
        case BLE_GAP_EVT_DISCONNECTED:
    
          NRF_LOG_INFO("Disconnected. conn_handle: 0x%x, reason: 0x%x",
                 p_gap_evt->conn_handle,
                 p_gap_evt->params.disconnected.reason);
          break;
    
        case BLE_GAP_EVT_TIMEOUT:
          if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
          {
            NRF_LOG_INFO("Connection Request timed out.");
          }
          break;
    
        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
          // Pairing not supported.
          err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
          APP_ERROR_CHECK(err_code);
          break;
    
        case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
          // Accepting parameters requested by peer.
          err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle,
                              &p_gap_evt->params.conn_param_update_request.conn_params);
          APP_ERROR_CHECK(err_code);
          break;
    
        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
          NRF_LOG_DEBUG("PHY update request.");
          ble_gap_phys_t const phys =
          {
            .rx_phys = BLE_GAP_PHY_AUTO,
            .tx_phys = BLE_GAP_PHY_AUTO,
          };
          err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
          APP_ERROR_CHECK(err_code);
        } break;
    
        case BLE_GATTC_EVT_TIMEOUT:
          // Disconnect on GATT Client timeout event.
          NRF_LOG_DEBUG("GATT Client Timeout.");
          err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                           BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
          APP_ERROR_CHECK(err_code);
          break;
    
        case BLE_GATTS_EVT_TIMEOUT:
          // Disconnect on GATT Server timeout event.
          NRF_LOG_DEBUG("GATT Server Timeout.");
          err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                           BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
          APP_ERROR_CHECK(err_code);
          break;
    
        default:
          break;
      }
    }
    

    Change to scanner issue :(

    BR
    Paul

  • Hi Paul,

    I assume the only relevant event from your event handler here is BLE_GAP_EVT_ADV_REPORT? I cannot say if the way you filter makes sense, but this part of the code should always work as far as  I can see, so any received advertising packet that match your filters will be (partially) printed on UART.

    A few potential problems:

    • Too much/fast printing over UART (if the UART itself is the bottleneck), causing lost data there.
    • Some issue with the scanner itself, do you stop and restart scanning at some point (deliberately or not)? Or do you experience resets or other unexpected behaviours?

    Adding some logging if you have not done so could help in seeing what happens on your application. I may also need to see more of your code in order to comment further.

  • Hi,
    Yes, I deal only BLE_GAP_EVT_ADV_REPORT event.
    I change uart FIFO size to 1024, but same result.

    Specific adv packet is generated very long interval(1 sec). so, bottleneck seems not problem.
    Only one 52840 DK for sending adv packet is used for test.

    If experience reset, I can aware. but no reset is occurred.

    I add m_scan_param variable,

    #define SCAN_INTERVAL               0x0320                              /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW                 0x0320                              /**< Determines scan window in units of 0.625 millisecond. */
    #define SCAN_DURATION           	0x0000                              /**< Duration of the scanning in units of 10 milliseconds. If set to 0x0000, scanning continues until it is explicitly disabled. */
    
    
    static ble_gap_scan_params_t m_scan_param =                 /**< Scan parameters requested for scanning and connection. */
    {
        .active        = 0x00,
        .interval      = SCAN_INTERVAL,
        .window        = SCAN_WINDOW,
        .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
        .timeout       = SCAN_DURATION,
    //    .scan_phys     = BLE_GAP_PHY_CODED,                                 // Choose only one of the following scan_phys
        .scan_phys     = BLE_GAP_PHY_1MBPS,
    //    .scan_phys     = BLE_GAP_PHY_2MBPS,
        .extended      = 1,
    };

    and modify scan_init function as follow.

      init_scan.connect_if_match = false;
      init_scan.conn_cfg_tag   = APP_BLE_CONN_CFG_TAG;
      init_scan.p_scan_param   = &m_scan_param;

    3rd line.
    But, experience reset... after scan_start() is called

  • That is odd... Can you share your whole scanner project?

Related