mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
add lwt to connect
This commit is contained in:
parent
44923910ea
commit
ce6537f2a9
1 changed files with 19 additions and 0 deletions
|
@ -269,6 +269,24 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
|
|||
}
|
||||
}
|
||||
|
||||
// Last Will and Testimate is the way I can get the server notified of a
|
||||
// closed connection.
|
||||
private void addLWTIf( MqttConnectOptions mqttConnectOptions )
|
||||
{
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
try {
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put( "devid", mDevID );
|
||||
payload.put( "ts", Utils.getCurSeconds() );
|
||||
mqttConnectOptions.setWill( "xw4/device/LWT", payload.toString().getBytes(), 2, false );
|
||||
|
||||
// mqttConnectOptions.setKeepAliveInterval( 15 ); // seconds; for testing
|
||||
} catch ( JSONException je ) {
|
||||
Log.e( TAG, "addLWTIf() ex: %s", je );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setup()
|
||||
{
|
||||
Log.d( TAG, "setup()" );
|
||||
|
@ -277,6 +295,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
|
|||
mqttConnectOptions.setCleanSession(false);
|
||||
mqttConnectOptions.setUserName("xwuser");
|
||||
mqttConnectOptions.setPassword("xw4r0cks".toCharArray());
|
||||
addLWTIf( mqttConnectOptions );
|
||||
|
||||
try {
|
||||
setState( State.CONNECTING );
|
||||
|
|
Loading…
Reference in a new issue