Hi,
I am trying to implement BLE on nRF52840 using Zephyr APIs. I am wondering if anyone can elaborate how to use bt_gatt_write() and bt_gatt_read(). As of now, I am able to see the definition and description of these function in gatt.h, but there is some information I need to know before I can use these two functions properly.
I know there is this structure called bt_gatt_write_params for passing parameters in bt_gatt_write function but as in the header file it's defined as:
struct bt_gatt_write_params {
/** Response callback */
bt_gatt_write_func_t func;
/** Attribute handle */
uint16_t handle;
/** Attribute data offset */
uint16_t offset;
/** Data to be written */
const void *data;
/** Length of the data */
uint16_t length;
};
So, Its not clear to me what does data offset means here. FYI we need a custom service having a couple of characteristics. Now, I need to write and read those characteristics. I made the service as follows:
BT_GATT_SERVICE_DEFINE(Service_name,
BT_GATT_PRIMARY_SERVICE(&SERVICE_UUID),
//Dev ID
BT_GATT_CHARACTERISTIC(&DEV_ID_UUID,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE,
BT_GATT_PERM_READ, NULL, NULL,
dev_ID),
//Device type,
BT_GATT_CHARACTERISTIC(&DEV_TYPE_UUID,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE,
BT_GATT_PERM_READ, NULL, NULL,
0x00),
//Dev description
BT_GATT_CHARACTERISTIC(&DEV_DESC_UUID,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE,
BT_GATT_PERM_READ, NULL, NULL,
0x00),
//Status
BT_GATT_CHARACTERISTIC(&STATUS_UUID,
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, NULL, NULL,
0x00),
//TX
BT_GATT_CHARACTERISTIC(&TX_UUID,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE,
BT_GATT_PERM_WRITE, NULL, NULL,
100),
//RX
BT_GATT_CHARACTERISTIC(&RX_UUID,
BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ, NULL, NULL,
0x00)
);
Can you please guide me how to read and write to any of these attribute let say if I want to write to TX and read from RX characteristics?