Hi Renesas,
I am using DA14531 with central exemple. I am able to discover new services and read the characteristic value. I have one service that demand read and write. How to write on this service ?
I have the GATTC_READ_IND and GATTC_EVENT_IND case which work well. I wanted to do the write event with GATTC_WRITE_CMD case but it's not going in this case.
Do you have any recommendations ?
Thank you,
Kind regards,
Anto
Hi Anto,Thank you for posting your question online.
Anto said:I am using DA14531 with central exemple. I am able to discover new services and read the characteristic value. I have one service that demand read and write. How to write on this service ?
As you can see on the ReadMe of the Central Example:On the user_ble_gatt.h file you can find:
/** **************************************************************************************** * @brief Perform a gatt write * @param[in] con_idx - connection identifier * @param[in] handle - attribute handle to write * @param[in] data - data to write * @param[in] data_len - data len * @return void **************************************************************************************** */ void user_ble_gatt_write(uint8_t op, uint8_t con_idx, uint16_t handle, uint8_t *data, uint16_t data_len);
/** **************************************************************************************** * @brief Perform a gatt write * @param[in] con_idx - connection identifier * @param[in] handle - attribute handle to write * @param[in] data - data to write * @param[in] data_len - data len * @return void **************************************************************************************** */ void user_ble_gatt_write(uint8_t op, uint8_t con_idx, uint16_t handle, uint8_t *data, uint16_t data_len) { struct gattc_write_cmd *cmd = KE_MSG_ALLOC_DYN(GATTC_WRITE_CMD, KE_BUILD_ID(TASK_GATTC, con_idx), TASK_APP, gattc_write_cmd, sizeof(struct gattc_write_cmd) + data_len); cmd->operation = op; cmd->auto_execute = 1; cmd->seq_num = 0; cmd->offset = 0; cmd->length = data_len; cmd->cursor = 0; cmd->handle = handle; memcpy(&cmd->value[0], data, data_len); ke_msg_send(cmd); }
case GATTC_WRITE: { dbg_printf("Completion Event: GATTC_WRITE\r\n", evt->operation); break; }
Thanks for your answer!
case GATTC_WRITE: { struct gattc_write_cmd const *writepin = (struct gattc_write_cmd const*)param; #ifdef ENABLE_PIN if(writepin->handle == central_app_env.periph_devices[conn_idx].serv_disc.pin_char.c.value_handle) { uint8_t valTest = 1; user_ble_gatt_write(writepin->operation, conn_idx, writepin->handle, &valTest, sizeof(uint8_t)); } #endif break; }
Hi Anto,Thank you for the reply.The GATTC_WRITE case will be triggered only when the GATT write has been completed. This is the reason why you are not able to write on your characteristic. Please try the same approach on a different place in your code. For instance, try this code after the Service and Characteristics discovery has been finished.
/** **************************************************************************************** * @brief After full discovery finished * @param[in] con_idx - connection identifier * @return void **************************************************************************************** */ static void handle_service_disc_finished(uint8_t con_idx) { #ifdef ENABLE_BAS if(central_app_env.periph_devices[con_idx].serv_disc.bas_handle_valid){ user_gatt_read_simple(con_idx, central_app_env.periph_devices[con_idx].serv_disc.bas_char.c.value_handle); } #endif #ifdef ENABLE_IAS if(central_app_env.periph_devices[con_idx].serv_disc.ias_handle_valid){ configure_alert_button(); } #endif }
Hi OV_Renesas,
Thank for your answer!Everything is clearer now.
Kind Regards,Anto