add sensor overview and start link
parent
0a0976dc37
commit
7aa6f7fdf8
26
main.tpl
26
main.tpl
|
@ -14,5 +14,31 @@
|
|||
<li>{{measdata[item]['varname']}}: {{measlen}}</li>
|
||||
%end
|
||||
</ul>
|
||||
<p><a href="/kfz">Dateneingabe KFZ</a></p>
|
||||
<p><a href="/haus">Dateneingabe Haus</a></p>
|
||||
<p> Sensoren:</p>
|
||||
<form action="/" method="post">
|
||||
<table>
|
||||
<tr><th>Sensor</th><th>Aktiviert</th><th>in Betrieb</th></tr>
|
||||
%for sns in sensors:
|
||||
%snns=sensors[sns]
|
||||
%sac="Inaktiv"
|
||||
%sru=""
|
||||
%if snns['enable']==1:
|
||||
%sac="Aktiviert"
|
||||
%if snns['running']:
|
||||
%sru="läuft"
|
||||
%else:
|
||||
%sru='unterbrochen'
|
||||
%end
|
||||
%end
|
||||
<tr><th>{{sns}}</th><th>{{sac}}</th><th>{{sru}}
|
||||
%if sru=='unterbrochen':
|
||||
<input name="sensor" value={{sns}} type="submit"/>
|
||||
%end
|
||||
</th></tr>
|
||||
%end
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
50
pyweb.py
50
pyweb.py
|
@ -19,10 +19,27 @@ except:
|
|||
log_conf=json.load(cf)
|
||||
cf.close()
|
||||
|
||||
sensors={
|
||||
"bme280":{"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"tristar":{"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"vedirect":{"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"mcp9808": {"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"tsl2591":{"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"veml6070":{"enable":0,"script":"log_ads1x15.py","running":0},
|
||||
"ads1x15":{"enable":0,"script":"log_ads1x15.py","running":0}
|
||||
}
|
||||
|
||||
parameter={"device":socket.gethostname(),"allowed_ip":{"127.0.0.1":"25A4CF79414F10FD"},"gpg_keyid":"25A4CF79414F10FD","server_transfer_wait":2,"server_keyid":"25A4CF79414F10FD"}
|
||||
for n in parameter:
|
||||
if n in log_conf:
|
||||
parameter[n]=log_conf[n]
|
||||
|
||||
for sns in sensors:
|
||||
if sns in log_conf:
|
||||
if 'enable' in log_conf[sns]:
|
||||
if log_conf[sns]['enable'] == 1:
|
||||
sensors[sns]['enable']=1
|
||||
|
||||
if "sqlserver" in log_conf:
|
||||
hostname="localhost"
|
||||
if "host" in log_conf['sqlserver']:
|
||||
|
@ -110,8 +127,22 @@ app=Bottle()
|
|||
|
||||
@app.get('/')
|
||||
def approot():
|
||||
print(request.remote_addr in parameter['allowed_ip'])
|
||||
return template('main.tpl',server=socket.gethostname(),cpupercent=psutil.cpu_percent(),countticket=count_tickets,tickettime=last_ticket_time,measdata=measdata)
|
||||
for sns in sensors:
|
||||
if sensors[sns]['enable']==1:
|
||||
sensors[sns]['running']= sensors[sns]['script'] in (p.name() for p in psutil.process_iter())
|
||||
print(sensors)
|
||||
return template('main.tpl',server=socket.gethostname(),cpupercent=psutil.cpu_percent(),countticket=count_tickets,tickettime=last_ticket_time,measdata=measdata,sensors=sensors)
|
||||
@app.post('/')
|
||||
def submit_root():
|
||||
sensor_start=request.forms.get('sensor')
|
||||
if sensor_start in sensors:
|
||||
sensor_script=abspath+'/'+sensors[sensor_start]['script']
|
||||
try:
|
||||
stored_timestamps=os.path.getsize(sensor_script)
|
||||
except:
|
||||
print("start script does not exist")
|
||||
else:
|
||||
os.spawnl(os.P_NOWAIT,sensor_script,' ')
|
||||
|
||||
@app.post('/data/<hash_id:int>')
|
||||
def dataimport(hash_id):
|
||||
|
@ -216,7 +247,20 @@ def submit_kfz():
|
|||
print(json_out)
|
||||
# q.put(json_out,block=False)
|
||||
|
||||
|
||||
@app.get('/test')
|
||||
def get_test():
|
||||
return template('''
|
||||
<form action="/test" method="post">
|
||||
<input name="but" value="Senden1" type="submit" /></br>
|
||||
<input name="but" value="Senden2" type="submit" /></br>
|
||||
<input name="but" value="Senden3" type="submit" /></br>
|
||||
</form>
|
||||
''')
|
||||
|
||||
@app.post('/test')
|
||||
def submit_test():
|
||||
print(request.forms.get('but'))
|
||||
|
||||
q=Queue(maxsize=0)
|
||||
|
||||
sql_worker=threading.Thread(target=sql_insert,args=(q,))
|
||||
|
|
Loading…
Reference in New Issue