-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
142 lines (114 loc) · 3.59 KB
/
Copy pathmain.py
File metadata and controls
142 lines (114 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/local/bin/python
from mqtt import Mqtt
#from frame import Frame
from tkFrame import tkFrame
from config import Config
import thread
import time
import Queue
#import wx
import json
from datetime import datetime
from update import Update
from Tkinter import *
# =======Debug
# import pydevd
# pydevd.settrace('192.168.20.218', port=12345, stdoutToServer=True, stderrToServer=True)
# =======end
global queue
# queue = Queue.Queue()
queue = Queue.Queue(maxsize=12) # maxsize=0 infinite queue size
def mqttConnect():
m = Mqtt(queue, con)
m.connect()
def display():
while True:
time.sleep(3)
try:
data = queue.get(False)
temp = str(data['Temperature']) + ' C'
deviceId = str(data['DeviceId'])
localtime = str(data['localtime'])
frame.UpdateLabel(temp, deviceId, localtime)
quenefull = queue.full()
print("Return True if the queue is full, False otherwise. ", quenefull)
quenesize = queue.qsize()
print("Return the approximate size of the queue. ", quenesize)
queueempty = queue.empty()
print("Return True if the queue is empty, False otherwise. ", queueempty)
print("\n")
except Queue.Empty:
data = 'empty'
def verifyAlarm():
while True:
time.sleep(100)
for d in data:
verifyTimeElapsed(d)
verifyMinMaxTemp(d)
def verifyTimeElapsed(d):
print("verify time ...")
if frame.getLabelTime(str(d)):
try:
timeLabel = frame.getLabelTime(str(d))
timeNow = time.ctime(time.time())
tdelta = datetime.strptime(timeNow, "%a %b %d %H:%M:%S %Y") - datetime.strptime(str(timeLabel), "%a %b %d %H:%M:%S %Y")
print(timeLabel)
print(timeNow)
print(tdelta.seconds)
print(int(con.getTimeNoData()))
if tdelta.seconds > int(con.getTimeNoData()):
frame.errorLabel(d)
except ValueError:
print('valore sbagliato ' + frame.getLabelTime(str(d)))
def verifyMinMaxTemp(d):
if d in maxTemp:
if frame.getLabelTemperature(str(d)):
tempLabel = frame.getLabelTemperature(str(d))
val = 0.0
mt = 0.0
try:
val = float(tempLabel[:-2])
mt = float(maxTemp[d])
except ValueError:
pass
if val > mt:
frame.redLabel(d)
else:
frame.normalLabel(d)
def updateConfig():
while True:
time.sleep(10000)
updt = Update()
updt.getConfigFile()
con.reloadFile()
# def showApp():
# global frame
# app = wx.App(False)
# frame = Frame(None)
# frame.Show(True)
# app.MainLoop()
def showApp():
global frame
root = Tk()
frame = tkFrame(root)
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes("-fullscreen", True) # True
# root.geometry('800x600')
root.columnconfigure(0, weight=1)
root.mainloop()
def loadConfig():
data = con.getConfigDevice()
if __name__ == "__main__":
global data, con, maxTemp
con = Config()
data = con.getConfigDevice()
maxTemp = con.getMaxTemp()
try:
thread.start_new_thread(mqttConnect, ())
thread.start_new_thread(display, ())
thread.start_new_thread(verifyAlarm, ())
thread.start_new_thread(updateConfig, ())
except:
print("Error: unable to start thread")
showApp()