- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BLE Data Exchange
Please read section BLE Data Exchange in document How-to-Write-WICED-Smart-Applications.pdf(in directory of WICED-Smart-SDK\Doc). Make sure you understand what Attribute, Characteristic, Descriptor, Service, Profile are.
GATT Database Access
Please read section GATT Database in document How-to-Write-WICED-Smart-Applications.pdf.
GATT Database Structure
Please read through section Create a GATT Database in the BLE Application in document How-to-Write-WICED-Smart-Applications.pdf. Try to find answers to the following questions:
- What is the difference between 16-bits and 128-bits UUID?
- What’s the data length of a handle of characteristic?
- What’s the purpose of a handle compared with UUID?
- Why does a characteristic have two handles?
- Are services UUID_SERVICE_GATT and UUID_SERVICE_GAP mandatory for each of BLE device?
Properties and Permissions
Section 3.3.1.1 Characteristic Properties in Bluetooth Core Specification v4.0 helps to understand the following definitions that are required to describe properties a characteristic.
LEGATTDB_CHAR_PROP_BROADCAST | Permits the broadcast of characteristic value |
LEGATTDB_CHAR_PROP_READ | Permits the read of the characteristic value |
LEGATTDB_CHAR_PROP_WRITE_NO_RESPONSE | Permits the write of the characteristic value without response |
LEGATTDB_CHAR_PROP_WRITE | Permits the write of the characteristic value with response |
LEGATTDB_CHAR_PROP_NOTIFY | Permits the notification of the characteristic value without acknowledgement |
LEGATTDB_CHAR_PROP_INDICATE | Permits the indication of the characteristic value with acknowledgement |
LEGATTDB_CHAR_PROP_AUTHD_WRITES | Permits signed writes to the characteristic value |
LEGATTDB_CHAR_PROP_EXTENDED | Additional characteristic properties are defined |
Section 3.2.5 Attribute Permissions in Bluetooth Core Specification v4.0 helps to understand the following definitions that are required to describe permissions a characteristic.
LEGATTDB_PERM_NONE | Characteristic value is not readable or writable (can support indication or notification) |
LEGATTDB_PERM_VARIABLE_LENGTH | Characteristic value can be a variable-length array |
LEGATTDB_PERM_READABLE | Permits the read of the characteristic value |
LEGATTDB_PERM_WRITE_CMD | Permits the write of the characteristic value without response |
LEGATTDB_PERM_WRITE_REQ | Permits the write of the characteristic value with response |
LEGATTDB_PERM_AUTH_READABLE | Permits the authenticated read operation |
LEGATTDB_PERM_RELIABLE_WRITE | Permits reliable write operation |
LEGATTDB_PERM_AUTH_WRITABLE | Permits authenticated write operation |
Create a GATT Database
A GATT database can be found in file hello_sensor.c of application Hello Sensor. Remove comments then we can get the definition of GATT database for example application hello_sensor as showed in Figure 1. Macro CHARACTERISTIC_UUID16* or CHARACTERISTIC_UUID128* add a characteristic to a previously defined service. Macro CHAR_DESCRIPTOR_UUID16* adds a characteristic descriptor to a previously defined characteristic.
const UINT8 hello_sensor_gatt_database[]=
{
PRIMARY_SERVICE_UUID16 (0x0001, UUID_SERVICE_GATT),
PRIMARY_SERVICE_UUID16 (0x0014, UUID_SERVICE_GAP),
CHARACTERISTIC_UUID16 (0x0015, 0x0016, UUID_CHARACTERISTIC_DEVICE_NAME, LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE, 16), 'H','e','l','l','o',0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
CHARACTERISTIC_UUID16 (0x0017, 0x0018, UUID_CHARACTERISTIC_APPEARANCE,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 2), BIT16_TO_8(APPEARANCE_GENERIC_TAG),
PRIMARY_SERVICE_UUID128 (HANDLE_HELLO_SENSOR_SERVICE_UUID, UUID_HELLO_SERVICE),
CHARACTERISTIC_UUID128 (0x0029, HANDLE_HELLO_SENSOR_VALUE_NOTIFY, UUID_HELLO_CHARACTERISTIC_NOTIFY,
LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_INDICATE,
LEGATTDB_PERM_READABLE, 7), 'H','e','l','l','o',' ','0',
CHAR_DESCRIPTOR_UUID16_WRITABLE (HANDLE_HELLO_SENSOR_CLIENT_CONFIGURATION_DESCRIPTOR,
UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,
LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ, 2), 0x00,0x00,
CHARACTERISTIC_UUID128_WRITABLE (0x002c, HANDLE_HELLO_SENSOR_CONFIGURATION, UUID_HELLO_CHARACTERISTIC_CONFIG,
LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE,
LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ, 1), 0x00,
PRIMARY_SERVICE_UUID16 (0x004d, UUID_SERVICE_DEVICE_INFORMATION),
CHARACTERISTIC_UUID16 (0x004e, 0x004f, UUID_CHARACTERISTIC_MANUFACTURER_NAME_STRING, LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE, 8), 'B','r','o','a','d','c','o','m',
CHARACTERISTIC_UUID16 (0x0050, 0x0051, UUID_CHARACTERISTIC_MODEL_NUMBER_STRING, LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE, 8), '1','2','3','4',0x00,0x00,0x00,0x00,
CHARACTERISTIC_UUID16 (0x0052, 0x0053, UUID_CHARACTERISTIC_SYSTEM_ID, LEGATTDB_CHAR_PROP_READ,
LEGATTDB_PERM_READABLE, 8), 0x93,0xb8,0x63,0x80,0x5f,0x9f,0x91,0x71,
PRIMARY_SERVICE_UUID16 (0x0061, UUID_SERVICE_BATTERY),
CHARACTERISTIC_UUID16 (0x0062, 0x0063, UUID_CHARACTERISTIC_BATTERY_LEVEL,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 1), 0x64,
};
Figure 1 Definition of Hello Sensor GATT database
Following is the hierarchy diagram that reflects above definition.
Figure 2 Hierarchy of Hello Sensor GATT Database
Figure 3 shows the breakdown of characteristic definition. Please make sure the value and the length of the value match. Macro CHARACTERISTIC_UUID128_WRITABLE should be used to define a writable 128-bits characteristic instead of CHARACTERISTIC_UUID128.
Figure 3 Breakdown of Characteristic Definition
One or more descriptors can exist in each characteristic definition. Possible descriptors are defined in the Bluetooth specification. Please refer to 3.3.3 Characteristic Descriptor Declarations[vol 3] in Bluetooth Core Specification V4.0 to understand the following C programming definition.
enum ble_uuid_characteristic_descriptor
{
UUID_DESCRIPTOR_CHARACTERISTIC_EXTENDED_PROPERTIES = 0x2900,
UUID_DESCRIPTOR_CHARACTERISTIC_USER_DESCRIPTION = 0x2901,
UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION = 0x2902,
UUID_DESCRIPTOR_SERVER_CHARACTERISTIC_CONFIGURATION = 0x2903,
UUID_DESCRIPTOR_CHARACTERISTIC_PRESENTATION_FORMAT = 0x2904,
UUID_DESCRIPTOR_CHARACTERISTIC_AGGREGATE_FORMAT = 0x2905,
UUID_DESCRIPTOR_VALID_RANGE = 0x2906,
UUID_DESCRIPTOR_EXTERNAL_REPORT_REFERENCE = 0x2907,
UUID_DESCRIPTOR_REPORT_REFERENCE = 0x2908,
//0.9, added after tapeout
UUID_DESCRIPTOR_NUMBER_OF_DIGITALS = 0x2909,
UUID_DESCRIPTOR_TRIGGER_SETTING = 0x290A,
};
Figure 4 Standard Characteristic Descriptors
Examine a GATT Database
You can dump the content of GATT database during runtime for debug. Figure 5 shows the output of debug UART after calling function legattdb_dumpDb().
14:46:36 - 0118
14:46:36 - 0018
14:46:36 - 021600002a
14:46:36 - 48656c6c6f0000000000000000000000
14:46:36 - 021800012a
14:46:36 - 0002
14:46:36 - 2320567c05cf6eb4c341772851827e1b
14:46:36 - 322a0026f6699168eec2be444db95c3f
14:46:36 - 2dc38a
14:46:36 - 48656c6c6f2031
14:46:36 - 0000
14:46:36 - 0a2d001a89074a2f3b7ea681443ff9a8
14:46:36 - f29b5e
14:46:36 - 00
14:46:36 - 48656c6c6f20436f6e666967
14:46:36 - 0a18
14:46:36 - 024f00292a
14:46:36 - 42726f6164636f6d
14:46:36 - 025100242a
14:46:36 - 3132333400000000
14:46:36 - 025300232a
14:46:36 - 93b863805f9f9171
14:46:36 - 0f18
14:46:36 - 026300192a
14:46:36 - 01
Figure 5 Output of legattdb_dumpDb()
Practice with Hello Sensor Application
Complete the following two assignment to verify what you have learned from this session:
- Add a new characteristic to expose hello_sensor_timer_count in example application Hello Sensor.
- Add a Characteristic User Description Descriptor for characteristic HELLO_SENSOR_CONFIGURATION.
- Labels:
-
ReadWrite Characteristics
-
SDK 1.X
-
SDK 2.X
- Tags:
- gatt database