Note: This KBA has been marked as deprecated. A more updated KBA and example can be found here:
This article is about the differences among the types of a characteristic value. In the profile toolkit, there are 3 types of value can be used, hex, utf-8 and user. You can find detailed description in UG118, chapter 2.5.3.
hex: Value type is hex
utf-8: Value is a string
user: When the characteristic type is marked as type="user" the application is responsible of initializing the characteristic value and also providing it for example when read operation occurs. The Bluetooth stack does not initialize the value, nor automatically provide the value when it's being read. When this is set the Bluetooth stack generates gatt_server_user_read_request or gatt_server_user_write_request which must be handled by the application.
The idea of this article is to give both examples of type "user" and "hex" to help users choosing the right property of a characteristic value.
The most significant difference between the type “user” and the other two types is where the data is stored.
If you use "user" as the data type, the value of the characteristic is stored in the application layer. And you need to respond to write/read requests by sending write/read response back via API gecko_cmd_gatt_server_send_user_read_response(…) and gecko_cmd_gatt_server_send_user_write_response(…).
For example, there is a characteristic with length 20, you need to allocate a 20-byte buffer in the application layer to store its value.
IDE – Simplicity Studio 4
Software - Bluetooth SDK v2.7.0 or newer
Hardware – Bluetooth Compatiable Boards
Note: DO NOT FORGET TO CLICK “GENERATE” BUTTON AFTER YOU MODIFY THE FILE.
The example code shows where to handle the read and write requests to the characteristic with user type, as well as the event generated by write request to the characteristic with hex/utf-8 type.
Follow below steps to test the example:
When to use "user" and when to use "hex"?
The memory for user type characteristic is reserved by the application code so you can reserve any amount that you need for the characteristic.
The BT spec limits maximum characteristic length to 512 bytes so there's no point trying to go beyond that.
You can find the latest version of this file in https://github.com/KevinFuSilabs/log_module.git
Where is the main.c, app.c, and app.h files mentioned in this demo?