2

I face issue , once GATT Operation done, Second time i am unable to scan any Beacon.

I am developing basic demo BLE app. Wearable SDK 3.0, Device: Samsung Gear S2, I have two buttons Start and Stop. when press start button app start scanning and if found perticular like MY_BEACON_1 then gatt operation perform.

GATT operation-> read service - characterstic- descriptor UUIDs, Write command and get response. once i finished write comand and get all operation then unable to scan beacon second time.

what i did for disconnect beacon:

1) Stop scan, -success

2) Derigister characteristic. -success

3) Call GATT connection callback - success

4) Disconnect Client -success

5) Deregister GATT -success

6) Deintiliaze Bluetooth all operations. -success

"If i disconnect battery cell of beacon then connect (add) , scanning is work."

Stop button some time give positive response like: client successfully destroy, Successfully deregister GATT, But not work all time Please suggest me the right way to disconnet chip, GATT, Client. Code (stop) button:

//release all resources once user press stop or close app.

void release_resources() {

 /* not work.
  ret = bt_gatt_set_value(chr, "QUIT\r", 4);
 if (ret != BT_ERROR_NONE) {
  dlog_print(DLOG_ERROR, LOG_TAG, "set failed Resume %d", ret);
  //return;
 } else {
  dlog_print(DLOG_INFO, LOG_TAG, "set success Resume", ret);
 }*/

//appdata_s *ad=(appdata_s *) data;
 dlog_print(DLOG_INFO, LOG_TAG, "Remote address of FxChip %s",ad->remote_address_global);

 //stop scanning
 ret = bt_adapter_le_stop_scan();
 if (ret != BT_ERROR_NONE) {
  dlog_print(DLOG_ERROR, LOG_TAG, "[bt_adapter_le_stop_scan] failed.");
 }

 bt_swtich_response(ret, "LE Stop");

 char *svc_uuid = "0bd51666-e7cb-469b-8e4d-2742f1ba77cc";
 char *chr_uuid = "e7add780-b042-4876-aae1-112855353cc1";

 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 failed: %d",
    ret);
  //return;
 }

 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 failed: %d", ret);
  //return;
 }

 ret = bt_gatt_client_unset_characteristic_value_changed_cb(chr);
 if (ret != BT_ERROR_NONE) {
  dlog_print(DLOG_INFO, LOG_TAG,
    "bt_gatt_client_unset_characteristic_value_changed_cb failed: %d",
    ret);
  //return;
 } else {
  dlog_print(DLOG_INFO, LOG_TAG,
    "bt_gatt_client_unset_characteristic_value_changed_cb succesful");
 }

 //De-register the GATT connection callback
 ret = bt_gatt_unset_connection_state_changed_cb();

 if (ret != BT_ERROR_NONE)
  dlog_print(DLOG_INFO, LOG_TAG, "Failed to deregister");
 else
  dlog_print(DLOG_INFO, LOG_TAG, "Successfully deregister");
 bt_swtich_response(ret, "De register");

 // Destroy the client
 if (client != NULL) {
  ret = bt_gatt_client_destroy(client);
  if (ret == BT_ERROR_NONE) {
   dlog_print(DLOG_INFO, LOG_TAG, "Successfully destroy client");

  } else
   dlog_print(DLOG_INFO, LOG_TAG, "Falied to destroy client");
  client = NULL;
  bt_swtich_response(ret, "Client");
 }

 //Disconnect : got null value;
 ret = bt_gatt_disconnect(ad->remote_address_global);
 dlog_print(DLOG_INFO, LOG_TAG, "%s",
   ret == BT_ERROR_NONE ?
     "Successfully disconnect GATT - stop call" :
     "Fail to disconnect GATT- stop call ");
 bt_swtich_response(ret, "GATT Disconnect");

 // Deinitialize Bluetooth
 ret = bt_deinitialize();
 if (ret != BT_ERROR_NONE) {
  dlog_print(DLOG_ERROR, LOG_TAG, "[bt_deinitialize] Failed.");
 } else {
  dlog_print(DLOG_ERROR, LOG_TAG, "[bt_deinitialize] Success.");
 }
 bt_swtich_response(ret, "De initialize");

 bt_mgr_release();
}

void bt_mgr_release(void) {
 bt_adapter_unset_state_changed_cb();
 bt_adapter_unset_device_discovery_state_changed_cb();
 bt_device_unset_service_searched_cb();
 bt_socket_unset_data_received_cb();
 bt_socket_unset_connection_state_changed_cb();
 bt_deinitialize();
}



void bt_swtich_response(int ret, char *s) {
 dlog_print(DLOG_INFO, LOG_TAG, "################## %s ###################",
   s);
 switch (ret) {
 case BT_ERROR_NONE:
  dlog_print(DLOG_INFO, LOG_TAG, "Successful");
  break;
 case BT_ERROR_NOT_INITIALIZED:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_NOT_INITIALIZED");
  break;
 case BT_ERROR_NOT_ENABLED:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_NOT_ENABLED");
  break;
 case BT_ERROR_INVALID_PARAMETER:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_INVALID_PARAMETER");
  break;
 case BT_ERROR_OPERATION_FAILED:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_OPERATION_FAILED");
  break;
 case BT_ERROR_PERMISSION_DENIED:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_PERMISSION_DENIED");
  break;
 case BT_ERROR_NOT_SUPPORTED:
  dlog_print(DLOG_INFO, LOG_TAG, "BT_ERROR_NOT_SUPPORTED");
  break;
 default:
  dlog_print(DLOG_INFO, LOG_TAG, "Default called");
  break;
 }
}

It would be great if any other process for disconnect beacon for Samsung Gear S2.

Thanks in Advance.

0 Answers0