Hi, first of all thank you for your support.
I have implemented Mqtt in my Android application, and there is an bug/issue when it reconnects.
When devices looses internet connection, mqtt gets disconnected. It reconnects and resubscribe automatically, successfully in the major of the cases, but sometimes it doesn’t resubscribe itself.
I can’t reproduce it, I only saw it in the logs I print in the logcat after a user complaint about it.
To resolve the issue, I need one of the following options (or both):
- The ability to deactivate auto-subscription upon reconnection.
- The capability to print internal logs from the HiveMQ SDK in Android Studio’s logcat. This would allow me to gather more information and better understand the root cause.
Here is the code:
Configuration:
client = with(config) {
Mqtt3Client.builder()
.identifier(identifier)
.serverHost(host)
.serverPort(port)
.webSocketConfig(
MqttWebSocketConfig.builder()
.serverPath(path)
.queryString(query)
.build()
)
.simpleAuth(
Mqtt3SimpleAuth.builder()
.username(username)
.password(password.toByteArray())
.build()
)
.sslWithDefaultConfig()
.addConnectedListener {
onConnectedListener.onConnected()
}
.addDisconnectedListener {
handleDisconnect(it, onDisconnectedListener)
}
.buildRx()
}
}
Connection:
client.connectWith()
.run {
if (keepAliveSeconds != null) {
keepAlive(keepAliveSeconds)
} else {
noKeepAlive()
}
}
.cleanSession(true)
.applyConnect()
.await()
Reconnection:
val reconnector = context.reconnector
onDisconnectedListener.onDisconnected(reason, reconnector.attempts)
?.also { delaySeconds ->
if (delaySeconds > 0) {
reconnector.delay(delaySeconds.toLong(), TimeUnit.SECONDS)
}
reconnector.reconnect(true)
}
Thank you very much fro your help.