-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserviceReport.py
49 lines (35 loc) · 1.34 KB
/
serviceReport.py
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
import paho.mqtt.publish as mqtt_publish
import json
import time
# external files/classes
import settings
# System check
ACTION_NOTHING = 0
ACTION_RESTART = 1
checkMsg = 'OK'
checkFail = False
checkAction = ACTION_NOTHING
checkReport = {}
def current_sec_time():
return int(round(time.time()))
systemWatchTimer = current_sec_time()
# Called by mqtt
def on_message_check(client, userdata, msgJson):
if (current_sec_time() - systemWatchTimer) > 300:
sendCheckReportToHomeLogic(True, ACTION_RESTART, "Timeout systemWatchTimer, 5 min no activity in serialPortThread-thread loop")
else:
# print("on_message_check: " + msgJson.topic + ": " + str(msgJson.payload))
sendCheckReportToHomeLogic(checkFail, checkAction, checkMsg)
# Send the report to the Home Logic system checker
def sendCheckReportToHomeLogic(fail, action, msg):
global checkMsg
global checkFail
checkMsg = msg
checkFail = fail
checkReport['checkFail'] = checkFail
checkReport['checkAction'] = checkAction
checkReport['checkMsg'] = checkMsg
mqtt_publish.single(settings.MQTT_TOPIC_REPORT, json.dumps(checkReport), qos=1, hostname=settings.MQTT_ServerIP)
# Don't wait for the Home Logic system checker, report it directly
def sendFailureToHomeLogic(_checkAction, _checkMsg):
sendCheckReportToHomeLogic(True, _checkAction, _checkMsg)