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

Simple Observing of nearby devices

Hi, I have an nRF51822 with s130 doing normal advertising and a Nordic UART service. Is there an example somewhere of doing some simple observation with it at the same time?

Ideally I'd just have start_listening and end_listeningfunctions, and would then get the event handler called whenever an advertising packet was received (which would contain signal strength info?). No connection needed at all.

Would the softdevice need configuring in central mode for this? I'm short on RAM so the less the Soft Device takes the better.

thanks!

Parents
  • Ok, in case anyone else is interested in this - with Einar's help:

    #define SCAN_INTERVAL              0x00A0                             /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW                0x0050                             /**< Determines scan window in units of 0.625 millisecond. */
    
    
    static void on_ble_evt(ble_evt_t * p_ble_evt) {
    switch (p_ble_evt->header.evt_id) {
      // ...
      case BLE_GAP_EVT_ADV_REPORT: {
        // Advertising data received
        const ble_gap_evt_adv_report_t *p_adv = &p_ble_evt->evt.gap_evt.params.adv_report;
        printf("RSSI: %d\n", p_adv->rssi);
        // also data, address, etc in p_adv
        break;
      }
    }
    
    ble_gap_scan_params_t     m_scan_param;
    // non-selective scan
    m_scan_param.active       = 0;            // Active scanning set.
    m_scan_param.selective    = 0;            // Selective scanning not set.
    m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
    m_scan_param.window       = SCAN_WINDOW;  // Scan window.
    m_scan_param.p_whitelist  = NULL;         // No whitelist provided.
    m_scan_param.timeout      = 0x0000;       // No timeout.
    
    err_code = sd_ble_gap_scan_start(&m_scan_param);
    
    // and stop with
    err_code = sd_ble_gap_scan_stop();
    

    This seems to work, however the advertising window of 50ms / 100ms means that you do tend to miss things. Is it ok to put the window up to 100ms as well? It seems to work.

  • Thanks for posting your solution. That will be helpful for others with similar questions.

Reply Children
No Data
Related