I'm using an ESP8266 as an IOT device, with MQTT to send status messages.
Each device have its own availability topic, to state its online
or offline
state ( needed for Home Assistant
indication on web GUI )
Since multiple devices are present- I was wondering if a lastwill status can be sent for a joint topic to be monitored ( for example :"device_id:offline
" )
my relevant part of the code defining a lastwill for devices topic is : mqttClient.connect(deviceName, user, passw, availTopic, 0, true, "offline")
EDIT1:
using PubSubClient.h
1 Answer 1
The "Last Will & Testament" facility of MQTT is controlled by the server, not the client.
The topic and payload are specified when the client connects as part of the connection handshaking. When the client disconnects this stored information is published automatically by the server.
The specification only allows for one topic and payload to be set.
Of course, you can specify the same topic for many clients and give each one its own distinct payload, but you can't also have a unique topic for each client at the same time.
This is according to the specification - however that doesn't stop a broker implementing its own extensions to the specification to allow such things - but I know of no such extensions being implemented. But, given the open-source nature of many MQTT implementations (PubSubClient.h and Mosquitto, for example), there is no reason you couldn't extend the protocol to implement your own requirements (at the cost of compatibility with other systems of course).
offline
notification from all 10 devices ( a topic that will be saved as a log file ).