Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException during connection #41

Open
RoProducts opened this issue Apr 9, 2018 · 3 comments
Open

IllegalStateException during connection #41

RoProducts opened this issue Apr 9, 2018 · 3 comments

Comments

@RoProducts
Copy link

RoProducts commented Apr 9, 2018

Hi,

I'm using neatle to connect one or more BLE cycling sensors in an Android app. These are long lasting connections and I'm setting the keepAlive flag in a ConnectionMonitor.
Occasionally, after some time I'm getting the following exception during the connection :

java.lang.IllegalStateException at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) at java.lang.reflect.Method.invoke(Method.java:372) at java.lang.reflect.Method.invoke(Native Method) at android.app.ActivityThread.main(ActivityThread.java:5254) at android.os.Looper.loop(Looper.java:135) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Handler.handleCallback(Handler.java:739) at si.inova.neatle.Device$6.run(Device.java:480) at si.inova.neatle.operation.CharacteristicSubscriptionImpl$1.onConnectionStateChanged(CharacteristicSubscriptionImpl.java:56) at si.inova.neatle.operation.CharacteristicSubscriptionImpl.access$000(CharacteristicSubscriptionImpl.java:39) at si.inova.neatle.operation.CharacteristicSubscriptionImpl.subscribeOnDevice(CharacteristicSubscriptionImpl.java:130) at si.inova.neatle.operation.OperationImpl.execute(OperationImpl.java:97) at si.inova.neatle.Device.execute(Device.java:220) at si.inova.neatle.Device.connect(Device.java:388)

I'm doing the following to connect a device (here for a csc sensor) :

  final BluetoothDevice device = Neatle.getDevice(macAddress));
  final CharacteristicSubscription cscSubscription = Neatle.createSubscription(context, device, Bluetooth.CSC_SERVICE, Bluetooth.CSC_MEASUREMENT_CHARACTERISTIC);
  cscSubscription.setOnCharacteristicsChangedListener(sensorDataHandler.getBLEListener());
  cscSubscription.start();

  final ConnectionMonitor monitor = Neatle.createConnectionMonitor(context, btDevice);
        monitor.setOnConnectionStateListener(new ConnectionStateListener() {
            @Override
            public void onConnectionStateChanged(Connection connection, int newState) {

                switch (newState){
                    case BluetoothAdapter.STATE_DISCONNECTED:
                        log("sensor "+ sensorName + " disconnected");
                        break;
                    case BluetoothAdapter.STATE_CONNECTING:
                        log("sensor "+ sensorName + " connecting");
                        break;
                    case BluetoothAdapter.STATE_CONNECTED:
                        log("sensor "+ sensorName + " connected");
                        break;
                    case BluetoothAdapter.STATE_DISCONNECTING:
                        log("sensor "+ sensorName + " disconnecting");
                        break;
                }
            }
        });
   monitor.setKeepAlive(true);
   monitor.start();`

What am I doing wrong here ? Can you help me ?

Thank you

Robert

@tomazs
Copy link
Contributor

tomazs commented Apr 10, 2018

Is your application running in the background?

@RoProducts
Copy link
Author

This is done in an Android service, which runs on the UI thread.

@RoProducts
Copy link
Author

I changed the order of the api calls. I do now connect first and subscribe then. The crash did not reappear this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants