Skip to content

Commit

Permalink
Merge pull request enesbcs#285 from clumsy-stefan/add_lwt_retain_true
Browse files Browse the repository at this point in the history
Add retain=True to LWT for MQTT
  • Loading branch information
enesbcs authored Jan 11, 2024
2 parents 6156c5f + 1850dec commit 340e596
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _C014_GenMQTT.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def connect(self):
except:
self.keepalive = 60
try:
self.mqttclient.will_set(self.lwt_t, payload=self.lwtdisconnmsg, qos=0, retain=True)
self.mqttclient.will_set(self.lwt_t, self.lwtdisconnmsg, qos=0, retain=True)
self.mqttclient.connect(self.controllerip,int(self.controllerport),keepalive=self.keepalive) # connect_async() is faster but maybe not the best for user/pass method
self.mqttclient.loop_start()
except Exception as e:
Expand All @@ -184,7 +184,7 @@ def connect(self):

def disconnect(self):
try:
(mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtdisconnmsg)
(mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtdisconnmsg, qos=0, retain=True)
except Exception as e:
print(e)
try:
Expand Down Expand Up @@ -223,7 +223,7 @@ def isconnected(self,ForceCheck=True):
commands.rulesProcessing("GenMQTT#Disconnected",rpieGlobals.RULE_SYSTEM)
else:
try:
(mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtconnmsg)
(mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtconnmsg, qos=0, retain=True)
except:
pass
commands.rulesProcessing("GenMQTT#Connected",rpieGlobals.RULE_SYSTEM)
Expand Down Expand Up @@ -582,4 +582,4 @@ def on_disconnect(self, client, userdata, rc):
def on_message(self, mqttc, obj, msg):
if self.controllercb is not None:
self.controllercb(msg)


0 comments on commit 340e596

Please sign in to comment.