---
title: "bt_adv_packet_read()"
canonical: "https://docs.xirgoglobal.com/space/SD/27141768/bt_adv_packet_read()"
format: markdown
---
### <span style="color: #36b37e">Description</span>

Reads out data from Bluetooth scan module into user array.

### <span style="color: #36b37e">Syntax</span>

`bt_adv_packet_read(data_array[], scan_buffer_to_readout);`

### <span style="color: #36b37e">Parameters</span>

|  |  |
| --- | --- |
| **Variable** | **Input** |
| `data_array[]` | Data array into which scanned data will be stored. It is recommended to have this array at least 250 bytes in size. |
| `scan_buffer_to_readout` | <span style="color: #4c9aff">BT_FILTER_MATCH </span>- Readout from filter match buffer.<br><span style="color: #4c9aff">BT_FILTER_MISMATCH </span>- Readout from filter mismatch buffer. |

### <span style="color: #36b37e">Returns</span>

|  |  |
| --- | --- |
| **Return value** | **Return explanation** |
| **from 1 to 255 bytes** | Read data size. |

### <span style="color: #36b37e">Packet structure</span>

The stored packet will possess its own structure. The following is an example of received data:

FF 48 80 33 E3 A8 00 D2 02 01 06 05 16 6E 2A 72 09 0E 09 50 20 54 20 45 4E 20 38 30 43 42 37 36

This data can be broken down as follows:

<span style="color: #00b8d9">FF 48 80 33 E3 A8</span><span style="color: #bf2600"> 00</span><span style="color: #36b37e"> D2</span> <span style="color: #403294">02 01 06 05 16 6E 2A 72 09 0E 09 50 20 54 20 45 4E 20 38 30 43 42 37 36</span>

| <span style="color: #00b8d9">FF 48 80 33 E3 A8</span> | <span style="color: #ff5630">00</span> | <span style="color: #36b37e">D2</span> | <span style="color: #403294">02 01 06 05 16 6E 2A 72 09 0E 09 50 20 54 20 45 4E 20 38 30 43 42 37 36</span> |
| --- | --- | --- | --- |
| MAC address of scanned device | Message type | RSSI | RAW message data |

- Message type - there are several distinct types of messages. Reference the following table to determine the received message type:

| **Message type value** | **Value meaning:** |
| --- | --- |
| 0x00 | Scannable and connectable advertising. |
| 0x01 | Directed connectable advertising. |
| 0x02 | Non-connectable and scannable advertising. |
| 0x03 | Non-connectable and non-scannable advertising. |
| 0x04 | Additional advertising data requested by an active scanner (message acquired during active scan). |
| 0x05 | Extended advertising. |

- RSSI - this value is signal strength. To convert RSSI into dBm do a byte hex to decimal conversion. In this example RSSI is -46 dBm:


- RAW message data - this represents the data generated by the beacon or device manufacturer. To understand the formation of this data, refer to the "Example" section within the [https://xirgotech.atlassian.net/wiki/spaces/~266691641/pages/44992181](https://xirgotech.atlassian.net/wiki/spaces/~266691641/pages/44992181) function.

### <span style="color: #36b37e">Function call example</span>

```c
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
#include <socket>
#include <bluetooth>

forward public callback (event);

new scan_parameters[.type, .options, .interval, .window, .timeout, .interval_coded, .window_coded];
new mac_addr_filter[] = [0xFF, 0x48, 0x80, 0x33, 0xE3, 0xA8];
new scan_data_length = 0;
new scanned_adv_data[255];

public callback (event)
{
    switch(event)
    {
        case BT_FILTER_MATCH:
        {
            scan_data_length = bt_adv_packet_read(scanned_adv_data, BT_FILTER_MATCH);
        }
        case BT_FILTER_MISMATCH:
        {
            // SCAN FILTER MISMATCH CALLBACK
        }
    }
    return 0;
}

main()
{
    scan_parameters[.type] = BT_SCAN_TYPE_ACTIVE;
    scan_parameters[.options] = BT_ADV_OPT_NONE;
    scan_parameters[.interval] = BT_SCAN_INTERVAL_FAST;
    scan_parameters[.window] = BT_SCAN_WINDOW_FAST;
    scan_parameters[.timeout] = 0;
    scan_parameters[.interval_coded] = 0;
    scan_parameters[.window_coded] = 0;
    
    bt_init();
    bt_scan_init(scan_parameters);
    bt_scan_filter_add(BT_SCAN_FILTER_TYPE_ADDR_PUBLIC, mac_addr_filter, sizeof(mac_addr_filter));
    bt_scan_filter_enable((BT_SCAN_FILTER_NAME | BT_SCAN_FILTER_ADDR), false);
    bt_scan_callback_enable(BT_FILTER_MATCH); 
    bt_scan_start();
    for(;;)
    {
        Delay(100);
    }
}
```

### <span style="color: #36b37e">Notes and Warnings</span>

While it is feasible to utilize this function outside of a callback, it is advisable to read advertisement data within the callback to ensure that no messages are missed.