bt_gatt_chrc_update_by_ref()

bt_gatt_chrc_update_by_ref()

Description

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

Syntax

bt_gatt_chrc_update_by_ref(user_ref, data[], data_length);

Parameters

Variable

Input

Variable

Input

user_ref

User-defined reference from chracteristic creation. Available range 1-240.

data[]

Data buffer 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_ref = 3; 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), chrc_ref); 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_ref(chrc_ref, chrc_data[], strlen(chrc_data)); } }