diff --git a/main.tpl b/main.tpl index 6fc07b7..87fdbc0 100644 --- a/main.tpl +++ b/main.tpl @@ -14,5 +14,31 @@
  • {{measdata[item]['varname']}}: {{measlen}}
  • %end +

    Dateneingabe KFZ

    +

    Dateneingabe Haus

    +

    Sensoren:

    +
    + + +%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 + +%end +
    SensorAktiviertin Betrieb
    {{sns}}{{sac}}{{sru}} +%if sru=='unterbrochen': + +%end +
    +
    diff --git a/pyweb.py b/pyweb.py index b74fcca..c4fa61b 100755 --- a/pyweb.py +++ b/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/') 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(''' +
    +
    +
    +
    +
    + ''') + +@app.post('/test') +def submit_test(): + print(request.forms.get('but')) + q=Queue(maxsize=0) sql_worker=threading.Thread(target=sql_insert,args=(q,))