2016-10-27 3 views
1

연결을 끊고 BLE 장치를 전화기에 연결하는 데 문제가 있습니다. 내 전화기에는 연결 해제 버튼이 있습니다. 전화기와 장치가 연결되면 장치를 눌러 연결을 끊습니다. 성공적으로 연결이 끊어졌습니다. 그러나 연결 함수를 호출하면 10 초 후에 다시 연결됩니다. 이것은 내 코드이고 logcat입니다. 재 연결 시간을 줄이는 데 도와 주시겠습니까? 클라이언트가 링크 계층 수준에 연결 요청을 보낼 때BLE에서 재 연결 시간을 수정하는 방법은 무엇입니까?

public boolean connect(final String address) { 
     if (mBluetoothAdapter == null || address == null) { 
      Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); 
      return false; 
     } 

     // Previously connected device. Try to reconnect. 
     if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) 
       && mBluetoothGatt != null) { 
      Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection."); 
      if (mBluetoothGatt.connect()) { 
       mConnectionState = STATE_CONNECTING; 
       return true; 
      } else { 
       return false; 
      } 
     } 

     final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); 
     if (device == null) { 
      Log.w(TAG, "Device not found. Unable to connect."); 
      return false; 
     } 
     // We want to directly connect to the device, so we are setting the autoConnect 
     // parameter to false. 

     //mBluetoothGatt = device.connectGatt(this, true, mGattCallback); 
     new Handler(getMainLooper()).post(new Runnable() { 
      @Override 
      public void run() { 
       if (device != null) { 
        mBluetoothGatt = device.connectGatt(getApplicationContext(), true, mGattCallback); 
       } 
      } 
     }); 
} 

이 내 로그 캣

10-27 23:19:37.284 13162-13162/com.example.blechat D/BluetoothGatt: close() 
10-27 23:19:37.284 13162-13162/com.example.blechat D/BluetoothGatt: unregisterApp() - mClientIf=6 
10-27 23:19:37.314 13162-13162/com.example.blechat D/BluetoothLeService: Trying to create a new connection. 
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: connect() - device: 00:02:5B:00:15:33, auto: true 
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: registerApp() 
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: registerApp() - UUID=23513bb1-c4fc-4203-ad3a-d58c38f2ddfb 
10-27 23:19:37.394 13162-13706/com.example.blechat D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6 
10-27 23:19:42.374 13162-13162/com.example.blechat D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 
10-27 23:19:48.994 13162-13162/com.example.blechat D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 
10-27 23:19:56.704 13162-13706/com.example.blechat D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=00:02:5B:00:15:33 

답변

-1

입니다 :

//Click button disconnect 
public void onClickDisconnect(View view) { 
    mBluetoothLeService.disconnect(); 
} 

은 그 때 나는 다음과 같이 나는 연결 함수를 호출, 다시 연결 , 장치로부터 서버가 연결 가능한 상태에 있음을 나타내는 광고 패킷을 기다립니다. 서버의 보급 간격에 따라 다소 시간이 걸릴 수 있습니다.

따라서 연결 및 재 연결 시간을 줄이는 방법은 일반적으로 BLE 장치의 광고 빈도를 높이는 것입니다. 그러나 이것은 또한 장치의 에너지 소비를 증가 시킨다는 것을 명심하십시오. 장치가 사용되지 않는 나머지 시간 동안 많은 에너지를 절약 할 수있는 경우 대부분의 경우 10-20 초 간격 (따라서 평균 재 연결 기간 5-10 초)이 허용됩니다.

단절된 직후 광고 간격을 훨씬 더 낮은 값으로 설정하여 일정 시간이 지난 후에 원래의 값으로 되돌릴 수있는 방식으로 장치를 구성 할 수 있습니다. 빠른 재 연결이 자주 사용되는 경우 이것이 길일 수 있습니다.

그러나 빠른 반응 시간이 필요한 경우 BLE가 가장 좋은 방법은 아니며 고전적인 블루투스를 선호 할 것입니다. Bluetooth Low Energy는 속도가 아닌 에너지 소비가 적도록 최적화되어 있습니다.

+0

감사합니다. 코드로 어떻게 수정할 수 있습니까? 이론뿐만 아니라 – Jame

+0

말하기 어렵습니다. 일반적으로 BLE 장치에서 수행됩니다. 어떤 장치를 사용하고 있습니까? 장치의 BLE API에는 "Set Advertising Parameters"또는 "Set Advertising Interval"또는 이와 유사한 기능이 있어야합니다. 그러나이 전화가 가능한지 의심 스럽습니다. – Nebr

관련 문제