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

Readind RSSI in beacon_evt_handler shows wrong value

Hello i read RSSI in beacon_evt_handler() hrs_scanner project:

printf("RSSI: %d\n\n\n",p_evt->rcv_adv_packet.adv_data.rssi);

but he show me a wrong value of RSSI: 4539

how i can fix this??

Best Regards

Nelson

  • What SDK version is this? Could you post some code?

    You are looking for the rssi in the adv_data field? It should be in the rssi field:

    /**@brief Event structure for @ref BLE_GAP_EVT_ADV_REPORT. */
    typedef struct
    {
      ble_gap_addr_t peer_addr;                     /**< Bluetooth address of the peer device. If the peer_addr resolved: @ref ble_gap_addr_t::addr_id_peer is set to 1
                                                         and the address is the device's identity address. */
      ble_gap_addr_t direct_addr;                   /**< Set when the scanner is unable to resolve the private resolvable address of the initiator
                                                         field of a directed advertisement packet and the scanner has been enabled to report this in @ref ble_gap_scan_params_t::adv_dir_report. */
      int8_t         rssi;                          /**< Received Signal Strength Indication in dBm. */
      uint8_t        scan_rsp : 1;                  /**< If 1, the report corresponds to a scan response and the type field may be ignored. */
      uint8_t        type     : 2;                  /**< See @ref BLE_GAP_ADV_TYPES. Only valid if the scan_rsp field is 0. */
      uint8_t        dlen     : 5;                  /**< Advertising or scan response data length. */
      uint8_t        data[BLE_GAP_ADV_MAX_SIZE];    /**< Advertising or scan response data. */
    } ble_gap_evt_adv_report_t;
    
  • I use hrs_scanner example with s130 softdevice, i read a wrong rssi value in:

    static void beacon_evt_handler(ble_scan_beacon_evt_t * p_evt) { uint32_t err_code;

    if (p_evt->rcv_adv_packet.adv_data.manuf_id==0x59){
    		printf("********************************************************");
    		printf("App company id: %x\r\n",p_evt->rcv_adv_packet.adv_data.manuf_id);
    		unsigned short major=p_evt->rcv_adv_packet.adv_data.major;
    		major=(major>>8) | (major<<8);
    		unsigned short minor=p_evt->rcv_adv_packet.adv_data.minor;
    		minor=(minor>>8) | (minor<<8);
    		printf("Major: %d\r\n",major);
    		printf("Minor: %d\r\n",minor);
    	        int8_t rssi=p_evt->rcv_adv_packet.adv_data.rssi;
    		printf("RSSI: %d\n",rssi);//WRONG VALUE
    		for (int i=0;i<sizeof(p_evt->rcv_adv_packet.adv_data.uuid.uuid128);i++){
    				printf("%02X",p_evt->rcv_adv_packet.adv_data.uuid.uuid128[i]);
    		}
    		printf("\n\n");
    
    	
    }
    
    
    if((p_evt->rcv_adv_packet.adv_data.major    == SEARCHED_MAJOR)
     &&(p_evt->rcv_adv_packet.adv_data.minor    == SEARCHED_MINOR)
     &&(p_evt->rcv_adv_packet.adv_data.manuf_id == APP_COMPANY_IDENTIFIER))
    {
        err_code = bsp_indication_set(BSP_INDICATE_ALERT_3);
        APP_ERROR_CHECK(err_code);
    }else{
    		///printf("beacon no detectado\r\n");
    	}
    

    }

    Serial monitor output:

    App company id: 59 Major: 3584 Minor: 35409 RSSI: -69 ------------->WRONG VALUE DONT CHANGE 0112233445566778899AABBCCDDEEFF0

  • Hi,

    Yes, this value is indeed constant. This is the RSSI value of the beacon measured at 1 meter distance, which can be used for estimating the distance from the beacon. It's a constant value set together with the major, minor and the company id.

    If you need the measured RSSI from the beacon, you can get this information in e.g. the function app_beacon_scanner_on_ble_evt()in scanner_beacon.c. Change it to something like this:

    void app_beacon_scanner_on_ble_evt(ble_evt_t * p_ble_evt)
    {
        if (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT)
        {
            ble_scan_beacon_evt_t evt;
            
            
            printf("RSSI: %d\n",p_ble_evt->evt.gap_evt.params.adv_report.rssi);
            
            uint32_t err_code = decode_advertising(p_ble_evt->evt.gap_evt.params.adv_report.data, p_ble_evt->evt.gap_evt.params.adv_report.dlen, &evt.rcv_adv_packet);
            if (err_code == NRF_SUCCESS)
            {
                if (m_beacon_scanner.evt_handler != NULL)
                {
                        evt.evt_type = BLE_SCAN_BEACON_ADVERTISER_FOUND;
                        m_beacon_scanner.evt_handler(&evt);
                }
            }
        }
    }
    

    You can also add this to the on_ble_evt() in main.c, add the case BLE_GAP_EVT_ADV_REPORT to the switch-statement, and get the rssi when you get the BLE_GAP_EVT_ADV_REPORT.

Related