void __bt_adapter_le_scan_result_cb(int result,bt_adapter_le_device_scan_result_info_s *info, void *user_data)
dlog_print(DLOG_INFO, LOG_TAG, "some info found for patch %s",info->remote_address);
ret = bt_gatt_set_connection_state_changed_cb(_bt_gatt_connection_state_changed_cb, NULL);
dlog_print(DLOG_ERROR, LOG_TAG,"[__bt_gatt_connection_state_changed_cb] Failed.");
dlog_print(DLOG_ERROR, LOG_TAG, "Callback registered. %d ", ret);
dlog_print(DLOG_ERROR, LOG_TAG, "[bt_device_destroy_bond] failed. %d",ret);
ret = bt_device_set_bond_created_cb(device_bond_created_cb, info->remote_address);
dlog_print(DLOG_ERROR, LOG_TAG, "[bt_device_set_bond_created_cb] failed. %d",ret);
dlog_print(DLOG_INFO, LOG_TAG, "[bt_device_create_bond] succeeded. device_bond_created_cb callback will be called.");
void device_bond_created_cb(int result, bt_device_info_s *device_info, void *user_data)
{bt_gatt_h svc = NULL;
bt_gatt_h chr = NULL;
bt_gatt_h chr1 = NULL;
bt_gatt_h desc = NULL;
if (result != BT_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "[bt_device_bond_created_cb] failed. result(%d).", result);
return;
}
dlog_print(DLOG_ERROR, LOG_TAG, "[bt_device_bond_created_cb] success. result(%d).", result);
ret=bt_device_set_authorization_changed_cb(__bt_device_authorization_changed_cb,device_info->remote_address);
if (ret != BT_ERROR_NONE)
{
dlog_print(DLOG_INFO, LOG_TAG, "callback is not registered");
}
else
{
dlog_print(DLOG_INFO, LOG_TAG, "athorization callback is registered");
}
ret=bt_device_set_authorization(device_info->remote_address,BT_DEVICE_AUTHORIZED);
if (ret != BT_ERROR_NONE)
{
dlog_print(DLOG_INFO, LOG_TAG, "device is not authorized %d",ret);
dlog_print(DLOG_INFO, LOG_TAG, "device is not authorized remote address %s",device_info->remote_address);
}
else
{
dlog_print(DLOG_INFO, LOG_TAG, "device authorized");
}
ret = bt_gatt_client_create(device_info->remote_address, &client);
if (ret == BT_ERROR_NONE)
{
dlog_print(DLOG_INFO, LOG_TAG, "Client created");
Evas_Object *label = elm_label_add(box);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(box,EVAS_HINT_FILL,EVAS_HINT_FILL);
elm_object_text_set(label, "Client Created");
elm_box_pack_end(box,label);
evas_object_show(label);
char *addr = NULL;
ret = bt_gatt_client_get_remote_address(client, &addr);
if (ret == BT_ERROR_NONE)
dlog_print(DLOG_INFO, LOG_TAG, "Success %s",addr);
ret = bt_gatt_client_foreach_services(client, __bt_gatt_client_foreach_svc_cb, NULL);
if (ret != BT_ERROR_NONE)
{
dlog_print(DLOG_INFO, LOG_TAG, "fail");
}
ret = bt_gatt_client_get_service(client, SERVICE_UUID, &svc);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service failed: %d", ret);
return;
}
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service success: %d", ret);
ret = bt_gatt_service_get_characteristic(svc, CHAR_WRITE, &chr);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic failed: %d", ret);
return;
}
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic success: %d", ret);
ret = bt_gatt_service_get_characteristic(svc, CHAR_NOTIFY, &chr1);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic failed: %d", ret);
return;
}
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic success: %d", ret);
ret = bt_gatt_client_set_characteristic_value_changed_cb(chr1, __bt_gatt_client_value_changed_cb,
NULL);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_set_characteristic_value_changed_cb failed: %d", ret);
return;
}
ret = bt_gatt_characteristic_get_descriptor(chr1, CHAR_NOTIFYCCD, &desc);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor failed: %d", ret);
return;
}
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor success: %d", ret);
ret = bt_gatt_client_read_value(desc, __bt_gatt_client_read_complete_cb, NULL);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_read_value failed: %d", ret);
return;
}
char *myArray = (char []) {0x01, 0x00 };
ret = bt_gatt_set_value(desc, myArray, 2);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_set_value failed: %d", ret);
return;
}
else {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_set_value :");
}
ret = bt_gatt_client_write_value(desc, __write_completed_cb, NULL);
if (ret != BT_ERROR_NONE) {
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_write_value failed: %d %s", ret, ret);
return;
}
}