esprfid / esp-rfid

ESP8266 RFID (RC522, PN532, Wiegand, RDM6300) Access Control system featuring WebSocket, JSON, NTP Client, Javascript, SPIFFS
MIT License
1.36k stars 423 forks source link

MQTT LWT #286

Open cyberhasse opened 5 years ago

cyberhasse commented 5 years ago

Will you implement "LWT" Last will and testament mqtt feature? Thanks for your great work. Regards.

omersiar commented 5 years ago

125 #103

Identify all esp-rfids in the network by ChipID Give user an option to add their topic for LWT

cyberhasse commented 4 years ago

First of all: I'm no programmer but.. I have LWT success by adding:

    mqttClient.setCleanSession(true);
    mqttClient.setKeepAlive(15);
    mqttClient.setWill("/door/log/lwt", 1, false, "offline");

to config.esp and adding a function in mqtt.esp

void mqtt_publish_lwt(time_t heartbeat) { mqttClient.connect(); // More stable? String stopic (mqttTopic); stopic = stopic + "/lwt"; mqttClient.publish(stopic.c_str(), 0, false, ("online"));

and adding to main.cpp just below nextbeat = (unsigned)now() + interval;

mqtt_publish_lwt(now());

Problem now is that lwt message is hardcoded...

Regards.