Giter Site home page Giter Site logo

vincentmasselis / rxbluetoothkotlin Goto Github PK

View Code? Open in Web Editor NEW
87.0 7.0 12.0 749 KB

Bluetooth low energy reactive framework for Android written in Kotlin

License: Other

Kotlin 100.00%
kotlin bluetooth-low-energy android rxjava3 rxjava rxjava-android bluetooth ble ble-api

rxbluetoothkotlin's Issues

Type mismatch: inferred type is Application but Boolean was expected

I got an issue in DeviceActivity of demoApp

.switchMapSingle { device.connectRxGatt(applicationContext as Application) }
Type mismatch: inferred type is Application but Boolean was expected

Also ScanActivty
.rxScan(this, flushEvery = 1L to TimeUnit.SECONDS)
Type mismatch: inferred type is ScanActivity but Pair<List, ScanSettings>? was expected

We have an exception when running demo-app from this repo.

\RxBluetoothKotlin-maven-central-migration\RxBluetoothKotlin-maven-central-migration\demo-app\app\src\main\java\com\vincentmasselis\demoapp\DeviceActivity.kt: (50, 14): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun Disposable.disposeOnState(exceptedState: ActivityState, activityToMonitor: Activity): Disposable defined in com.vincentmasselis.rxuikotlin
public fun Disposable.disposeOnState(exceptedState: FragmentState, fragmentToMonitor: Fragment): Disposable defined in com.vincentmasselis.rxuikotlin
public fun Disposable.disposeOnState(exceptedState: ViewHolderState, viewHolderToMonitor: LifecycleViewHolder): Disposable defined in com.vincentmasselis.rxuikotlin

Usage of `value class`

Some of the returned data cloud be transformed from data class to value class introduced in Kotlin 1.5, it will increase the global performance of the library when processing input and outputs of the android framework.

crash com.vincentmasselis.rxbluetoothkotlin.DescriptorNotFound

##Code:

connectDisposable = connectState.filter { it is RXBleManager.ConnectStates.Connecting }
            .switchMapSingle {
                (connectState.value as? RXBleManager.ConnectStates.Connecting)?.device?.connectRxGatt(true)
            }
            .switchMapMaybe {
                    gatt -> gatt.whenConnectionIsReady().map { gatt }
            }
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                { gatt->
                    Toast.makeText(this, "Connected !", Toast.LENGTH_SHORT).show()
                    connectState.onNext(RXBleManager.ConnectStates.Connected(gatt))
                    Maybe
                        .defer {
                            if (gatt.source.services.isEmpty()) gatt.discoverServices()
                            else Maybe.just(gatt.source.services)
                        }.subscribe { serviceList ->
                            for (service in serviceList)
                            {
                                for (characteristic in service.characteristics){

                                    if (containProperty(BluetoothGattCharacteristic.PROPERTY_NOTIFY,characteristic.properties)){
                                        if (characteristic.descriptors.isEmpty()){
                                            BuglyLog.i(tag,"no characteristic.descriptors")
                                            continue
                                        }
                                        gatt.enableNotification(characteristic)
                                            .flatMapPublisher {
                                                gatt.listenChanges(it)
                                            }
                                            .subscribe ({ byteArray ->
                                                //BuglyLog.d(tag,byteArray.toString())
                                            },{//cash here
                                                BuglyLog.e(tag,it.message)
                                                it.printStackTrace()
                                            })
                                    }
                                }
                            }
                        }
                },{
                    val message =
                        when (it) {
                            is BluetoothIsTurnedOff -> "Bluetooth is turned off"
                            is DeviceDisconnected -> "Unable to connect to the device"
                            else -> "Error occurred: $it"
                        }
                    AlertDialog.Builder(this).setMessage(message).show()
//                    bluetoothAdapter.disable()
//                    Handler().postDelayed(Runnable { bluetoothAdapter.enable() },500)
                }
            )

##Log

1 io.reactivex.exceptions.OnErrorNotImplementedException:The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | DescriptorNotFound(device=C7:E4:E3:E2:E1:FD, characteristicUUID=00010203-0405-0607-0809-0a0b0c0d2b17, descriptorUUID=00002902-0000-1000-8000-00805f9b34fb)
2 io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
3 ......
4 Caused by:
5 com.vincentmasselis.rxbluetoothkotlin.DescriptorNotFound:
6 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$3.apply(RxBluetoothGattImpl.kt:517)
7 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$3.apply(RxBluetoothGattImpl.kt:28)
8 io.reactivex.internal.operators.maybe.MaybeFlatten$FlatMapMaybeObserver.onSuccess(MaybeFlatten.java:88)
9 io.reactivex.internal.operators.observable.ObservableElementAtMaybe$ElementAtObserver.onNext(ObservableElementAtMaybe.java:82)
10 io.reactivex.internal.operators.observable.ObservableOnErrorNext$OnErrorNextObserver.onNext(ObservableOnErrorNext.java:68)
11 io.reactivex.internal.operators.observable.ObservableFlatMapSingle$FlatMapSingleObserver.innerSuccess(ObservableFlatMapSingle.java:151)
12 io.reactivex.internal.operators.observable.ObservableFlatMapSingle$FlatMapSingleObserver$InnerObserver.onSuccess(ObservableFlatMapSingle.java:284)
13 io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:67)
14 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$enqueue$1$1$singleToEnqueue$1.accept(RxBluetoothGattImpl.kt:203)
15 io.reactivex.internal.operators.single.SingleDoOnSuccess$DoOnSuccess.onSuccess(SingleDoOnSuccess.java:54)
16 io.reactivex.internal.operators.single.SingleTimeout$TimeoutMainObserver.onSuccess(SingleTimeout.java:141)
17 io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.onSuccess(SingleSubscribeOn.java:68)
18 io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:67)
19 com.vincentmasselis.rxbluetoothkotlin.RxBluetoothGattImpl$rxChangeNotification$1.subscribe(RxBluetoothGattImpl.kt:511)
20 io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
21 io.reactivex.Single.subscribe(Single.java:3603)
22 io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
23 io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124)
24 android.os.Handler.handleCallback(Handler.java:808)
25 android.os.Handler.dispatchMessage(Handler.java:101)
26 android.os.Looper.loop(Looper.java:166)
27 android.app.ActivityThread.main(ActivityThread.java:7529)
28 java.lang.reflect.Method.invoke(Native Method)
29 com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
30 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

ๅ›พ็‰‡

Missing LICENSE

I know it is listed as TODO but in order to be used, a library needs a license file / description.
Please add one to your project (in the README or even better, in a specific LICENSE file)

BLE Enable notifications and read characteristic notification (listen change)

Hi

I'm trying to establish BLE communication with an esp32. I succeed to do it in java but I'm trying to do it in Kotlin now. I run the demo app but it seems the Notifications are not used in the example. However I found a file named "ListenChangeTest.kt" I think the solution is in this file but I don't understand it. Can you explain how to use notifications in your example please ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.