PunchThrough/bean-sdk-android

SerialMessageReceived no longer working after Bean firmware update and 2.1.1 SDK update

Opened this issue · 12 comments

Can you help with the following issue?

I am getting the following errors in the Android Monitor:

Unhandled exception in callback
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.BluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)' on a null object reference
at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:181)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:70)
at android.os.Binder.execTransact(Binder.java:565)

Profile NOT Discovered: GattSerialXportProfile
Profile NOT Discovered: DeviceProfile
Profile NOT Discovered: BatteryProfile
Profile NOT Discovered: ScratchProfile
Profile NOT Discovered: OADProfile

Is this something that is happening repeatedly or just seen once? Either way, could you please make sure to power cycle the Bean and also restart your phones Bluetooth via the settings? After a Bean goes through a firmware update the GATT table handles may have changed and Android often caches these handles which results in errors.

Yes, this is happening repeatedly. My app was working fine before the uodates. Now, even going back to SDK 1.0.3, does not work.

I am pretty sure it is not the device because the Bean Loader virtual serial port sends the incoming data to the Arduino serial Monitor as expected. The issue seems to be in Android.

I'd really like to know the firmware version that the Bean reports. Do you have access to an iPhone so you could use LightBlue Explorer app to read the firmware version? Otherwise you could write a very isolated Android test that just reads the firmware version.

Also, another thing to try is download the latest Bean Loader application from the Android store and attempt connecting/uploading a sketch. The app will force your Bean firmware to the latest available.

The firmware is 201606030000 img-B

I am using Bean Loader on a Mac and it appears I have the latest available version.

@swstack Was the firmware information helpful?

Yes it's helpful, at least we know that it is running the latest firmware. Could you send me the entire android monitor log (from a fresh run) ... it will give me some intuition as to what your code is doing. Also, if you are comfortable sending me your code, i don't mind taking a look.

SerialMessageReceived Android Monitor log.txt

Here is the log. Is there an e-mail where I can send you code snippets? Thanks,

Ok. I sent you the main activity file with relevant code snippets. Thanks again.

@swstack Was the Android code snippet helpful in getting to root cause?

Hello @MMIX2009 ,

After looking at your logs and code snippets, the issue is not abundantly clear. I copied your code snippet into my local environment and was able to run it and connect to beans of my choosing.

However, one thing that I have noticed is that BeanDiscoveryListener.onBeanDiscovered() will be called many times for the same Bean while scanning is enabled. Do not attempt to connect to the same Bean object more than once! Once you find the Bean you are looking for, call .connect() on it and ignore any further discoveries of that Bean.

Let me know if this makes sense, or helps your issue.

@swstack Thanks for following up. Connecting to the Bean was not an issue for me either. I will make the code change to ensure the device is connected only once. It still looks like there is another issue because that part of the code was the same and worked before upgrading the Bean firmware.

Could it be some changes in Android related on how permission are required? Does the Bean SDK require setting permissions for location in the manifest?