How to stop receiving LWT retained message?

2.1k views Asked by At

For testing, I have created a client with clean sessin = false and setWill(WILL_TOPIC, WILL_MSG.getBytes(), 1, true); and ran the App. Later, i set setWill(WILL_TOPIC, WILL_MSG.getBytes(), 1, false); when i run the App, i receive the previously reatined LWT messages. How to stop receiving them?

2

There are 2 answers

2
Amrmsmb On

You could send a CONNECT message with “CleanSession=false” and “Will=true”, and sends an empty WILLTOPIC message

check this section 6.3

2
ralight On

You aren't receiving LWT messages as such, but a retained message. To clear a retained message, send a zero length retained message to the same topic. For example, with the Paho Python client you would do:

client.publish(WILL_TOPIC, payload=None, retain=True)