The Last Will message in MQTT v5 functions the same way as that of last will v3.1.1 ,however the last Will messages has been expanded considerably from version 3.1.1.
In version 3.1.1 the last Will message contained:
- Topic and QOS
- payload
- Retain Flag
In MQTT v5 we have:
- Topic and QOS
- Payload
- Retain Flag
- Will delay Interval
- Payload Format Indicator -i.e binary or UTF-8
- Message Expiry Interval
- Content Type
- Response Topic
- Correlation Data
- User Property
Will Delay Interval
This is a 4 byte field with the interval in seconds and is 0 by default which means there is no delay in sending the last Will Message.
The field is meant to be used to cater for very temporary network failures.
Additional Properties 5-10
These are present because the message payload in MQTT v3.1.1 has been expanded in MQTT v5.
They serve the same purpose as those fields in a standard message payload and you can find more details of these fields in these tutorials:
- MQTT v 5.0 New Features Overview
- MQTTv5 Properties by Message Type
- Examining MQTTv5 User Properties
- MQTTv5 CONNECT and CONNACK Messages
- Understanding And Using MQTT v5 Request Response
Summary
Although the last will message in v5 contains more properties than v3.1.1 it functions the same way and the purpose is to provide state information for a connected client.
MQTT implementations like sparkplug also provide state information by using birth message.
You can find an example implementation in the tutorial Checking Active MQTT Client Connections
Related Tutorials and Resources
- MQTTv5 Clean Start (Clean Sessions) and Session Expiry
- Paho Python MQTT Client Changes for MQTTv5 Support
- MQTTv5 Properties by Message Type
- Understanding and Using MQTTv5 Shared Subscriptions and Topics
- Understanding MQTTv5 Topic Aliases