Fitbit / golden-gate

Framework to connect wearables and other IoT devices to mobile phones, tablets and PCs with an IP-based protocol stack over Bluetooth Low Energy
Other
299 stars 31 forks source link

Exception when using example Android App #37

Open nilstk opened 3 years ago

nilstk commented 3 years ago

Hi there!

We are getting an exception when using the example app for Android and Gatt/UDP/DTLS and CoAP. I was wondering if you have an hint for us on how to fix that. Is that some sort of device issue with missing values?

BitGattPeer$setupNotifications-[main] fail to subscribe notification...
java.lang.IllegalStateException: descriptor must not be null
    at com.fitbit.bluetooth.fbgatt.rx.client.BitGattPeer$writeDescriptorCharacteristic$1.call(BitGattPeer.kt:153)
    at com.fitbit.bluetooth.fbgatt.rx.client.BitGattPeer$writeDescriptorCharacteristic$1.call(BitGattPeer.kt:32)
    at io.reactivex.internal.operators.single.SingleDefer.subscribeActual(SingleDefer.java:36)
    at io.reactivex.Single.subscribe(Single.java:3603)
    at io.reactivex.internal.operators.single.SingleFlatMap$SingleFlatMapCallback.onSuccess(SingleFlatMap.java:84)
    at io.reactivex.internal.operators.single.SingleMap$MapSingleObserver.onSuccess(SingleMap.java:64)
    at io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:67)
    at com.fitbit.bluetooth.fbgatt.rx.GattTransactionExtKt$runTxReactive$1$1.onTransactionComplete(GattTransactionExt.kt:24)
    at com.fitbit.bluetooth.fbgatt.GattTransaction$1.onTransactionComplete(GattTransaction.java:373)
    at com.fitbit.bluetooth.fbgatt.GattTransaction.callCallbackWithTransactionResultAndRelease(GattTransaction.java:334)
    at com.fitbit.bluetooth.fbgatt.tx.SubscribeToCharacteristicNotificationsTransaction.lambda$transaction$0$SubscribeToCharacteristicNotificationsTransaction(SubscribeToCharacteristicNotificationsTransaction.java:100)
    at com.fitbit.bluetooth.fbgatt.tx.-$$Lambda$SubscribeToCharacteristicNotificationsTransaction$XxolJDFBYeyzUBs_rl-S9nO1zxw.run(Unknown Source:6)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7386)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
-java.lang.IllegalStateException: descriptor must not be null
barbibulle commented 3 years ago

Hi. Thanks for reporting this. We'll take a look shortly to see how that should be fixed.

nilstk commented 3 years ago

Any news on this issue @barbibulle ? It happens to me on all my devices (Samsung S7, S8, Google Pixel) and the CoAP message is displayed locally (sending device) only. I'd expected that it gets transmitted to the other (receiving) device. Nevertheless, in the logcat (of the receiving device) I can see some data gets transmitted (encrypted) ... it just never reaches the UI ... any idea where to look for an issue?

ShawnW858 commented 3 years ago

hello Nils, Could you share more info of your peripheral device? for the error exception, it seems like the golden gate android app was not able to subscribe the CCCD of Gattlink service on the peer device.

nilstk commented 3 years ago

@ShawnW858 Sure, please find attached the whole adb log of my central device (Pixel 3a) connected to a SPro88 that acts as peripheral.

Currently, there are two issues:

To me the above exception ("descriptor must not be null" and its following errors) appears to be sort of a racing condition and the descriptor and its service is found later on. Nevertheless, I cannot receive a coap message sent from the peripheral device to central and vice-versa. Taking a closer look at the lower layers and RxSource here, I see that data is received, but it is not forwarded to the UI for unknown reasons. Any idea about that issue? We tested it with several devices now (S7, S8 and Pixel).

Also, I was surprised to see two MAC addresses for the same device. For privacy reasons, I replaced all MAC address with fixed strings like PRIVATE-MAC-SPRO88 or PRIVATE-MAC-SPRO88-NO2 .

Thanks for any help :) !

Log_Pixel_asCentral_modified_mac.txt

ShawnW858 commented 3 years ago

I went through your log and it seems like the connection was set up successfully. StackPeer$getDtlsEventObservable-[main] StackPeer with key BluetoothAddressNodeKey(value=PRIVATE-MAC-S88PRO-NO2) Tls status changed to TLS_STATE_HANDSHAKE StackPeer$getDtlsEventObservable-[main] StackPeer with key BluetoothAddressNodeKey(value=PRIVATE-MAC-S88PRO-NO2) Tls status changed to TLS_STATE_SESSION StackPeer$connect-[main] StackPeer with key BluetoothAddressNodeKey(value=PRIVATE-MAC-S88PRO-NO2) connection has updated its status to CONNECTED You probably can debug further on the CoAP layer and try with a simple CoAP request and response. You could check if the filter mode of CoAP endpoint is set correctly. Also it's possible that it's a string parsing issue on the example app UI.

Thanks

nilstk commented 3 years ago

@ShawnW858 @barbibulle

Hi Shawn, is there an updated example app available maybe? I tried your provided example app with numerous devices (S7, S8, Pixel, ...) without success now. Sometimes, there is even no connection at all and the above exception along with the GattServiceNotFound exception persists.

If there is a connection between the devices (in my case SPRO88 as peripheral and Pixel as central), hitting the "send coap request over dtls" on the connected peripheral device, results in a received message on the lower layers only and and it has no effect on the UI at all (I'd assume a message like "Hello world!" in the UI of central). You may see it in the logs as RxSource received data.

Therefore, please find attached the log files and a screenshot of the app after I sent a coap message to central. Is this a device issue or version issue of Android maybe? Both devices have Android 10 at least. May I ask for which version you developed the Android app originally?

Central_Pixel_to_Perip_SPro88_defaultExampleAppLog.txt

Screenshot_ExampleApp_after_received_coap_message_20210729-120128

barbibulle commented 3 years ago

Hi Nils. Once you have a connection between your two phones (one in the Central role and the other in the Peripheral role), you should indeed be able to send a CoAP request from one to the other and the UI will show the response. I have tested with two phones running the test app built from the tip of the main branch and it works as expected. (I'm testing on two devices running Android 8.1, I'll try to find other devices with more recent versions to test with) Here's what it should look like: Screenshot_20210729-163039

Regarding the race condition you're mentioning, I'll take a look to see if I can find what could be at cause and if I can replicate it.

nilstk commented 3 years ago

@barbibulle any news on your testing? Can you confirm the issues with newer Android versions? Any ideas how to resolve it?