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

NCS bt_le_scan_start API is limited to report phy and adv detail

Hi Team,

I'm working on scanner and NCS/Zephyr bt_le_scan_start callback API

typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, int8_t rssi,
uint8_t adv_type, struct net_buf_simple *buf);

The adv_type is too limited to tell

PHY (1M or CODED)

Coded ADV or Coded Scan Response.

1M AE or Legacy.

Is there any way to improve it ?

Thanks,

Sam

  • Hi,

    You can register a callback with bt_le_scan_cb_register(), and get all that information.

    If you are connecting to the devices, I recommend checking out the NCS Scanning module. We use it in e.g. the central_bas sample. Here you can find all that information in the bt_le_scan_recv_info struct, that is included in the bt_scan_device_info struct

    /** LE advertisement packet information */
    struct bt_le_scan_recv_info {
    	/**
    	 * @brief Advertiser LE address and type.
    	 *
    	 * If advertiser is anonymous then this address will be
    	 * @ref BT_ADDR_LE_ANY.
    	 */
    	const bt_addr_le_t *addr;
    
    	/** Advertising Set Identifier. */
    	uint8_t sid;
    
    	/** Strength of advertiser signal. */
    	int8_t rssi;
    
    	/** Transmit power of the advertiser. */
    	int8_t tx_power;
    
    	/** Advertising packet type. */
    	uint8_t adv_type;
    
    	/** Advertising packet properties. */
    	uint16_t adv_props;
    
    	/**
    	 * @brief Periodic advertising interval.
    	 *
    	 * If 0 there is no periodic advertising.
    	 */
    	uint16_t interval;
    
    	/** Primary advertising channel PHY. */
    	uint8_t primary_phy;
    
    	/** Secondary advertising channel PHY. */
    	uint8_t secondary_phy;
    };

    If you instead want to use the bt_le_scan_cb_register() directly, then you can find an example on how that is used in e.g. the EnOcean subsys(used in the Bluetooth Mesh). See this link.

    Snippet:

    	static struct bt_le_scan_cb scan_cb = { .recv = adv_recv };
    
    	bt_le_scan_cb_register(&scan_cb);

    static void adv_recv(const struct bt_le_scan_recv_info *info,
    		     struct net_buf_simple *buf)
    {
    ..
    ..
    }

    In adv_recv() you then have the bt_le_scan_recv_info.

    See the code example here on how to decode the information in bt_le_scan_recv_info.

  • Hi Sigurd,

    I works for me. Thanks you.

    However I cannot get Scan Response from 1M LE AE and Coded devices.

    Active scan is used. legacy scan response is fine.

    I verify Scan Response with our original scanner to make sue the Scan Response is carried with 1M AE and Coded devices.

    Anything missed ?

    ps. I can get Scannable ADV with 0 len payload  but I cannot get Scan Response.

    BR,

    Sam

Related