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

Function to receive data from the GATT client. Characteristic UUID and user reference are used for identification. Data can be read only once.

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

`bt_gatt_server_receive(data[]);`

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

| **Variable** | **Input** |
| --- | --- |
| `data[]` | Data buffer where the newly written characteristic value resides. Refer below for the data structure.<br>> ℹ️ The data header is specified to be **18 bytes**, meaning that the buffer size needs to be a minimum of **19 bytes** to successfully read a single data byte. The maximum allowable data size is **220 bytes**. |

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

|  |  |
| --- | --- |
| **Return value** | **Return explanation** |
| **SCRIPT_OPERATION_FAILED** | Invalid data buffer. |
| **SCRIPT_NO_ACCESS** | Bluetooth GATT server is not initialized. |
| **Data length** | In case of success, function will return the number of bytes received in the buffer. |

Data will follow this format:

**Example 1 (No user reference was assigned):**

GATT server callback data: 00 02 6E 40 00 03 B5 A3 F3 93 E0 A9 E5 0E 24 DC CA 9E 00 10

            - User-defined reference

            - UUID Type (0x00 - 16 bit UUID, 0x01 - 32 bit UUID, 0x02 - 128 bit UUID)

            - UUID

            - Data

**Example 2 (User reference was assigned) :**

GATT server callback data: 05 02 6E 40 00 04 B5 A3 F3 93 E0 A9 E5 0E 24 DC CA 9E 74 65 73 74

            - User-defined reference

            - UUID Type (0x00 - 16 bit UUID, 0x01 - 32 bit UUID, 0x02 - 128 bit UUID)

            - UUID

            - Data

### <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>

new service_uuid[UUID_LENGTH_128_BIT] = [0x08, 0x07, 0x06, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB];
new chrc_uuid_1[UUID_LENGTH_128_BIT] = [0x05, 0x12, 0x96, 0x99, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB];
new chrc_uuid_2[UUID_LENGTH_128_BIT] = [0x05, 0x12, 0x96, 0x99, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB];
new chrc_handle_2 = 5;
new gatt_rx_data[64];

forward public callback (event);

public callback (event)
{
    switch(event)
    {
        case BT_GATT_SERVER_RX:
        {
            new data_len = bt_gatt_server_receive(gatt_rx_data);
            
            if (gatt_rx_data[GATT_RX_HEADER_USER_REF_POS] == chrc_handle_2)
            {
                chrc_2_rx(data_len);
            }
        }
    }
    return 0;
}

chrc_2_rx(msg_len)
{
    /* Handle characteristic write code start */
    
    /* Handle characteristic write code end */
}

main()
{   
    bt_init();
    bt_gatt_server_init();
    bt_gatt_service_create(service_uuid);
    bt_gatt_chrc_create(chrc_uuid_1, GATT_CHRC_PROP_WRITE, 0, 0);
    bt_gatt_chrc_create(chrc_uuid_2, GATT_CHRC_PROP_WRITE, 0, chrc_handle_2);
    
    for(;;)
    {
        Delay(100);
    }
}
```