Page 1 of 3

Last will on umqtt.simple

Posted: Mon Sep 10, 2018 5:13 pm
by guyd
Hi,

I'm trying to config my ESP8266 running Micropython, to notify "last-will", as shown below and according to developer as noted on github.
still- I get no notification when I disconnect my ESP8266, other command and notification work as needed.

Guy

def startMQTTclient(self):
self.mqtt_client = MQTTClient(self.mqtt_client_id, self.server, self.qos, user=self.user,
password=self.password)
self.mqtt_client.set_callback(self.on_message)
self.mqtt_client.set_last_will(topic=self.topic2, msg="last_will")

try:
self.mqtt_client.connect()
for topic in self.topic1:
self.mqtt_client.subscribe(topic)
print("Connected to MQTT server")
return 1
except OSError:
self.notify_error("Error connecting MQTT broker")
return 0

Re: Last will on umqtt.simple

Posted: Mon Sep 10, 2018 11:07 pm
by SpotlightKid
Are you the same person, who opened this issue?

https://github.com/micropython/micropyt ... issues/304

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 1:01 am
by guyd
No.

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 1:06 am
by guyd
I found this topic,
viewtopic.php?t=3584- which asks almost exactly the same.
I added a "keepalive" time out - and now I get my "last will" notification all time ( around 1-2 minutes ). Now, this is not a fake " last will" since somehow it does get disconnected from broker ( guess it has something to do with that "keep alive" parameter ).
commenting "keepalive" and last_will stop this disconnection.

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 1:08 am
by guyd
guyd wrote:
Tue Sep 11, 2018 1:01 am
No.
I'm using a local broker on RPI zero W - wich works great from some time now.

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 1:52 pm
by SpotlightKid
Which MQTT broker are you using (mosquitto?) and which MQTT client do you have subscribed to the topic to receive the last will message? Have you checked the broker server logs?

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 3:59 pm
by guyd
hi,
yes- mosquitto .
for last will- is the same topic for all outgoing messages for all my device ( which are recorded to a log file )

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 7:56 pm
by SpotlightKid
So, have you looked at the mosquitto log? Also, I repeat, how are confirming that the last will message is not sent?

Re: Last will on umqtt.simple

Posted: Tue Sep 11, 2018 8:14 pm
by guyd
SpotlightKid wrote:
Tue Sep 11, 2018 7:56 pm
So, have you looked at the mosquitto log? Also, I repeat, how are confirming that the last will message is not sent?
please guide

Re: Last will on umqtt.simple

Posted: Wed Sep 12, 2018 4:56 pm
by pythoncoder
One way to test this is to run mosquitto_sub on a PC on the network.