Skip to content

Commit

Permalink
Minor webgui enhancements: debug device time, toggle button, port lis…
Browse files Browse the repository at this point in the history
…t customization
  • Loading branch information
enesbcs committed May 6, 2020
1 parent b8ca368 commit 509df28
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
5 changes: 4 additions & 1 deletion RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ def initprogram():
t = threading.Thread(target=mainloop) # starting sensors and background functions
t.daemon = True
t.start()
ports = [80,8080,8008] # check for usable ports
try:
ports = Settings.AdvSettings["portlist"]
except:
ports = [80,8080,8008,591] # check for usable ports
up = 0
for p in ports:
up = p
Expand Down
1 change: 1 addition & 0 deletions Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"fileloglevel":0,
"sysloglevel":0,
"syslogip":"",
"portlist":[80,8080,8008,591],
"battery": { "enabled":0,"tasknum":0,"taskvaluenum":0}
}

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 = 20126
BUILD = 20127
PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:]

gpMenu = []
Expand Down
62 changes: 61 additions & 1 deletion webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import rpieGlobals
import Settings
import time
from datetime import datetime
from datetime import datetime, timedelta
import rpieTime
import linux_os as OS
import misc
Expand Down Expand Up @@ -1236,6 +1236,8 @@ def handle_devices(self):
setpage = arg("setpage",responsearr)
taskIndex = arg("index",responsearr)
runIndex = arg("run",responsearr)
toggleIndex = arg("toggle",responsearr)

if page=='':
page=0
else:
Expand Down Expand Up @@ -1288,6 +1290,22 @@ def handle_devices(self):
except Exception as e:
print(e)

if toggleIndex != "":
if len(Settings.Tasks)<1:
return False
try:
s = int(toggleIndex)
except:
s = -1
try:
if s >0 and (s<=len(Settings.Tasks)):
s = s-1 # array is 0 based, tasks is 1 based
if (type(Settings.Tasks[s])!=bool) and (Settings.Tasks[s]):
if (Settings.Tasks[s].enabled):
Settings.Tasks[s].set_value(1,(1-int(Settings.Tasks[s].uservar[0])),publish=True)
except Exception as e:
print(e)

if taskIndexNotSet: # show all tasks as table
if True:
TXBuffer += "<script> (function(){ var max_tasknumber = "+ str(rpieGlobals.TASKS_MAX) +"; var max_taskvalues = "+ str(rpieGlobals.VARS_PER_TASK) +"; var timeForNext = 2000; var c; var k; var err = ''; var i = setInterval(function(){ var url = '/json?view=sensorupdate';"
Expand Down Expand Up @@ -1330,6 +1348,12 @@ def handle_devices(self):
TXBuffer += "&page="
TXBuffer += str(page)
TXBuffer += "'>Run</a>"
if Settings.Tasks[x].recdataoption and Settings.Tasks[x].vtype==rpieGlobals.SENSOR_TYPE_SWITCH:
TXBuffer += "<a class='button link' href='devices?toggle="
TXBuffer += str(x + 1)
TXBuffer += "&page="
TXBuffer += str(page)
TXBuffer += "'>Toggle</a>"
except:
pass
TXBuffer += "<TD>"
Expand Down Expand Up @@ -1462,6 +1486,13 @@ def handle_devices(self):
TXBuffer += "</div>"
except Exception as e:
print(e)
try:
if int(Settings.AdvSettings["webloglevel"])>=rpieGlobals.LOG_LEVEL_DEBUG_MORE:
if Settings.Tasks[x].enabled:
lds = rpieTime.start_time + timedelta(seconds=(Settings.Tasks[x]._lastdataservetime / 1000))
TXBuffer += "<div><p align=left><br><i>"+ lds.strftime('%Y-%m-%d %H:%M:%S')+"</i></div>"
except Exception as e:
print(e)
else:
TXBuffer += "<TD><TD><TD><TD><TD><TD>"
TXBuffer += "<tr><TD colspan=2><div class='button' id='clock'>00:00:00</div><TD><TD><TD><TD><TD><TD><TD></tr>"
Expand Down Expand Up @@ -2273,6 +2304,17 @@ def handle_advanced(self):
except:
Settings.AdvSettings["Latitude"] = 0
Settings.AdvSettings["Longitude"] = 0
portlist = []
for p in range(0,9):
try:
d = int(arg("_p"+str(p),responsearr))
except:
d = 0
if d > 0:
portlist.append(d)
if len(portlist)<1:
portlist = [80,8080,8008,591]
Settings.AdvSettings["portlist"] = portlist
Settings.saveadvsettings()

TXBuffer += "<form method='post'><table class='normal'>"
Expand All @@ -2289,6 +2331,24 @@ def handle_advanced(self):
Settings.AdvSettings["syslogip"] = val
addFormTextBox("Syslog IP", "syslogip", val,64)

addFormSubHeader("WebGUI Settings")
defports = [80,8080,8008,591]
try:
ports = Settings.AdvSettings["portlist"]
except:
ports = defports
TXBuffer += "<tr><td>Enabled GUI ports:<td><fieldset>"
for p in range(len(defports)):
try:
cn = "_p"+str(p)
TXBuffer += "<input type='checkbox' name='"+cn+"' id='"+cn+"' value='"+str(defports[p])+"' "
if defports[p] in ports:
TXBuffer += "checked"
TXBuffer += "><label for='"+cn+"'>"+str(defports[p])+"</label> "
except:
pass
TXBuffer += "</fieldset>"

addFormSubHeader("Location Settings")
try:
lat = Settings.AdvSettings["Latitude"]
Expand Down

0 comments on commit 509df28

Please sign in to comment.