Skip to content

Commit

Permalink
Sanitas SBF70/SBF75 (GATT_INSUF_AUTHORIZATION) bug fix (#441)
Browse files Browse the repository at this point in the history
set discovery/connect delay to one second and Bluetooth communication delay to 10ms
  • Loading branch information
oliexdev authored Mar 19, 2019
1 parent ce1ea8b commit f24fc35
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions android_app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha03'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
Expand All @@ -52,8 +52,8 @@ dependencies {
implementation 'com.j256.simplecsv:simplecsv:2.3'

// RxAndroidBle
implementation 'com.polidea.rxandroidble2:rxandroidble:1.7.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'com.polidea.rxandroidble2:rxandroidble:1.8.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.jakewharton.rx2:replaying-share:2.1.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private OpenScale(Context context) {
fragmentList = new ArrayList<>();
bleClient = RxBleClient.create(context);

RxBleClient.setLogLevel(RxBleLog.DEBUG);
RxBleClient.setLogLevel(RxBleLog.VERBOSE);
RxBleLog.setLogger((level, tag, msg) -> Timber.tag(tag).log(level, msg));

reopenDatabase(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.IOException;
import java.net.SocketException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import androidx.core.content.ContextCompat;
import io.reactivex.Observable;
Expand Down Expand Up @@ -69,6 +70,7 @@ public enum BT_STATUS {
protected Context context;

private final int BT_RETRY_TIMES_ON_ERROR = 3;
private final int BT_DELAY_MS = 10;

private RxBleClient bleClient;
private RxBleDevice bleDevice;
Expand Down Expand Up @@ -239,6 +241,7 @@ protected Observable<byte[]> writeBytes(UUID characteristic, byte[] bytes) {
.flatMapSingle(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristic, bytes))
.subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread())
.delay(BT_DELAY_MS, TimeUnit.MILLISECONDS)
.retry(BT_RETRY_TIMES_ON_ERROR);

compositeDisposable.add(observable.subscribe(
Expand Down Expand Up @@ -267,6 +270,7 @@ protected Single<byte[]> readBytes(UUID characteristic) {
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(characteristic))
.subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread())
.delay(BT_DELAY_MS, TimeUnit.MILLISECONDS)
.retry(BT_RETRY_TIMES_ON_ERROR);

compositeDisposable.add(observable
Expand Down Expand Up @@ -297,6 +301,7 @@ protected Observable<byte[]> setIndicationOn(UUID characteristic) {
.flatMap(indicationObservable -> indicationObservable)
.subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread())
.delay(BT_DELAY_MS, TimeUnit.MILLISECONDS)
.retry(BT_RETRY_TIMES_ON_ERROR);

compositeDisposable.add(observable.subscribe(
Expand Down Expand Up @@ -333,6 +338,7 @@ protected Observable<byte[]> setNotificationOn(UUID characteristic) {
.flatMap(notificationObservable -> notificationObservable)
.subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread())
.delay(BT_DELAY_MS, TimeUnit.MILLISECONDS)
.retry(BT_RETRY_TIMES_ON_ERROR);

compositeDisposable.add(observable.subscribe(
Expand All @@ -355,6 +361,7 @@ protected Observable<RxBleDeviceServices> discoverBluetoothServices() {
.flatMapSingle(RxBleConnection::discoverServices)
.subscribeOn(Schedulers.trampoline())
.observeOn(AndroidSchedulers.mainThread())
.delay(BT_DELAY_MS, TimeUnit.MILLISECONDS)
.retry(BT_RETRY_TIMES_ON_ERROR);

compositeDisposable.add(observable.subscribe(
Expand Down Expand Up @@ -520,7 +527,7 @@ public void run() {
resetDisconnectTimer();
}
}
}, 500);
}, 1000);
}

private void setBtMonitoringOn() {
Expand Down

0 comments on commit f24fc35

Please sign in to comment.