2019-07-25 11:34:33 -07:00
|
|
|
from Tkinter import *
|
2019-07-25 00:29:35 -07:00
|
|
|
import numpy as np
|
|
|
|
import os, time,socket,sys,json
|
|
|
|
|
2019-07-25 11:34:33 -07:00
|
|
|
payloads=["wasser","gas","kwh_haus","kwh_herd"]
|
2019-07-25 00:29:35 -07:00
|
|
|
|
|
|
|
def set_date():
|
|
|
|
datafields["date"].delete(0,END)
|
|
|
|
datafields["date"].insert(0,str(round(1000*time.time())))
|
|
|
|
|
|
|
|
def send_data():
|
2019-07-25 11:34:33 -07:00
|
|
|
json_out={"device":socket.gethostname(),"payload":{}}
|
|
|
|
for x in payloads:
|
|
|
|
json_out["payload"][x]={"time":0,"sensor":"rechnung","value":0,"i2c":0}
|
2019-07-25 00:29:35 -07:00
|
|
|
local_time=round(1000*time.time())
|
|
|
|
try:
|
|
|
|
local_time=int(datafields["date"].get())
|
|
|
|
except:
|
|
|
|
local_time=round(1000*time.time())
|
|
|
|
for x in payloads:
|
|
|
|
try:
|
|
|
|
json_out["payload"][x]["value"]=int(datafields[x].get())
|
|
|
|
except:
|
|
|
|
del(json_out["payload"][x])
|
|
|
|
print("kein ",x)
|
|
|
|
else:
|
|
|
|
json_out["payload"][x]["time"]=local_time
|
|
|
|
if len(json_out["payload"])>0:
|
|
|
|
try:
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
except:
|
|
|
|
print("{}: could not connect to database".format(time.time()))
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
s.connect(("banana", 24048))
|
|
|
|
except:
|
|
|
|
print("{}: could not connect to database".format(time.time()))
|
|
|
|
else:
|
|
|
|
s.sendall(json.dumps(json_out))
|
|
|
|
s.close()
|
|
|
|
|
2019-07-25 11:34:33 -07:00
|
|
|
json_out={"device":socket.gethostname(),"payload":{}}
|
|
|
|
for x in payloads:
|
|
|
|
json_out["payload"][x]={"time":0,"sensor":"rechnung","value":0,"i2c":0}
|
2019-07-25 00:29:35 -07:00
|
|
|
|
|
|
|
groot=Tk()
|
|
|
|
groot.wm_title("Hausverbrauch aufnehmen")
|
|
|
|
groot.config(background="#FFFFFF")
|
|
|
|
gframe=Frame(groot,width=400,height=300)
|
|
|
|
gframe.grid(row=0,column=0,padx=10,pady=3)
|
|
|
|
|
|
|
|
button_date=Button(gframe,text="Epoch",bg="#FF0000",width=15,command=set_date)
|
|
|
|
button_date.grid(row=0,column=0,padx=10,pady=3)
|
2019-07-25 11:34:33 -07:00
|
|
|
label_water=Label(gframe,text="Wasserzaehler")
|
2019-07-25 00:29:35 -07:00
|
|
|
label_water.grid(row=1,column=0,padx=10,pady=3)
|
2019-07-25 11:34:33 -07:00
|
|
|
label_gas=Label(gframe,text="Gaszaehler")
|
2019-07-25 00:29:35 -07:00
|
|
|
label_gas.grid(row=2,column=0,padx=10,pady=3)
|
2019-07-25 11:34:33 -07:00
|
|
|
label_electricity=Label(gframe,text="Stromzaehler")
|
2019-07-25 00:29:35 -07:00
|
|
|
label_electricity.grid(row=3,column=0,padx=10,pady=3)
|
2019-07-25 11:34:33 -07:00
|
|
|
label_oven=Label(gframe,text="Stromzaehler Herd")
|
2019-07-25 00:29:35 -07:00
|
|
|
label_oven.grid(row=4,column=0,padx=10,pady=3)
|
|
|
|
|
|
|
|
datafields={}
|
2019-07-25 11:34:33 -07:00
|
|
|
felder=["date","wasser","gas","kwh_haus","kwh_herd"]
|
|
|
|
|
2019-07-25 00:29:35 -07:00
|
|
|
for x in range(len(felder)):
|
|
|
|
datafields[felder[x]]=Entry(gframe,width=18)
|
|
|
|
datafields[felder[x]].grid(row=x,column=1,padx=10,pady=3)
|
|
|
|
|
|
|
|
button_send=Button(gframe,text="Absenden",bg="#00FF00",width=15,command=send_data)
|
|
|
|
button_send.grid(row=5,column=1,padx=10,pady=3)
|
|
|
|
|
|
|
|
datafields["date"].insert(0,str(round(1000*time.time())))
|
2019-07-25 05:33:33 -07:00
|
|
|
|
|
|
|
groot.mainloop()
|