bt_gatt_chrc_create()
Description
Function to create a GATT characteristic in a GATT service. Only 128-bit (16-byte) UUIDs are available for creation.
GATT server is limited to 40 attributes, 10 services, 13 characteristics of which 7 can be used for notifications. Also a 1112-byte memory pool is shared among all characteristics where chrc_value_size is used.
Take note that system services also use these limits. Refer to the system services page for more information.
It is required to create at least one GATT service prior to the creation of any GATT characteristic.
Syntax
bt_gatt_chrc_create(chrc_uuid[], properties, chrc_value_size, user_reference);
Parameters
Variable | Input |
|---|---|
| Characteristic UUID. Must up to 16 bytes (128-bits) length. |
| Characteristic properties allow certain characteristic operations to be permitted. Multiple properties can be set by using |
| Characteristic value size. This argument reserves the specified number of bytes for this characteristic. Maximum value is 200 bytes. Value must be higher than |
| Optional user-defined characteristic reference. Range: 1-240 or 0 to disable. References must be unique if used. This reference could be used as an argument to update characteristic values and when reading data received from the GATT client. |
Characteristic properties
Property | Value | Description |
|---|---|---|
| 0x00 | Characteristic with no properties. |
| 0x02 | Allows reading of the characteristic value. |
| 0x04 | Allows writing to the characteristic value without waiting for a response. |
| 0x08 | Allows writing to the characteristic value. |
| 0x10 | Allows subscribing to receive notifications when the characteristic value changes. |
| 0x20 | Allows subscribing to receive indications when the characteristic value changes. |
| 0x40 | Allows signed writes to the characteristic, requests authentication. |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Successfully created a GATT characteristic. |
SCRIPT_OPERATION_FAILED | Failed to create a GATT characteristic. Reasons:
|
SCRIPT_NO_ACCESS | Bluetooth gatt server is not initialized. |
SCRIPT_PARAM_INVALID | Reasons:
|
Function call example
#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, 0x97, 0x99, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB];
new chrc_reference_2 = 2;
main()
{
bt_init();
bt_gatt_server_init();
bt_gatt_service_create(service_uuid);
bt_gatt_chrc_create(chrc_uuid_1, GATT_CHRC_PROP_READ | GATT_CHRC_PROP_NOTIFY, 20, 0);
bt_gatt_chrc_create(chrc_uuid_2, GATT_CHRC_PROP_WRITE, 0, chrc_reference_2);
for(;;)
{
Delay(100);
}
}