Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

Saying goodbye with a Will

Our final MQTT feature for exploration is known as a Will. A client (publisher or subscriber) can register a special Will message with the broker so that if the client dies and disconnects from the broker abruptly (for example, it loses its network connection or its batteries go flat), the broker on the clients' behalf will send out the Will message notifying subscribers of the device's demise.

Wills are just a message and topic combination similar to what we have been using previously. 

Let's see Wills in action, and for this, we're going to need three Terminals:

  1. Open a Terminal and start a subscriber with the following command:
# Terminal #1 (Subscriber with Will)
$ mosquitto_sub -h localhost -t 'pyiot' --will-topic 'pyiot' --will-payload 'Good Bye' --will-qos 2 --will-retain

The new options are as follows:

    • --will-payload: This is the Will message.
    • --will-topic: This is the topic the Will...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461