|
|
Re: MQTT Client has lost connection [message #1709758 is a reply to message #1709724] |
Wed, 30 September 2015 17:31 |
Edward Woodhouse Messages: 12 Registered: September 2015 |
Junior Member |
|
|
Thank you for the response. I have noted the connectionLost callback you mentionned.
I have implemented an android.net.conn.CONNECTIVITY_CHANGE broadcast receiver for
ConnectivityManager.TYPE_WIFI
ConnectivityManager.TYPE_MOBILE
Here i create a new connectAction whenever a WIFI or MOBILE signal comes online, with priority given to new WIFI networks.
It is fully functional and when I manually disable and enable either WIFI or MOBILE data myself, connection is regained properly.
However, I experience the "MQTT Client has lost connection" when I am solely using MOBILE data as I travel. I am curious if anyone knows what sort of MOBILE data event could be triggering this behaviour? (for example, changing network type? or something else detectable by a PhoneStateListener?).
[Updated on: Wed, 30 September 2015 17:32] Report message to a moderator
|
|
|
Re: MQTT Client has lost connection [message #1710118 is a reply to message #1709758] |
Sun, 04 October 2015 16:41 |
Edward Woodhouse Messages: 12 Registered: September 2015 |
Junior Member |
|
|
For anyone interested in making the MQTT service restablish itself correctly and without losing cleansession messages, here is what to do:
Copy the Android Service src directly into your project and remove any existing dependencies on it. Do not change the folder structure or it will not work. Test that the Android service you imported is being used.
For example by refactoring the service name successfully in the manifest <service android:name="org.eclipse.paho.android.service.MqttService2"></service>
Make MqttService public and MqttService.connections public static
Finally in MqttCallbackHandler's connectionLost() method add this snippit
for (MqttConnection client : MqttService.connections.values()) {
client.reconnect();
}
Hopefully it helps you
[Updated on: Sun, 04 October 2015 16:44] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02382 seconds