Hello,
We are developing over a custom hardware which shows few sewrvice. WE try to connect them and read from Gear Application.
For Read it is giving value 0 and for write it is giving failure.
Here is my code:
void _bt_gatt_connection_state_changed_cb(int result, bool connected, const char *remote_address, void *user_data) { dlog_print(DLOG_INFO, LOG_TAG, "State Changed"); if (connected) { remote_addresss = remote_address; dlog_print(DLOG_INFO, LOG_TAG, "YES LE connected"); // ret = bt_gatt_client_create(remote_address, &client); // if (ret == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Created Client"); char *svc_uuid = "xxx"; // Custom service char *chr_uuid = "xxx"; // Custom Char // char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; // Battery service // char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; // Battery level // int len = 0; char *value = NULL; bt_gatt_h svc = NULL; bt_gatt_h char_svc = NULL; bt_gatt_h chr = NULL; bt_gatt_h desc = NULL; ret = bt_gatt_client_create("xx:xx:xx:xx:xx:xx", &client); if (ret == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Client created"); } //Get the service ret = bt_gatt_client_get_service(client, svc_uuid, &svc); if (ret != BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret); // return; } else { //GOt Service dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is success "); ret = bt_gatt_get_value(svc, &value, &len); if (ret != BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value is failed : %d", ret); } else { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value for service is : %d", value, " %s", value); } //Get Char ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr); if (ret != BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret); } else { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is success "); //Read value ret = bt_gatt_get_value(chr, &value, &len); int i = 0; F if (ret != BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value is failed : %d", ret); } else { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value is success : %d", len); for (i = 0; i < len; i++) { dlog_print(DLOG_INFO, LOG_TAG, "value %u", value[i]); } // dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value for char is : %d", value," %s", value); } int char_value = 30; //Set int value ret = bt_gatt_set_int_value(chr, BT_DATA_TYPE_UINT8, char_value, 1); if (ret == BT_ERROR_NONE) dlog_print(DLOG_INFO, LOG_TAG, "Success in write"); else dlog_print(DLOG_INFO, LOG_TAG, "Failure in write %d ", ret); ret = bt_gatt_client_read_value(chr, __bt_gatt_client_read_complete_cb, NULL); if (ret != BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_read_value is failed : %d", ret); } else { dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_read_value is success "); } } } // } } else dlog_print(DLOG_INFO, LOG_TAG, "LE disconnected"); }
Here are the logs:
) : Connected to our LE device.
) : State Changed
) : YES LE connected
) : Created Client
) : Client created
) : bt_gatt_client_get_service is success
) : bt_gatt_get_value is failed : -22
) : bt_gatt_service_get_characteristic is success
) : bt_gatt_get_value is success : 0
) : Failure in write
) : bt_gatt_client_read_value is success
) : Read Success for uuid : (xxx)
) : data : (0)
) : State Changed
) : LE disconnected
Could some one please help me?
Regards,
Shraddha