locked
Android Application throwing exception : java.io.IOException: Could not open the connection RRS feed

  • Question

  • Hi 

    Whenever I m trying to connect to IOT hub from my android application , having following dependency .

    implementation("com.microsoft.azure.sdk.iot:iot-device-client:1.16.0") {
    exclude module: 'azure-storage'
    }
    implementation "com.microsoft.azure.android:azure-storage-android:2.0.0"
    implementation "org.apache.commons:commons-lang3:3.6"
    api "com.microsoft.azure.sdk.iot:iot-service-client:1.16.1"
    implementation 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'
    implementation 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'

    I m getting following exception : 


    Informations :
    java.io.IOException: Could not open the connection
    at com.microsoft.azure.sdk.iot.device.DeviceIO.open(DeviceIO.java:164)
    at com.microsoft.azure.sdk.iot.device.InternalClient.open(InternalClient.java:130)
    at com.microsoft.azure.sdk.iot.device.DeviceClient.open(DeviceClient.java:317)
    at com.tomra.mhs.hh.mobile.clientManager.DeviceClientManager.connectDeviceToIOTHub(DeviceClientManager.java:150)
    at com.tomra.mhs.hh.mobile.repository.DataRepository.connectToDevice(DataRepository.java:784)
    at com.tomra.mhs.hh.mobile.appmodules.splashscreen.SplashInteractor.connectToDevice(SplashInteractor.java:50)
    at com.tomra.mhs.hh.mobile.appmodules.splashscreen.SplashScrenViewModel.connectToDevice(SplashScrenViewModel.java:73)
    at com.tomra.mhs.hh.mobile.appmodules.splashscreen.SplashScreenActivity.lambda$connectToIotHub$0(SplashScreenActivity.java:94)
    at com.tomra.mhs.hh.mobile.appmodules.splashscreen.-$$Lambda$SplashScreenActivity$5jQzB_Om_vojPuEqYQ4KqUNIZVE.onDelayCompleted(Unknown Source:2)
    at com.tomra.mhs.hh.mobile.appmodules.CommonUI.BaseActivity$7.run(BaseActivity.java:482)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6518)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    Caused by: com.microsoft.azure.sdk.iot.device.exceptions.ProtocolException: Unable to subscribe to topic :devices/tnazeu-pd-mhs-device-101/messages/devicebound/#
    at com.microsoft.azure.sdk.iot.device.transport.mqtt.exceptions.PahoExceptionTranslator.convertToMqttException(PahoExceptionTranslator.java:75)
    at com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt.subscribe(Mqtt.java:286)
    at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging.start(MqttMessaging.java:61)
    at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection.open(MqttIotHubConnection.java:180)
    at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.openConnection(IotHubTransport.java:653)
    at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.open(IotHubTransport.java:280)
    at com.microsoft.azure.sdk.iot.device.DeviceIO.open(DeviceIO.java:160)
    ... 16 more
    Caused by: Timed out waiting for a response from the server (32000)
    at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:112)
    at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:67)
    at com.microsoft.azure.sdk.iot.device.transport.mqtt.Mqtt.subscribe(Mqtt.java:281)
    ... 21 more

    ****  End of current Report ***

    This is happening sometimes , not regularly , but I need to have the solution for this.

    So can anybody help me in this.

    Thanks,

    Rohit

    Tuesday, November 5, 2019 12:03 PM

All replies

  • Hi,

    Whenever I m using my android application which needs to be connected to Azure IOT hub for posting data, it gets connected initially ,  but after some time its disconnects and never able to connect back. Here is snap of connection status logs that I have logged.


    10-14-2019 12:51:12 : onIotConnectionStateChanged: IotConnection Disconnected and Retrying..

    10-14-2019 12:53:44 : onIotConnectionStateChanged: IotConnection Established

    10-14-2019 12:53:45 : onIotConnectionStateChanged: IotConnection Disconnected and Retrying..

    10-14-2019 12:53:46 : onIotConnectionStateChanged: IotConnection Established

    10-14-2019 12:53:46 : onIotConnectionStateChanged: IotConnection Disconnected and Retrying..

    10-14-2019 12:53:48 : onIotConnectionStateChanged: IotConnection Established

    10-14-2019 12:53:48 : onIotConnectionStateChanged: IotConnection Disconnected and Retrying..

    10-14-2019 12:53:49 : onIotConnectionStateChanged: IotConnection Established

    10-14-2019 12:53:50 : onIotConnectionStateChanged: IotConnection Disconnected and Retrying..

    ..............................

    These keeps on changing status until I killed the application and wait for like 30 seconds and restart again.

    So can anyone suggest how can we resolve this.

    Thanks

    Rohit

     

    Tuesday, November 5, 2019 11:46 AM
  • Hi Rohit,

    This error occurs when your device is trying to connect to your IoT Hub, but the connection attempt times out. It could be due to either bad network connectivity, or due to a load problem on your IoT Hub side.

    How consistently do you get this error? Check if you have a lot of other devices connecting to your hub at the same time.

    I would also suggest you, report this error by creating an issue under azure-iot-sdk-java repo for further help.

    Wednesday, November 6, 2019 7:18 AM
  • Here is the Git Issue created for reference: https://github.com/Azure/azure-iot-sdk-java/issues/624

    Wednesday, December 4, 2019 8:40 AM