Skip to content

Commit

Permalink
C014 option reconnect added
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Oct 18, 2020
1 parent d194ad7 commit 88d9cd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions _C014_GenMQTT.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# topic: %sysname%/taskname/valuename/set payload value will be forwarded to it!
# (Two way communication)
#
# Variables: %sysname% %tskname% %valname%
# Variables: %sysname% %tskname% %valname% %tskid%
# # = %tskname%/%valname% !!!
#
# Commands can be remotely executed through MQTT with writing to:
# topic: %sysname%/cmd with payload: command
Expand Down Expand Up @@ -158,6 +159,7 @@ def connect(self):
self.mqttclient.loop_start()
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"MQTT controller: "+self.controllerip+":"+str(self.controllerport)+" connection failed "+str(e))
self.laststatus = 0
return self.isconnected()

def disconnect(self):
Expand All @@ -182,7 +184,7 @@ def isconnected(self,ForceCheck=True):
res = False
if self.enabled and self.initialized:
if ForceCheck==False:
return self.laststatus
return (self.laststatus==1)
if self.mqttclient is not None:
tstart = self.outch[:len(self.outch)-1]
gtopic = tstart+"status"
Expand Down Expand Up @@ -242,6 +244,7 @@ def webform_load(self): # create html page for settings
webserver.addFormTextBox("Controller lwl topic","c014_lwt",lwt,255)
webserver.addFormTextBox("LWT Connect Message","c014_cmsg",lwt1,255)
webserver.addFormTextBox("LWT Disconnect Message","c014_dcmsg",lwt2,255)
webserver.addFormCheckBox("Check conn & reconnect if needed at every 30 sec","c014_reconnect",self.timer30s)
return True

def webform_save(self,params): # process settings post reply
Expand Down Expand Up @@ -286,12 +289,23 @@ def webform_save(self,params): # process settings post reply
self.lwtdisconnmsg = "Offline"
if lwt!=self.lwt_topic or lwt1!= self.lwtconnmsg or lwt2!=self.lwtdisconnmsg:
pchange = True
if (webserver.arg("c014_reconnect",params)=="on"):
self.timer30s = True
else:
self.timer30s = False
if pchange and self.enabled:
self.disconnect()
time.sleep(0.1)
self.connect()
return True

def timer_thirty_second(self):
if self.enabled:
if self.isconnected()==False:
misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG,"MQTT: Try to reconnect")
self.connect()
return self.timer30s

def on_message(self, msg):
success = False
tstart = self.outch[:len(self.outch)-1]
Expand Down Expand Up @@ -367,7 +381,8 @@ def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,chang
vname = Settings.Tasks[tasknum].valuenames[u]
if vname != "":
if ('%t' in self.inch) or ('%v' in self.inch):
gtopic = self.inch.replace('#','')
gtopic = self.inch.replace('#/','')
gtopic = gtopic.replace('#','')
gtopic = gtopic.replace('%tskname%',tname)
gtopic = gtopic.replace('%tskid%',str(tasknum+1))
gtopic = gtopic.replace('%valname%',vname)
Expand All @@ -388,7 +403,8 @@ def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,chang
else:
vname = Settings.Tasks[tasknum].valuenames[changedvalue-1]
if ('%t' in self.inch) or ('%v' in self.inch):
gtopic = self.inch.replace('#','')
gtopic = self.inch.replace('#/','')
gtopic = gtopic.replace('#','')
gtopic = gtopic.replace('%tskname%',tname)
gtopic = gtopic.replace('%tskid%',str(tasknum+1))
gtopic = gtopic.replace('%valname%',vname)
Expand Down
2 changes: 1 addition & 1 deletion rpieGlobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
PROGNAME = "RPIEasy"
BUILD = 20291
BUILD = 20292
PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:]

gpMenu = []
Expand Down

0 comments on commit 88d9cd4

Please sign in to comment.