Read BLE complete advertising packets

How can I read the whole advertising packet when are packets larger than some specific size? 

This is the issue. I want to read this adv packet:

But I only get this on the device:


I read a similar question in the forum and the answer is that: "The second part of the payload is received in the scan response packet, while the device_found() function is invoked only for the primary advertising packet in your case"
But how can I access to that second part of the payload? 

In my code I set up a scan name filter and starting the scanner as 
BT_SCAN_TYPE_SCAN_ACTIVE.

Also, I'm using the advance mode scanning with the callbacks:

BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL,
		scan_connecting_error, scan_connecting);
static void scan_filter_match(struct bt_scan_device_info *device_info,
			      struct bt_scan_filter_match *filter_match,
			      bool connectable)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));

	LOG_INF("Filters matched. Address: %s connectable: %d\n",
		   addr, connectable);

	if (device_info->recv_info->adv_type == BT_GAP_ADV_TYPE_SCAN_RSP)
	{
		LOG_INF("Scan response recivida!");

	}
	LOG_HEXDUMP_INF(device_info->adv_data->data, device_info->adv_data->len, "adv_packet");

	bt_data_parse(device_info->adv_data, adv_cb, addr);

}
Parents
  • Hello,

    Also, I'm using the advance mode scanning with the callbacks:

    And are yhou seeing "Scan response recivida!" in your log?

    You are on the track of something here. The total amount of bytes in the advertising packet you refer to is:

    3 (the 3 bytes indicating the length of the different sections) + 2 (flags data structure), + 9 (name data structure) + 22 (manufacturer specific data structure) = 36 bytes. The maximum length of an advertising packet is 31 bytes, so this has to be split up in the normal advertising packet and a scan response packet. 

    If you are scanning with an BT_SCAN_TYPE_SCAN_ACTIVE, it means that it will request scan response packets from the advertiser. However, these will arrive in a different event, so my guess is that the advertising response packets doesn't pass your scan_filter. 

    I suggest you look into the example: NCS\zephyr\samples\bluetooth\central

    This sample is a bit weird, but it shows how you can start scanning, and get an event for each advertisement scanned. What you need to do is to then parse the advertisement packet (that you now know the format of). Then be aware that the scan response packet does not contain any information about the initial packet, other than that they will have the same bt_addr_le_t * addr.

    So you need to implement the filter that you are currently using, and then look for the address. After you have found the address, change the active filter to one just checking the address of which the advertisement is coming from.

    NB: Remember to change from BT_LE_SCAN_PASSIVE to BT_LE_SCAN_ACTIVE in start_scan(). And in your device_found() callback, remove everything where it connects to the device.

    Best regards,

    Edvin

Reply
  • Hello,

    Also, I'm using the advance mode scanning with the callbacks:

    And are yhou seeing "Scan response recivida!" in your log?

    You are on the track of something here. The total amount of bytes in the advertising packet you refer to is:

    3 (the 3 bytes indicating the length of the different sections) + 2 (flags data structure), + 9 (name data structure) + 22 (manufacturer specific data structure) = 36 bytes. The maximum length of an advertising packet is 31 bytes, so this has to be split up in the normal advertising packet and a scan response packet. 

    If you are scanning with an BT_SCAN_TYPE_SCAN_ACTIVE, it means that it will request scan response packets from the advertiser. However, these will arrive in a different event, so my guess is that the advertising response packets doesn't pass your scan_filter. 

    I suggest you look into the example: NCS\zephyr\samples\bluetooth\central

    This sample is a bit weird, but it shows how you can start scanning, and get an event for each advertisement scanned. What you need to do is to then parse the advertisement packet (that you now know the format of). Then be aware that the scan response packet does not contain any information about the initial packet, other than that they will have the same bt_addr_le_t * addr.

    So you need to implement the filter that you are currently using, and then look for the address. After you have found the address, change the active filter to one just checking the address of which the advertisement is coming from.

    NB: Remember to change from BT_LE_SCAN_PASSIVE to BT_LE_SCAN_ACTIVE in start_scan(). And in your device_found() callback, remove everything where it connects to the device.

    Best regards,

    Edvin

Children
No Data
Related