def p026_get_value(self, ptype): value = 0 if ptype == 1: value = rpieTime.getuptime(0) elif ptype == 2: value = OS.FreeMem() elif ptype == 3: value = OS.get_rssi() elif ptype == 4: value = OS.read_cpu_usage() elif ptype == 5: value = OS.read_cpu_temp() return value
def p026_get_value(self,ptype): value = 0 try: if ptype == 1: value = rpieTime.getuptime(0) elif ptype == 2: value = OS.FreeMem() elif ptype == 3: value = OS.get_rssi() elif ptype == 4: value = OS.read_cpu_usage() elif ptype == 5: value = OS.read_cpu_temp() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"P026 get "+str(e)) return value
def getglobalvar(varname): global SysVars svname = varname.strip().lower() res = "" if svname in SysVars: if svname == SysVars[0]: #%systime% 01:23:54 return datetime.now().strftime('%H:%M:%S') elif svname == SysVars[1]: #%systm_hm% 01:23 return datetime.now().strftime('%H:%M') elif svname == SysVars[2]: #%lcltime% 2018-03-16 01:23:54 return datetime.now().strftime('%Y-%m-%d %H:%M:%S') elif svname == SysVars[3]: #%syshour% 11 Current hour (hh) return datetime.now().strftime('%H') elif svname == SysVars[4]: #%sysmin% 22 Current minute (mm) return datetime.now().strftime('%M') elif svname == SysVars[5]: #%syssec% 33 Current second (ss) return datetime.now().strftime('%S') elif svname == SysVars[6]: #%sysday% 16 Current day of month (DD) return datetime.now().strftime('%d') elif svname == SysVars[7]: #%sysmonth% 3 Current month (MM) return datetime.now().strftime('%m') elif svname == SysVars[8]: #%sysyear% 2018 4 digits (YYYY) return datetime.now().strftime('%Y') elif svname == SysVars[9]: #%sysyears% 18 2 digits (YY) return datetime.now().strftime('%y') elif svname == SysVars[ 10]: #%sysweekday% 5 Weekday (integer) - 1, 2, 3... (1=Sunday, 2=Monday etc.) return str(int(datetime.now().strftime('%w')) + 1) elif svname == SysVars[ 11]: #%sysweekday_s% Fri Weekday (verbose) - Sun, Mon, Tue return datetime.now().strftime('%a') elif svname == SysVars[ 12]: #%unixtime% 1521731277 Unix time (seconds since epoch, 1970-01-01 00:00:00) return str(int(time.time())) elif svname == SysVars[13]: #%uptime% 3244 Uptime in minutes return str(rpieTime.getuptime(2)) elif svname == SysVars[14]: #%rssi% -45 WiFi signal strength (dBm) return str(OS.get_rssi()) elif svname == SysVars[15]: #%ip% 192.168.0.123 Current IP address return str(OS.get_ip()) elif svname == SysVars[16]: #%ip4% ipcim 4.byte res2 = str(OS.get_ip()) resarr = res2.split(".") if len(resarr) > 3: return resarr[3] elif svname == SysVars[17]: #%sysname% name return Settings.Settings["Name"] elif svname == SysVars[18]: #%unit% 32 Unit number return Settings.Settings["Unit"] elif svname == SysVars[19]: #%ssid% H4XX0R njietwork! wdev = False try: wdev = Settings.NetMan.getfirstwirelessdev() except: wdev = False if wdev: res = str(Network.get_ssid(wdev)) elif svname == SysVars[20]: #%mac% 00:14:22:01:23:45 MAC address pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd != "" and pd >= 0: return Settings.NetworkDevices[pd].mac elif svname == SysVars[ 21]: #%mac_int% 2212667 MAC address in integer to be used in rules (only the last 24 bit) pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd >= 0: try: res2 = Settings.NetworkDevices[pd].mac resarr = res2.split(":") if len(resarr) > 5: res = str( int("0x" + resarr[3] + resarr[4] + resarr[5], 16)) except: res = "" return res
def getstatusjson(st, globdata): rstr = "" if st == "Status": rstr += '"Status": {"Module": ' + str( globdata.modtype) + ',"DeviceName":"' + str( Settings.Settings["Name"]) + '",' rstr += '"FriendlyName": ["' + str(globdata.datas[0][1]) + '"' if globdata.taskdevicepluginconfig[0] > 1: for n in range(1, globdata.taskdevicepluginconfig[0]): rstr += ',"' + str(globdata.datas[n][1]) + '"' rstr += '],"Topic": "","ButtonTopic": "0","PowerOnState": 0,"LedState": 0,"SaveData": 1,"SaveState": 1,"ButtonRetain": 0,"PowerRetain": 0,' if getswitchstate(0, globdata): s = 1 else: s = 0 rstr += '"Power": ' + str(s) + '}' elif st == "StatusPRM": rstr += '"StatusPRM": {"Baudrate": 115200,"GroupTopic": "","OtaUrl": "","Sleep": 0,"BootCount": 1,"SaveCount": 1,"SaveAddress": "FB000",' rstr += '"Uptime": "' + rpieTime.getuptime(3) + '"}' elif st == "StatusNET": try: defaultdev = Settings.NetMan.getprimarydevice() if Settings.NetworkDevices[defaultdev].ip == "": defaultdev = -1 except: defaultdev = -1 if defaultdev == -1: try: defaultdev = Settings.NetMan.getsecondarydevice() except: defaultdev = -1 rstr += '"StatusNET": {"Webserver": 2,"WifiConfig": 4,' rstr += '"Hostname": "' + str(Settings.Settings["Name"]) + '",' rstr += '"IPAddress": "' + str( Settings.NetworkDevices[defaultdev].ip) + '",' rstr += '"Gateway": "' + str( Settings.NetworkDevices[defaultdev].gw) + '",' rstr += '"Subnetmask": "' + str( Settings.NetworkDevices[defaultdev].mask) + '",' dnss = Settings.NetworkDevices[defaultdev].dns.strip().split(" ") rstr += '"DNSServer": "' + str(dnss[0]) + '",' rstr += '"Mac": "' + str( Settings.NetworkDevices[defaultdev].mac).upper() + '"}' elif st == "StatusSNS": rstr += '"StatusSNS": {"Time": "' + datetime.now().strftime( '%Y-%m-%dT%H:%M:%S') + '",' if globdata.taskdevicepluginconfig[0] == 1: if getswitchstate(0, globdata) == 1: st = "ON" else: st = "OFF" rstr += '"Switch1": "' + st + '"' else: for s in range(int(globdata.taskdevicepluginconfig[0])): if getswitchstate(s, globdata) == 1: st = "ON" else: st = "OFF" rstr += '"Switch' + str(s + 1) + '": "' + st + '"' if s < (int(globdata.taskdevicepluginconfig[0]) - 1): rstr += "," rstr += '}' elif st == "StatusSTS": rstr += '"StatusSTS": {"Vcc": 3.1415,' # Pi= 3.14 rstr += '"Time": "' + str( datetime.now().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"Uptime": "' + rpieTime.getuptime(3) + '",' if globdata.taskdevicepluginconfig[0] == 1: rstr += '"POWER": "' if getswitchstate(0, globdata) == 1: rstr += "ON" else: rstr += "OFF" rstr += '",' else: for s in range(globdata.taskdevicepluginconfig[0]): rstr += '"POWER' + str(s + 1) + '": "' if getswitchstate(s, globdata) == 1: rstr += "ON" else: rstr += "OFF" rstr += '",' rstr += '"Wifi": {"AP": 1,' rstr += '"SSId": "' + str(Settings.NetMan.WifiSSID) + '",' rstr += '"RSSI": ' + str(OS.get_rssi()) + ',' rstr += '"APMac": "","Channel":1}}' elif st == "StatusTIM": rstr += '"StatusTIM": {' rstr += '"UTC": "' + str( datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"Local": "' + str( datetime.now().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"StartDST": "1970-01-01T00:00:00","EndDST": "1970-01-01T00:00:00",' rstr += '"Timezone": "+00:00"}' elif st == "StatusMEM": rstr += '"StatusMEM": {"ProgramSize": 2048,"Free": 2048,"ProgramFlashSize": 4096,"FlashSize": 4096,"FlashMode": 3,' rstr += '"Heap": ' + str(OS.FreeMem()) + '}' elif st == "StatusFWR": rstr += '"StatusFWR": {"Version": "5.12.0a","Boot": 1,' rstr += '"BuildDateTime": "' + str(globdata.btime) + '",' rstr += '"Core": "' + rpieGlobals.PROGNAME + ' ' + rpieGlobals.PROGVER + '",' rstr += '"SDK": "Python ' + sys.version.replace( '\n', '') + " " + platform.platform() + '",' cpui = OS.get_cpu() frarr = str(cpui["speed"]).split() try: fr = str(int(misc.str2num(frarr[0]))) except: fr = str(frarr[0]) rstr += '"CpuFrequency": "' + fr + '","Hardware":"' + str( cpui["model"]) + '"}' return rstr
def getglobalvar(varname): global SysVars, suntimesupported svname = varname.strip().lower() par = "" if ("-" in svname): resarr = svname.split("-") svname = resarr[0] par = "-"+resarr[1] if ("+" in svname): resarr = svname.split("+") svname = resarr[0] par = "+"+resarr[1] res = "" if svname in SysVars: if svname==SysVars[0]: #%systime% 01:23:54 return datetime.now().strftime('%H:%M:%S') elif svname==SysVars[1]: #%systm_hm% 01:23 return datetime.now().strftime('%H:%M') elif svname==SysVars[2]: #%lcltime% 2018-03-16 01:23:54 return datetime.now().strftime('%Y-%m-%d %H:%M:%S') elif svname==SysVars[3]: #%syshour% 11 Current hour (hh) return int(datetime.now().strftime('%H')) elif svname==SysVars[4]: #%sysmin% 22 Current minute (mm) return int(datetime.now().strftime('%M')) elif svname==SysVars[5]: #%syssec% 33 Current second (ss) return int(datetime.now().strftime('%S')) elif svname==SysVars[6]: #%sysday% 16 Current day of month (DD) return int(datetime.now().strftime('%d')) elif svname==SysVars[7]: #%sysmonth% 3 Current month (MM) return int(datetime.now().strftime('%m')) elif svname==SysVars[8]: #%sysyear% 2018 4 digits (YYYY) return datetime.now().strftime('%Y') elif svname==SysVars[9]: #%sysyears% 18 2 digits (YY) return datetime.now().strftime('%y') elif svname==SysVars[10]: #%sysweekday% 5 Weekday (integer) - 1, 2, 3... (1=Sunday, 2=Monday etc.) return str(int(datetime.now().strftime('%w'))+1) elif svname==SysVars[11]: #%sysweekday_s% Fri Weekday (verbose) - Sun, Mon, Tue return datetime.now().strftime('%a') elif svname==SysVars[12]: #%unixtime% 1521731277 Unix time (seconds since epoch, 1970-01-01 00:00:00) return str(int(time.time())) elif svname==SysVars[13]: #%uptime% 3244 Uptime in minutes return str(rpieTime.getuptime(2)) elif svname==SysVars[14]: #%rssi% -45 WiFi signal strength (dBm) return str(OS.get_rssi()) elif svname==SysVars[15]: #%ip% 192.168.0.123 Current IP address return str(OS.get_ip()) elif svname==SysVars[16]: #%ip4% ipcim 4.byte res2 = str(OS.get_ip()) resarr = res2.split(".") if len(resarr)>3: return resarr[3] elif svname==SysVars[17]: #%sysname% name return Settings.Settings["Name"] elif svname==SysVars[18]: #%unit% 32 Unit number return Settings.Settings["Unit"] elif svname==SysVars[19]: #%ssid% H4XX0R njietwork! wdev = False try: wdev = Settings.NetMan.getfirstwirelessdev() except: wdev = False if wdev: res = str(Network.get_ssid(wdev)) elif svname==SysVars[20]: #%mac% 00:14:22:01:23:45 MAC address pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd<0 and len(Settings.NetworkDevices)>0: pd = 0 if pd!="" and pd>=0: return Settings.NetworkDevices[pd].mac elif svname==SysVars[21]: #%mac_int% 2212667 MAC address in integer to be used in rules (only the last 24 bit) pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd<0 and len(Settings.NetworkDevices)>0: pd = 0 if pd>=0: try: res2 = Settings.NetworkDevices[pd].mac resarr = res2.split(":") if len(resarr)>5: res = str(int("0x"+resarr[3]+resarr[4]+resarr[5],16)) except: res = "" return res elif svname==SysVars[22]: #%build% bstr = str(rpieGlobals.BUILD) return bstr elif svname==SysVars[23]: #sunrise try: from suntime import Sun suntimesupported = 1 except: suntimesupported = 0 if suntimesupported==1: try: sun = Sun(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"]) abd_sr = sun.get_local_sunrise_time(datetime.now()) if par!="": abd_sr = addtoTime(abd_sr,par) res = abd_sr.strftime('%H:%M') except Exception as e: res = "00:00" return res elif svname==SysVars[24]: #sunset try: from suntime import Sun suntimesupported = 1 except: suntimesupported = 0 if suntimesupported==1: try: sun = Sun(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"]) abd_ss = sun.get_local_sunset_time(datetime.now()) if par!="": abd_ss = addtoTime(abd_ss,par) res = abd_ss.strftime('%H:%M') except Exception as e: res = "00:00" return res elif svname==SysVars[25]: #sun altitude try: from pytz import reference from pysolar.solar import get_altitude pysolarsupported = 1 except: pysolarsupported = 0 res = "0" if pysolarsupported==1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) res = get_altitude(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"], today) except Exception as e: print(e) res = "0" return res elif svname==SysVars[26]: #sun azimuth try: from pytz import reference from pysolar.solar import get_azimuth pysolarsupported = 1 except: pysolarsupported = 0 res = "0" if pysolarsupported==1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) res = get_azimuth(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"], today) except Exception as e: print(e) res = "0" return res elif svname==SysVars[27]: #sun radiation try: from pytz import reference from pysolar.solar import get_altitude from pysolar.radiation import get_radiation_direct pysolarsupported = 1 except: pysolarsupported = 0 res = "-1" if pysolarsupported==1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) altitude_deg = get_altitude(Settings.AdvSettings["Latitude"],Settings.AdvSettings["Longitude"], today) res = get_radiation_direct(today, altitude_deg) except Exception as e: print(e) return res elif svname==SysVars[28]: #%br% return str("\r\n") elif svname==SysVars[29]: #%lf% return str("\n") elif svname==SysVars[30]: #%tab% return str(" ") return res