From fadb8031612dd6efbce9efdd9c9f97999a9e8514 Mon Sep 17 00:00:00 2001 From: enesbcs Date: Tue, 23 Nov 2021 19:16:27 +0100 Subject: [PATCH] Telegram, P2P, Time comparison, PCF8574 fixes. Added support for RPI Zero 2W --- _C013_ESPEasyP2P.py | 87 +++++++++++++++++++++++++++++++++++++++------ _N006_Telegram.py | 2 ++ _P019_PCF8574.py | 4 +-- commands.py | 70 ++++++++++++++++++++++++++---------- linux_os.py | 8 +++++ rpieGlobals.py | 2 +- 6 files changed, 141 insertions(+), 32 deletions(-) diff --git a/_C013_ESPEasyP2P.py b/_C013_ESPEasyP2P.py index 7565d07..2f3de2f 100644 --- a/_C013_ESPEasyP2P.py +++ b/_C013_ESPEasyP2P.py @@ -35,6 +35,9 @@ def __init__(self,controllerindex): self.controllerport = 65501 self.timer30s = True self.bgproc = None + self.netmethod = 0 + self.ownip = "" + self.ownmac = "" def controller_init(self,enablecontroller=None): if enablecontroller != None: @@ -44,13 +47,41 @@ def controller_init(self,enablecontroller=None): self.bgproc.daemon = True self.bgproc.start() # self.timer_thirty_second() + try: + nm = self.netmethod + except: + self.netmethod = 0 + self.ownip = "" self.initialized = True return True def webform_load(self): webserver.addFormNote("Hint: only the Controller Port parameter used!") + options = ["Primary net","Secondary net","Manual"] + optionvalues = [0,1,2] + try: + netm = self.netmethod + except: + netm = 0 + webserver.addFormSelector("IP address","c013_net",len(optionvalues),options,optionvalues,None,int(netm)) + try: + oip = self.ownip + except: + oip = "" + if netm != 2: + oip = "" + elif oip == "": + oip = str(OS.get_ip()) + webserver.addFormTextBox("Force own IP to broadcast","c013_ip",str(oip),16) return True + def webform_save(self,params): + self.netmethod = int(webserver.arg("c013_net",params)) + if self.netmethod == 2: + self.ownip = str(webserver.arg("c013_ip",params)) + else: + self.ownip = "" + def nodesort(self,item): v = 0 try: @@ -227,17 +258,51 @@ def timer_thirty_second(self): if self.enabled: #send alive signals dp = data_packet() - try: - defdev = Settings.NetMan.getprimarydevice() - except Exception as e: - misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"C013 sysinfo: "+str(e)) - defdev = -1 - if defdev != -1: - dp.infopacket["mac"] = Settings.NetworkDevices[defdev].mac - dp.infopacket["ip"] = Settings.NetworkDevices[defdev].ip - else: - dp.infopacket["mac"] = "00:00:00:00:00:00" - dp.infopacket["ip"] = "" + dp.infopacket["mac"] = "00:00:00:00:00:00" + dp.infopacket["ip"] = "" + if self.netmethod == 2: + try: + defdev = Settings.NetMan.getprimarydevice() + except Exception as e: + defdev = -1 + if defdev != -1: + try: + dp.infopacket["mac"] = Settings.NetworkDevices[defdev].mac + except: + pass + else: + try: + defdev = Settings.NetMan.getsecondarydevice() + except Exception as e: + defdev = -1 + if defdev != -1: + try: + dp.infopacket["mac"] = Settings.NetworkDevices[defdev].mac + except: + pass + dp.infopacket["ip"] = self.ownip + elif self.netmethod == 0: + try: + defdev = Settings.NetMan.getprimarydevice() + except Exception as e: + defdev = -1 + if defdev != -1: + try: + dp.infopacket["mac"] = Settings.NetworkDevices[defdev].mac + dp.infopacket["ip"] = Settings.NetworkDevices[defdev].ip + except: + pass + elif self.netmethod == 1: + try: + defdev = Settings.NetMan.getsecondarydevice() + except Exception as e: + defdev = -1 + if defdev != -1: + try: + dp.infopacket["mac"] = Settings.NetworkDevices[defdev].mac + dp.infopacket["ip"] = Settings.NetworkDevices[defdev].ip + except: + pass if dp.infopacket["ip"] == "": try: dp.infopacket["ip"] = str(OS.get_ip()) diff --git a/_N006_Telegram.py b/_N006_Telegram.py index 3887474..98a4cbb 100644 --- a/_N006_Telegram.py +++ b/_N006_Telegram.py @@ -58,6 +58,7 @@ def webform_load(self): # create html page for settings webserver.addFormTextBox("Server","server",self.server,128) webserver.addFormNumericBox("Port","port",self.port,1,65535) webserver.addFormPasswordBox("Token","passw",self.passw,64) + webserver.addFormTextBox("Chat-id","chatid",self.chatid,255) webserver.addHtml("Body:") @@ -77,6 +78,7 @@ def webform_save(self,params): # process settings post reply if "**" not in passw: self.passw = passw self.chatid = "" + self.chatid = str(webserver.arg("chatid",params)) self.body = webserver.arg("body",params) self.plugin_init() return True diff --git a/_P019_PCF8574.py b/_P019_PCF8574.py index 37e7bec..cce2784 100644 --- a/_P019_PCF8574.py +++ b/_P019_PCF8574.py @@ -162,7 +162,7 @@ def timer_ten_per_second(self): if self.initialized and self.enabled: try: val = self.pcf.readpin(self.rpin) - if int(val) != int(float(self.uservar[0])): + if float(val) != float(self.uservar[0]): self.set_value(1,val,True) self._lastdataservetime = rpieTime.millis() except: @@ -172,7 +172,7 @@ def timer_ten_per_second(self): def timer_once_per_second(self): if self.initialized and self.enabled: if self.timer100ms==False: - self.ten_per_second() + self.timer_ten_per_second() return self.timer1s def plugin_read(self): # deal with data processing at specified time interval diff --git a/commands.py b/commands.py index ce147e0..30b1553 100644 --- a/commands.py +++ b/commands.py @@ -1029,7 +1029,7 @@ def parseconversions(cvalue): return retval def parseruleline(linestr,rulenum=-1): - global GlobalRules, EventValues + global GlobalRules, EventValues, SysVars cline = linestr.strip() state = "CMD" if "[" in linestr: @@ -1090,6 +1090,19 @@ def parseruleline(linestr,rulenum=-1): cline = cline.replace(">==",">=") cline = cline.replace("<==","<=") tline = cline + if (SysVars[0] in linestr) or (SysVars[1] in linestr): #convert time strings + m = re.findall(r"(?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)", cline) + for tm in m: + st = timeStringToSeconds(tm) + if st != None: + st = str(st) + cline = cline.replace(tm,st) + m = re.findall(r"(?:[01]\d|2[0-3]):(?:[0-5]\d)", cline) + for tm in m: + st = timeStringToSeconds(tm) + if st != None: + st = str(st) + cline = cline.replace(tm,st) state = "IFST" try: cline = eval(cline[3:]) @@ -1152,23 +1165,23 @@ def rulesProcessing(eventstr,efilter=-1,startn=0): # fire events EventValues[1] = str(rpieTime.Timers[tn-1].loopcount) except: pass - else: # hack taskvalues to eventvalues for lazy users - try: - tname = estr - if "=" in tname: - tarr = tname.split("=") - tname = tarr[0].strip() - if '#' in tname: - ev = gettaskvaluefromname(tname) - if ev is not None: - EventValues = [0,0,0,0] - EventValues[0] = str(ev) - else: - ev = gettaskvaluefromnames(tname) - if len(ev) > 0: - EventValues = ev - except: - pass +# else: # hack taskvalues to eventvalues for lazy users +# try: +# tname = estr +# if "=" in tname: +# tarr = tname.split("=") +# tname = tarr[0].strip() +# if '#' in tname: +# ev = gettaskvaluefromname(tname) +# if ev is not None: +# EventValues = [0,0,0,0] +# EventValues[0] = str(ev) +# else: +# ev = gettaskvaluefromnames(tname) +# if len(ev) > 0: +# EventValues = ev +# except: +# pass for r in range(startn,len(GlobalRules)): if efilter!=-1: if GlobalRules[r]["ecat"]==efilter: # check event based on filter @@ -1313,3 +1326,24 @@ def comparetime(tstr): except: result = False return result + +def timeStringToSeconds(tstr): + cc = tstr.count(':') + tv = None + if cc==1 or cc==2: + tv = 0 + try: + tva = tstr.split(':') + h = int(tva[0]) + m = int(tva[1]) + if h>24 or h<0 or m<0 or m>59: + return None + tv = (h * 3600) + (m*60) + if cc==2: + s = int(tva[2]) + if s <0 or s>59: + return None + tv += s + except: + tv = None + return tv diff --git a/linux_os.py b/linux_os.py index 8eaa233..39be7b1 100644 --- a/linux_os.py +++ b/linux_os.py @@ -405,6 +405,14 @@ def getRPIVer(): "wlan": "1", "bt":"1" } + elif (hwid == "902120"): + hwarr = { + "name": "Pi Zero 2W", + "ram": "512MB", + "pins": "40", + "wlan": "1", + "bt":"1" + } elif (hwid == "a02082") or (hwid == "a22082") or (hwid == "a32082") or (hwid == "a52082") or (hwid == "a22083"): hwarr = { "name": "Pi 3 Model B", diff --git a/rpieGlobals.py b/rpieGlobals.py index 0264395..eb486a2 100644 --- a/rpieGlobals.py +++ b/rpieGlobals.py @@ -6,7 +6,7 @@ # Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/ # PROGNAME = "RPIEasy" -BUILD = 21234 +BUILD = 21327 PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:] gpMenu = []