<li>Bluetooth GATT Operations
<ul class="toc">
<li><a href="#gatt_client">Gatt Client Role Operation</a></li>
- <li><a href="#gatt_server">Gatt Server Role Operation</a></li>
- <li><a href="#gatt_getter">Gatt Client/Server Getter Operation</a></li>
- <li><a href="#gatt_setter">Gatt Client/Server Setter Operation</a></li>
+ <li><a href="#gatt_getter">Gatt Client Getter Operation</a></li>
+ <li><a href="#gatt_setter">Gatt Client Setter Operation</a></li>
</ul>
</li>
<li>Object Push Profile (OPP)
<ul>
<li><a href="#gatt_client">Gatt Client Role Operations</a>
<p>Create a client to connect to a remote service, get service details, read and set service attributes and set/unset characteristic value changed information callback.</p></li>
- <li><a href="#gatt_server">Gatt Server Role Operations</a>
- <p>Create a Server, add or delete service, characteristics, and descriptors. Modify the attributes value and properties.</p></li>
- <li><a href="#gatt_getter">Gatt Client/Server Common Getter Operations</a>
- <p>Getter APIs which are used commonly for GATT Client and Server related operations.
+ <li><a href="#gatt_getter">Gatt Client Common Getter Operations</a>
+ <p>Getter APIs which are used commonly for GATT Client related operations.
</p></li>
- <li><a href="#gatt_setter">Gatt Client/Server Common setter operations</a>
+ <li><a href="#gatt_setter">Gatt Client Common setter operations</a>
<p>Set the properties and values of the attribute.</p></li>
</ul></li>
<li>Object Push Profile (OPP)
</pre></li>
</ol>
-<h2 id="gatt_server" name="gatt_server">GATT Server Role Operations</h2>
-<p>To perform GATT Server operations:</p>
-<p>The GATT Server stores the service and its characteristics, characteristic descriptors.</p>
-<p>The GATT Client reads the services of GATT Server and uses the service and its characteristics according to pre defined functionalities of the service.</p>
-<ol>
-<li>Initialize the server:
-<pre class="prettyprint">
- int ret = 0;
-
- ret = bt_gatt_server_initialize();
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-
-<li>Create the server:
-<pre class="prettyprint">
- int ret = 0;
- bt_gatt_server_h server = NULL;
-
- ret = bt_gatt_server_create(&server);
- if (ret != BT_ERROR_NONE) {
- dlog_print(DLOG_INFO, LOG_TAG, "Failure");
-</pre></li>
-
-<li>Create the Service:
-<pre class="prettyprint">
- int ret = 0;
- char *service_uuid = "180a"; // Device Infromation Service
- bt_gatt_h service = NULL;
-
- ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service);
- if (ret != BT_ERROR_NONE || service == NULL) {
- dlog_print(DLOG_INFO, LOG_TAG, "Failure");
-</pre></li>
-
-<li>Register the Service:
-<pre class="prettyprint">
- int ret = 0;
- char *service_uuid = "180a"; // Device Infromation Service
- bt_gatt_h service = NULL;
- bt_gatt_server_h server = NULL;
-
- /* Server initialized */
- /* Server created */
- /* Service added */
- /* Characteristic added */
- /* Descriptor added*/
- ret = bt_gatt_server_register_service(server, service);
- if (ret == BT_ERROR_NONE) {
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-
-<li>Create characteristic and add characteristic to service:
-<pre class="prettyprint">
- int ret = 0;
- bt_gatt_h service = NULL;
- bt_gatt_h characteristic = NULL;
- char *service_uuid = "180a"; // Device Infromation Service
- char *char_uuid = NULL;
- char *char_value;
- int permissions = BT_GATT_PERMISSION_READ;
- int properties = BT_GATT_PROPERTY_READ;
-
- /* Server initialized */
- /* Server created */
- /* Service added */
- /* Add characteristic */
- char_uuid = "2a29"; // Manufacturer Name String
- char_value = g_strdup("Company_x");
- ret = bt_gatt_characteristic_create(char_uuid, permissions, properties,
- char_value, strlen(char_value), &characteristic);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
- g_free(char_value);
-
- ret = bt_gatt_service_add_characteristic(service, characteristic);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-
-<li>Create descriptor and add descriptor to characteristic:
-<pre class="prettyprint">
- int ret = 0;
- bt_gatt_h service = NULL;
- bt_gatt_h characteristic = NULL;
- bt_gatt_h descriptor = NULL;
- char *service_uuid = "1809"; // Health Thermometer Service
- char *char_uuid = "2a1c"; // Temperature Measurement
- char *desc_uuid = "2902"; // CCCD
- char char_value[5] = {0, 0x85, 0xff, 0xff, 0xfe}; // Flag + Temperature Measurement Value (Celsius, -1.23)
- char desc_value[2] = {0, 0};
- int permissions = BT_GATT_PERMISSION_READ;
- int properties = BT_GATT_PROPERTY_INDICATE | BT_GATT_PROPERTY_READ; // READ property added for testing
-
- /* Server initialized */
- /* Server created */
- /* Service added */
- /* Characteristic Added */
- /* Add Descriptor */
- permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE;
- ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, sizeof(desc_value), &descriptor);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-
- ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-
-<li>Register a callback for connection state changes:
-<pre class="prettyprint">
-int ret = 0;
-// Register for GATT connection callback
-void __bt_gatt_connection_state_changed_cb(int result,
- bool connected,
- const char *remote_address,
- void *user_data)
-{
- if (connected)
- dlog_print(DLOG_INFO, LOG_TAG, "LE connected");
- else
- dlog_print(DLOG_INFO, LOG_TAG, "LE disconnected");
-}
-ret = bt_gatt_set_connection_state_changed_cb(__bt_gatt_connection_state_changed_cb, NULL);
-</pre></li>
-
-<li>Set/Update characteristic Value:
-<pre class="prettyprint">
- int ret = 0;
- char char_value[1] = {1 + (rand()%100)};
-
- /* Server initialized */
- /* Server created */
- /* Service added */
- /* Characteristic added */
- /* Descriptor added*/
-
- if (!server) {
- dlog_print(DLOG_INFO, LOG_TAG, "Failure");
- return;
- }
-
- if (!service) {
- dlog_print(DLOG_INFO, LOG_TAG, "Failure");
- return;
- }
-
- ret = bt_gatt_set_value(service.chr, char_value, 1);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-
-<li>Example:
-<pre class="prettyprint">
- int ret = 0;
- bt_gatt_h service = NULL;
- bt_gatt_h characteristic = NULL;
- bt_gatt_h descriptor = NULL;
- char *service_uuid = "1809"; // Health Thermometer Service
- char *char_uuid = "2a1c"; // Temperature Measurement
- char *desc_uuid = "2902"; // CCCD
- char char_value[5] = {0, 0x85, 0xff, 0xff, 0xfe}; // Flag + Temperature Measurement Value (Celsius, -1.23)
- char desc_value[2] = {2, 0}; // Indication enabled
- int permissions = BT_GATT_PERMISSION_READ;
- int properties = BT_GATT_PROPERTY_INDICATE | BT_GATT_PROPERTY_READ; // READ property added for testing
-
- /* Initialize Server*/
- ret = bt_gatt_server_initialize();
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-
- /* Create server */
- ret = bt_gatt_server_create(&server);
- if (ret == BT_ERROR_NONE) {
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-
- /* Create Service */
- ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service);
- if (ret == BT_ERROR_NONE) {
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-
- /* Add characteristic */
- ret = bt_gatt_characteristic_create(char_uuid, permissions, properties,
- char_value, strlen(char_value), &characteristic);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
- g_free(char_value);
-
- ret = bt_gatt_service_add_characteristic(service, characteristic);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-
- ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor);
- if (ret == BT_ERROR_NONE)
- dlog_print(DLOG_INFO, LOG_TAG, "Success");
-</pre></li>
-</ol>
-
-<h2 id="gatt_getter" name="gatt_getter">Performing GATT Client/Server Common Getter Operations</h2>
-<p>To perform Getter operations for both GATT Client/Server related information:</p>
+<h2 id="gatt_getter" name="gatt_getter">Performing GATT Client Common Getter Operations</h2>
+<p>To perform Getter operations for both GATT Client related information:</p>
<ol>
<li>Gets the type of a service, characteristic or descriptor's GATT handle:
<pre class="prettyprint">
bt_gatt_type_e gatt_type;
// Handle is already created either for Service/Characteristic/Descriptor using
- // bt_gatt_service_create()/bt_gatt_characteristic_create()/bt_gatt_descriptor_create() respectively.
ret = bt_gatt_get_type(gatt_handle, &gatt_type);
if (ret != BT_ERROR_NONE)
char *uuid = NULL;
// Handle is already created either for Service/Characteristic/Descriptor using
- // bt_gatt_service_create()/bt_gatt_characteristic_create()/bt_gatt_descriptor_create() respectively.
ret = bt_gatt_get_uuid(gatt_handle, &uuid);
if (ret != BT_ERROR_NONE)
char *value = NULL;
// Handle is already created either for Characteristic/Descriptor using
- // bt_gatt_characteristic_create()/bt_gatt_descriptor_create() respectively.
ret = bt_gatt_get_value(gatt_handle, &value, &len);
if (ret != BT_ERROR_NONE)
bt_gatt_h chr = NULL;
int properties;
- //get the characteristic handle using bt_gatt_characteristic_create() or bt_gatt_service_get_characteristic()
+ //get the characteristic handle using bt_gatt_service_get_characteristic()
ret = bt_gatt_characteristic_get_properties(chr, &properties);
if (ret != BT_ERROR_NONE)
int ret = 0;
char char_value[1] = {1 + (rand()%100)};
-/* In case of Server, characteristic_handle is created when characteristic is created using bt_gatt_characteristic_create(),
- * In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
+/* In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
* using the bt_gatt_service_get_characteristic()*/
ret = bt_gatt_set_value(characteristic_handle, char_value, 1);
int ret = 0;
int char_value = 60 + (rand()%60);
-/* In case of Server, characteristic_handle is created when characteristic is created using bt_gatt_characteristic_create(),
- * In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
+/* In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
* using the bt_gatt_service_get_characteristic()*/
ret = bt_gatt_set_int_value(characteristic_handle, BT_DATA_TYPE_UINT16, char_value, 1);
<pre class="prettyprint">
int ret = 0;
-/* In case of Server, characteristic_handle is created when characteristic is created using bt_gatt_characteristic_create(),
- * In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
+/* In case of Client, the characteristic handle shall be retrived from the client created using gatt_client_create(),
* using the bt_gatt_service_get_characteristic()*/
/* Here the char value is, value: 123 exponent -2 */