Open rafaelekol opened 7 years ago
I removed DisconnectedBufferOptions
and faulty devices seems to connect and disconnect fine now.
Looks like your application did not have permission within Android to read/write to the sdcard. You might need to change your application manifest file.
Something like <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I already have that permission in Manifest.
Even though I disabled DisconnectedBufferOptions
I still get exception on HTC device, whenever I change WiFi connection, I get this exception.
The big issue is that, after that moment I can't connect to socket anymore, since client.connect() is always throwing this error afterwards.
I observe this error on this device:
HTC Desire 310 with Android JellyBean 4.2.2
onFailure:
MqttException (0)
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.restoreBackups(MqttDefaultFilePersistence.java:276)
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:126)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:391)
at org.eclipse.paho.android.service.MqttConnection.connect(MqttConnection.java:289)
at org.eclipse.paho.android.service.MqttService.connect(MqttService.java:329)
at org.eclipse.paho.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:467)
at org.eclipse.paho.android.service.MqttAndroidClient.access$200(MqttAndroidClient.java:76)
at org.eclipse.paho.android.service.MqttAndroidClient$1.run(MqttAndroidClient.java:435)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
I got the same situation as refaeleko, some devices are working correctly, but the device "Lenovo YT3-X90F" with 5.1
First connection :
W/ContextImpl: Failed to ensure directory: /storage/sdcard1/Android/data/com.sample.app/files/MqttConnection
D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.cht_ffdYOGA5DCE9841_MainClient
D/AlarmPingSender: Schedule next alarm at 1493976855031
D/AlarmPingSender: Alarm scheule using setExact, delay: 10000
E/Connection: cht_ffdYOGA5DCE9841_MainClient connection complete, isReconnect = false
After few seconds, connection lost and auto reconnect:
D/AlarmPingSender: Sending Ping at:1493977577617
D/AlarmPingSender: Schedule next alarm at 1493977577852
D/AlarmPingSender: Alarm scheule using setExact, delay: 231
D/AlarmPingSender: Unregister alarmreceiver to MqttServicecht_ffdYOGA5DCE9841_MainClient
D/AlarmPingSender: Schedule next alarm at 1493977582708
D/AlarmPingSender: Alarm scheule using setExact, delay: 100
E/Connection: cht_ffdYOGA5DCE9841_MainClient connection lost, throwable = 連線遺失 (32109) - java.io.EOFException
D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.cht_ffdYOGA5DCE9841_MainClient
D/AlarmPingSender: Schedule next alarm at 1493977594199
D/AlarmPingSender: Alarm scheule using setExact, delay: 10000
E/Connection: cht_ffdYOGA5DCE9841_MainClient connection complete, isReconnect = true
D/AlarmPingSender: Sending Ping at:1493977594201
D/AlarmPingSender: Schedule next alarm at 1493977604204
D/AlarmPingSender: Alarm scheule using setExact, delay: 10000
D/AlarmPingSender: Success. Release lock(MqttService.client.cht_ffdYOGA5DCE9841_MainClient):1493977594415
Here is my disconnect code :
@override
public void onPause() {
if (status == CONNECTED || status == CONNECTING) {
try {
client.disconnect();
setStatus(LEAVE);
} catch (MqttException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
Disconnect :
D/AlarmPingSender: Success. Release lock(MqttService.client.cht_ffdYOGA5DCE9841_MainClient):1493977605601
D/AlarmPingSender: Unregister alarmreceiver to MqttServicecht_ffdYOGA5DCE9841_MainClient
E/Connection: cht_ffdYOGA5DCE9841_MainClient connection lost, throwable = null
Connect again when resume :
W/ContextImpl: Failed to ensure directory: /storage/sdcard1/Android/data/com.sample.app/files/MqttConnection
E/ActionListener: Connect to mqtt server failure, MqttException (0)
My connection options:
mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setUserName(userName);
mqttConnectOptions.setPassword(mqttPassword);
mqttConnectOptions.setConnectionTimeout(30);
mqttConnectOptions.setKeepAliveInterval(10);
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setCleanSession(false);
Current library:
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
Also i already have the "android.permission.WRITE_EXTERNAL_STORAGE" in Manifest. Thanks.
who know the answer,i have the same problem.
I find the answer: MqttDefaultFilePersistence filePersistence = new MqttDefaultFilePersistence(getDir("mqtt", MODE_PRIVATE).getAbsolutePath()); MqttAndroidClient mqttAndroidClient = new MqttAndroidClient(getApplicationContext(), MQTT_BROKER_HOST, clientId,filePersistence);
when in Android ,we should pass our own filePersistence in.The exactly answer still don,t know
Another option is to use memory persistence (if you can allow for messages to be lost when the app is killed):
mqttAndroidClient = new MqttAndroidClient(context, serverUri, clientId,
new MemoryPersistence(), MqttAndroidClient.Ack.AUTO_ACK);
HI . I am using this type url mqtt://mqtt.go.th:1883 but with this i can't get make connection between my android app and mqtt server. But when i am trying it with this tcp://mqtt.go.th:1883 it make connection . what happened with mqtt:// ? I need this type url connection. please give me solution . Thank you.
I am using MQTT to get and publish messages to Server. On most phones MQTT connect and disconnect is working, but on Phone:
LG LFino with Android Kitkat 4.4.2, and HTC Desire 310 with Android JellyBean 4.2.2
I got exception when I try to immediately connect after disconnect.I use MqttAndroidClient in my local service. Here is my code.
Log:
After more testing found out that phones where I can see this Exception in common has low available memory (About 200MB free memory).