지난 6 개월 동안 BLE 응용 프로그램을 작성했습니다. 최근 프로젝트에서 사용자 지정 BLE 장치를 통합하려고하며 데이터를 읽는 동안 동기화 문제가 발생합니다. "onCharacteristicRead"는 항상 133 오류 코드를 반환합니다. 전체 시나리오를 살펴보고 누군가가 해결책을 찾으면 저를 도우십시오.Android BLE 데이터 문제 쓰기 - 가져 오기 오류 133
시나리오 사용자 지정 BLE 장치에는 세 가지 서비스가 있습니다.
비상
캐치
배터리 잔량
내가 내 응용 프로그램에서 두 서비스를 필요로하는 모든. 배터리 및 비상 사태. 처음에, 나는
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);
}
}
나는 똑같은 문제에 직면하고 난 너무 지연을 사용 ...하지만 콜백은 거리가 더 때 500ms 이상 걸릴 수 있기 때문에 좋은 해결책이 아니에요. 가장 좋은 해결책은 읽기/쓰기 콜백에 의존하는 것입니다. –
읽기 - 쓰기 콜백 (onCharacteristicRead() 및 onCharacteristicWrite())을 잡으려고합니다. 하지만 여기서 문제는 지연없이 읽기 - 쓰기 콜백에서 GATT 오류가 발생한다는 것입니다. 나는이 문제에 대한 해결책이 없다고 생각한다. – Nithinjith
여러 값을 쓰거나 여러 값을 읽으면이 오류가 발생합니까? 그렇다면, 나는 이것을위한 해결책을 가지고있다. –