Last will on umqtt.simple

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Last will on umqtt.simple

Post by guyd » Mon Sep 10, 2018 5:13 pm

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

SpotlightKid
Posts: 357
Joined: Wed Apr 08, 2015 5:19 am

Re: Last will on umqtt.simple

Post by SpotlightKid » Mon Sep 10, 2018 11:07 pm

Are you the same person, who opened this issue?

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

guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Re: Last will on umqtt.simple

Post by guyd » Tue Sep 11, 2018 1:01 am

No.

guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Re: Last will on umqtt.simple

Post by guyd » Tue Sep 11, 2018 1:06 am

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.

guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Re: Last will on umqtt.simple

Post by guyd » Tue Sep 11, 2018 1:08 am

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.

SpotlightKid
Posts: 357
Joined: Wed Apr 08, 2015 5:19 am

Re: Last will on umqtt.simple

Post by SpotlightKid » Tue Sep 11, 2018 1:52 pm

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?

guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Re: Last will on umqtt.simple

Post by guyd » Tue Sep 11, 2018 3:59 pm

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 )

SpotlightKid
Posts: 357
Joined: Wed Apr 08, 2015 5:19 am

Re: Last will on umqtt.simple

Post by SpotlightKid » 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?

guyd
Posts: 74
Joined: Fri Jul 20, 2018 6:08 am

Re: Last will on umqtt.simple

Post by guyd » Tue Sep 11, 2018 8:14 pm

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

User avatar
pythoncoder
Posts: 2887
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Last will on umqtt.simple

Post by pythoncoder » Wed Sep 12, 2018 4:56 pm

One way to test this is to run mosquitto_sub on a PC on the network.
Peter Hinch

Post Reply