bt_gatt_chrc_update_by_uuid()

bt_gatt_chrc_update_by_uuid()

Description

This function is designed to update GATT server characteristic values and dispatch notifications or indications when enabled. It uses UUID to identify the characteristic and is best suited for handling string and custom data types.

Syntax

bt_gatt_chrc_update_by_uuid(chrc_uuid[], data[], data_length);

Parameters

Variable

Input

Variable

Input

chrc_uuid[]

Characteristic UUID. Must be up to 16 bytes (128-bits) length.

data[]

Data to update the characteristic value.

data_length

Length of the data to be updated. Maximum data length value is 200 bytes.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Successfully updated the characteristic value.

SCRIPT_OPERATION_FAILED

Failed to update the characteristic value.

SCRIPT_NO_ACCESS

Bluetooth GATT server is not initialized.

SCRIPT_PARAM_INVALID

Possible reasons:

  • Characteristic was not found in the GATT server.

  • Data did not fit in the characteristic value buffer.

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[UUID_LENGTH_128_BIT] = [0x05, 0x12, 0x96, 0x99, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB]; new chrc_data[40]; main() { bt_init(); bt_gatt_server_init(); bt_gatt_service_create(service_uuid); bt_gatt_chrc_create(chrc_uuid, GATT_CHRC_PROP_READ | GATT_CHRC_PROP_NOTIFY, sizeof(chrc_data), 0); bt_gatt_server_start(); for(;;) { Delay(10000); snprintf(chrc_data, sizeof(chrc_data), "Ticks:%d\r\nVCC:%d\r\n", get_val(Sensor_Ticks), get_val(SENSOR_VCC)); bt_gatt_chrc_update_by_uuid(chrc_uuid, chrc_data, strlen(chrc_data)); } }