0

i have he following LWT topic and WT message

private final String WILL_TOPIC = "sensor_0_LWT";
private final String WILL_MSG = "LWT: Unexpected Connection Drop Down";

And i am subscribed to a topic named sensor_0 when I publish a message I receive it, but when I urn the WiFi off and turn it on again I expect o see the LWT messahe I set in the connection options, but what happens is that i do not receive it.

why i do not receive the LWT message when I reconnect?

Code:

final MqttClientPersistence persistenceDataDir = new   
MqttDefaultFilePersistence(folder.toString());

    final MqttAndroidClient client_1 = new MqttAndroidClient(getApplicationContext(), serverURI,   
    clientID, persistenceDataDir, Ack.AUTO_ACK);

    MqttConnectOptions opts = new MqttConnectOptions();
    opts.setCleanSession(false);
    opts.setWill(WILL_TOPIC, WILL_MSG.getBytes(), 1, true);
    opts.setKeepAliveInterval(keepAliveInterval);
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Are you sure the broker detected that you disconnected? – ralight Nov 17 '14 at 10:08
  • @ralight yes, the asynchronous callback dispayed "connection lost" twice. but what happened after I posted the question is,i tried many time to connect and disconnect fro the broker, and at one time, i found that the WT message shows up twice after reconnect? any logical explanation for that? – Amrmsmb Nov 17 '14 at 10:20
  • The broker asynchronous callback or the client callback? It is the broker that needs to notice the client has disconnected, not the other way round. The will message appearing twice - you're connecting with clean session set to false, so messages should be queued up for you. If you disconnected before the broker could deliver the message, then reconnected and resubscribed you would receive the first queued message then a second message due to the resubscribe. – ralight Nov 17 '14 at 10:39
  • i think it is the broker asynchronous callback, because the client callback is synchronous. or my understanding is wrong? – Amrmsmb Nov 17 '14 at 10:42
  • @ralight ne more question please. is the LWT topic should be different than the opic to which i am subscribig or it does not matter.?regards – Amrmsmb Nov 17 '14 at 10:45
  • That depends entirely whether you want to receive the LWT or not! – ralight Nov 17 '14 at 10:47
  • @ralight so if i want to ke receiving LWT messages i should make the LWT topic as same as the topic to which i am subscribing? – Amrmsmb Nov 17 '14 at 10:52

0 Answers0