2017-12-20 18 views
1

지난 6 개월 동안 BLE 응용 프로그램을 작성했습니다. 최근 프로젝트에서 사용자 지정 BLE 장치를 통합하려고하며 데이터를 읽는 동안 동기화 문제가 발생합니다. "onCharacteristicRead"는 항상 133 오류 코드를 반환합니다. 전체 시나리오를 살펴보고 누군가가 해결책을 찾으면 저를 도우십시오.Android BLE 데이터 문제 쓰기 - 가져 오기 오류 133

시나리오 사용자 지정 BLE 장치에는 세 가지 서비스가 있습니다.

  1. 비상

  2. 캐치

  3. 배터리 잔량

내가 내 응용 프로그램에서 두 서비스를 필요로하는 모든. 배터리 및 비상 사태. 처음에, 나는

private void scan() { 
     if (isLollyPopOrAbove()) {// Start Scanning For Lollipop devices 
      mBluetoothAdapter.getBluetoothLeScanner().startScan(scanFilters(), scanSettings(), scanCallback); // Start BLE device Scanning in a separate thread 
     } else { 
      mBluetoothAdapter.startLeScan(mLeScanCallback); // Start Scanning for Below Lollipop device 
     } 
    } 




    private List<ScanFilter> scanFilters() { 
     String emergencyUDID = "3C02E2A5-BB87-4BE0-ADA5-526EF4C14AAA"; 
     ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(emergencyUDID)).build(); 
     List<ScanFilter> list = new ArrayList<ScanFilter>(1); 
     list.add(filter); 
     return list; 
    } 



    private ScanSettings scanSettings() { 
     ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build(); 
     return settings; 
    } 

이 잘 작동하고 내가 검사 결과를 얻고, 아래의 코드를 사용하여 장치를 스캔 나는 장치에 연결할 수 있습니다. 연결이 설정되면, 나는 제공된 UUID의를 사용하여 사용 가능한 MLDP 서비스를 찾을 수

mBluetoothGatt.discoverServices(); 

그럼 난 여기에서 서비스 검색을 완료 콜백

@Override 
     public void onServicesDiscovered(BluetoothGatt gatt, int status) {    //BLE service discovery complete 
      if (status == BluetoothGatt.GATT_SUCCESS) {         //See if the service discovery was successful 
       Log.i(TAG, "**ACTION_SERVICE_DISCOVERED**" + status); 
       broadcastUpdate(BLEConstants.ACTION_GATT_SERVICES_DISCOVERED);      //Go broadcast an intent to say we have discovered services 
      } else {                  //Service discovery failed so log a warning 
       Log.i(TAG, "onServicesDiscovered received: " + status); 
      } 
     } 

을 얻고있다 GattCallBack

에서 아래 전화를 할 것입니다. 이것은 또한 잘 작동합니다.

하지만 오류 코드가

@Override 
     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { //A request to Read has completed 
      //String value = characteristic.getStringValue(0); 
      //int value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 0); 
//   if(characteristic.getUuid().e) 
       if (status == BluetoothGatt.GATT_SUCCESS) { 
        //See if the read was successful 
        Log.i(TAG, "**ACTION_DATA_READ**" + characteristic); 
        broadcastUpdate(BLEConstants.ACTION_DATA_AVAILABLE, characteristic);     //Go broadcast an intent with the characteristic data 
       } else { 
        Log.i(TAG, "ACTION_DATA_READ: Error" + status); 
       } 


     } 

답변

1

마지막으로 133 오류를 처리 할 수있는 해결책을 발견했습니다. 심층 분석 동안 BLE 요청 응답 프로세스에 약간의 지연이 있음을 발견했습니다. 그래서 각 읽기 및 쓰기에 500 밀리 초의 지연 시간을 걸었습니다. 이제 완벽하게 작동합니다. 나는 다양한 장치와 그 동작에 대해 테스트 해왔다. 해결 방법이 있는지 나는 모른다. 그러나 이것은 유사한 문제에 직면 한 개발자에게 도움이 될 수 있습니다.

+0

나는 똑같은 문제에 직면하고 난 너무 지연을 사용 ...하지만 콜백은 거리가 더 때 500ms 이상 걸릴 수 있기 때문에 좋은 해결책이 아니에요. 가장 좋은 해결책은 읽기/쓰기 콜백에 의존하는 것입니다. –

+0

읽기 - 쓰기 콜백 (onCharacteristicRead() 및 onCharacteristicWrite())을 잡으려고합니다. 하지만 여기서 문제는 지연없이 읽기 - 쓰기 콜백에서 GATT 오류가 발생한다는 것입니다. 나는이 문제에 대한 해결책이 없다고 생각한다. – Nithinjith

+0

여러 값을 쓰거나 여러 값을 읽으면이 오류가 발생합니까? 그렇다면, 나는 이것을위한 해결책을 가지고있다. –

1

(133)로,

public void readCharacteristic(BluetoothGattCharacteristic characteristic) { 
     if (mBluetoothAdapter == null || mBluetoothGatt == null) {      //Check that we have access to a Bluetooth radio 
      return; 
     } 
     boolean status = mBluetoothGatt.readCharacteristic(characteristic);        //Request the BluetoothGatt to Read the characteristic 
     Log.i(TAG, "READ STATUS " + status); 
    } 

는 응답 상태가 진정한지고 있지만 "onCharacteristicRead"콜백은 항상 받고 특성을 읽을 때 : (133) GATT__ERROR를 표시하고, 기기를 사용하지 않을입니다 범위. 읽기 이벤트 중에 버그가있을 수 있습니다. 먼저 기기 측에서 확인하시기 바랍니다.

1 개 :이 장치는 연결을 위해 본딩이 필요합니까?

+0

예, 본딩도 추가했습니다. 이제 그 반응이 나타납니다. 하지만 여전히 임의로 던지고 133. – Nithinjith