Moderators: grovkillen, Stuntteam, TD-er
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#1
Post
by timsson » 04 Apr 2016, 09:51
Hi,
is somethink like that possible?
Code: Select all
#define MQTT_TOPIC_LAST_WILL "/ESP_02/lwt"
mqttClient.connect("ESP_02", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
-
chrille
- Normal user
- Posts: 88
- Joined: 26 Aug 2015, 15:11
- Location: Horsens, Denmark
#2
Post
by chrille » 04 Apr 2016, 14:37
timsson wrote:Hi,
is somethink like that possible?
Code: Select all
#define MQTT_TOPIC_LAST_WILL "/ESP_02/lwt"
mqttClient.connect("ESP_02", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
I support this! LWT support for MQTT would be great - however I think some kind of integration with the UI is preferred. Maybe just a checkbox under MQTT settings, or under advanced settings
- Jan
Jan Chrillesen, Denmark
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#3
Post
by timsson » 10 Apr 2016, 10:53
Unfortunately, me is as noob the implementation not possible, but i can wait in this great project!
Thanks alot
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#4
Post
by timsson » 17 Apr 2016, 12:56
Hi,
can you explain the Command.ino with connect?
Maybe we can use lwt???
??On System#Boot do
connect("ESP_02", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
publish(MQTT_TOPIC_LAST_WILL, "connected", true);
??
Thanks
P.S.
Thx for this, it works great!
On <event> do
publish /ESP_01/gpio/2 0
endon
-
tozett
- Normal user
- Posts: 734
- Joined: 22 Dec 2015, 15:46
- Location: Germany
#5
Post
by tozett » 19 Apr 2016, 12:34
What is your usage of this?
Would be interested in an example.
Thanks for that, if you could provvide one...
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#6
Post
by timsson » 28 Apr 2016, 15:21
Hello tozett,
i use it to check the status in openhab/mqtt. If the battery or the wifi are down, lastwill change to "disconnectet"
For me is this a good and fast indicator...
Code: Select all
openhab item:
String ESP_04kalive "keep alive_4: [%s]" {mqtt="<[localbroker:/ESP_04/lwt:state:default]"}
Thx!

- keepalive.jpg (44.67 KiB) Viewed 20199 times
-
tozett
- Normal user
- Posts: 734
- Joined: 22 Dec 2015, 15:46
- Location: Germany
#7
Post
by tozett » 29 Apr 2016, 13:20
Ah, ok. thanks for supplying me this info.
i am on r105, did you implement the LWT with rules? could you post your working example?
i read
on the net some background,
The Last Will and Testament (LWT) feature is used in MQTT to notify other clients about an ungracefully disconnected client. Each client can specify its last will message (a normal MQTT message with topic, retained flag, QoS and payload) when connecting to a broker. The broker will store the message until it detects that the client has disconnected ungracefully. If the client disconnect abruptly, the broker sends the message to all subscribed clients on the topic, which was specified in the last will message. The stored LWT message will be discarded if a client disconnects gracefully by sending a DISCONNECT message.
and i will take over this function to my system. fantastic state info of the ESPs,
thanks
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#8
Post
by timsson » 29 Apr 2016, 18:04
tozett wrote:i am on r105, did you implement the LWT with rules? could you post your working example?
I use also r105, fantastic projekt! but for lwt i take my one ino file with exactly this syntax and it works fine:
Code: Select all
#define MQTT_TOPIC_LAST_WILL "/ESP_02/lwt"
mqttClient.connect("ESP_02", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
or do you need the complete ino?
and i use this library:
PubSubClient by Nick O'Leary Version 2.6.0 mqtt3.1.1
Last edited by
timsson on 29 Apr 2016, 18:55, edited 2 times in total.
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#10
Post
by timsson » 29 Apr 2016, 18:33
tozett wrote:so it is/could be feature-request for r106 ...?
sorry, yes - i send you a pm
-
tozett
- Normal user
- Posts: 734
- Joined: 22 Dec 2015, 15:46
- Location: Germany
#11
Post
by tozett » 30 Apr 2016, 08:28
thanks,
but i thought martinus will maybe reads this,
and will implement this in the gui.
configurable last-will-message ...
--i put this on the feature-request list ... and let us be suprised with r106 ..

-
JR01
- Normal user
- Posts: 260
- Joined: 14 Feb 2016, 21:04
- Location: South Africa
#12
Post
by JR01 » 09 May 2016, 17:46
Would like to use LWT as well, +1+1 here
-
lucaberta
- Normal user
- Posts: 59
- Joined: 09 May 2016, 11:26
- Location: Lausanne, Switzerland
-
Contact:
#13
Post
by lucaberta » 09 May 2016, 18:20
timsson wrote:
or do you need the complete ino?
and i use this library:
PubSubClient by Nick O'Leary Version 2.6.0 mqtt3.1.1
@timsson have you patched all the source code to support the lastest 2.6.0 version of PubSubClient?
I had to revert back to 1.9.1 to compile ESPEasy earlier today, and was wondering how difficult it would be to refresh the code to support all the latest versions of the different libraries.
Ciao, Luca
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#14
Post
by timsson » 21 Jul 2016, 21:10
... oh i see a new pubsubclient version by martinus!
great work!
Who can integrale lwt?
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#15
Post
by timsson » 25 Jul 2016, 13:19
maybe:
ESPEasy.ino
-------------------------
#define MQTT_TOPIC_LAST_WILL "/ESP_01/lwt"
// Setup MQTT Client
byte ProtocolIndex = getProtocolIndex(Settings.Protocol);
if (Protocol[ProtocolIndex].usesMQTT)
MQTTConnect();
MQTTclient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
sendSysInfoUDP(3);
-------------------------
Controller.ino
-------------------------
//boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
MQTTclient.connect("ESP_01", MQTT_TOPIC_LAST_WILL, 1, true, "disconnected");
if ((SecuritySettings.ControllerUser[0] != 0) && (SecuritySettings.ControllerPassword[0] != 0))
------------------------
->
mosquitto_sub -t /ESP_01/# -v
/ESP_01/lwt connected
/ESP_01/sys/wifi -77
/ESP_01/sys/wifi -78
/ESP_01/sys/wifi -76
/ESP_01/sys/wifi -75
/ESP_01/sys/time 2
/ESP_01/sys/freeram 26200
/ESP_01/lumi/lux 1024
/ESP_01/lwt disconnected
-
Martinus
#16
Post
by Martinus » 03 Aug 2016, 18:58
last will is currently implemented with a fixed "connection lost" message to <template>/status topic. Same topic as used for status requests.
-
tozett
- Normal user
- Posts: 734
- Joined: 22 Dec 2015, 15:46
- Location: Germany
#17
Post
by tozett » 04 Aug 2016, 10:29
+1
great, thanks!
-
JR01
- Normal user
- Posts: 260
- Joined: 14 Feb 2016, 21:04
- Location: South Africa
#18
Post
by JR01 » 04 Aug 2016, 17:58
last will is currently implemented with a fixed "connection lost" message to <template>/status topic. Same topic as used for status requests
Hi @Martinus, somehow I missed the ability to do a status request, I search the forum, don ton get it. Does one send a message into <template>/status on the ESP, and then get a status back? I tried a few ideas, not getting a response back. Also listened in this queue - whilst rebooting the ESP, nothing. Could you point us in the correct direction?
-
JR01
- Normal user
- Posts: 260
- Joined: 14 Feb 2016, 21:04
- Location: South Africa
#19
Post
by JR01 » 04 Aug 2016, 19:29
Thanks Martinus for the updates,
I am on R108, let me upgrade first.... // {post edited after firmware update}
Okay, done, on R118, with pubsub v2.6, wow, looks stable.... So, how can I use the <>/status MQTT queue? Can I push a question into the queue to get status info back? How?
-
JR01
- Normal user
- Posts: 260
- Joined: 14 Feb 2016, 21:04
- Location: South Africa
#21
Post
by JR01 » 06 Aug 2016, 09:11
Thank you @tozett, I got that part working, get my message "Connection Lost" on the <template>/status MQTT channel. But I was asking if it was also designed to ask questions on that channel and get answers back?
-
timsson
- Normal user
- Posts: 77
- Joined: 25 Mar 2016, 22:00
#22
Post
by timsson » 22 Aug 2016, 10:02
Hello,
please can you add this:?
MQTTclient.publish(LWTTopic.c_str() , "connected", true);
Thanks!
-
JR01
- Normal user
- Posts: 260
- Joined: 14 Feb 2016, 21:04
- Location: South Africa
#23
Post
by JR01 » 22 Aug 2016, 18:47
Hi @timsson ,
I assume this code you are using for, is to send the opposite of 'Connection Lost' - once only, on mqtt connect?
If so: +1 on this request...
...as I want to store in a MySQL db when connection is lost, with the time, and then do same when the connection is re-established.
-
jsilver
- Normal user
- Posts: 23
- Joined: 24 May 2016, 14:45
- Location: Lewes, UK
-
Contact:
#24
Post
by jsilver » 06 Sep 2016, 08:17
JR01 wrote:I assume this code you are using for, is to send the opposite of 'Connection Lost' - once only, on mqtt connect?
+1 from me too

-
wutu
- Normal user
- Posts: 35
- Joined: 05 Feb 2016, 07:33
#25
Post
by wutu » 28 Nov 2016, 11:10
It would be good to solve this separate topic. With online/connected status.
Now I find out whether the device is reconnected to a broker. Respectively. I have in my system two rules are in addition to achieve this.
See also
viewtopic.php?f=6&t=2352
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 26 guests