|
@@ -24,6 +24,10 @@ import math
|
|
# Change working dir to the same dir as this script
|
|
# Change working dir to the same dir as this script
|
|
os.chdir(sys.path[0])
|
|
os.chdir(sys.path[0])
|
|
|
|
|
|
|
|
+
|
|
|
|
+# stop program if nothing is received from JeeLink for 5 min (will be restarted by systemd)
|
|
|
|
+serialReceived_maxAge = 300
|
|
|
|
+
|
|
config = configparser.ConfigParser()
|
|
config = configparser.ConfigParser()
|
|
config.read('jeelinklog.ini')
|
|
config.read('jeelinklog.ini')
|
|
|
|
|
|
@@ -293,6 +297,9 @@ ser = serial.Serial(port=serialport,
|
|
|
|
|
|
|
|
|
|
checkLastUpdateInterval_lastRun = time.time() # first check after timeout expired
|
|
checkLastUpdateInterval_lastRun = time.time() # first check after timeout expired
|
|
|
|
+
|
|
|
|
+# set serialReceivedLastTime to current time so that we can detect if nothing is received for some time
|
|
|
|
+serialReceivedLastTime = int(time.time())
|
|
|
|
|
|
try:
|
|
try:
|
|
while True:
|
|
while True:
|
|
@@ -311,6 +318,10 @@ try:
|
|
|
|
|
|
if(serLine):
|
|
if(serLine):
|
|
if serLine.find('OK 9') != -1:
|
|
if serLine.find('OK 9') != -1:
|
|
|
|
+
|
|
|
|
+ # set serialReceivedLastTime to current time so that we can detect if nothing is received for some time
|
|
|
|
+ serialReceivedLastTime = int(time.time())
|
|
|
|
+
|
|
if verbosemode:
|
|
if verbosemode:
|
|
print(serLine + " = LaCrosse sensor")
|
|
print(serLine + " = LaCrosse sensor")
|
|
|
|
|
|
@@ -1124,6 +1135,13 @@ try:
|
|
|
|
|
|
# handle outdated sensor values once a minute
|
|
# handle outdated sensor values once a minute
|
|
if (int(time.time()) - checkLastUpdateInterval_lastRun) > checkLastUpdateInterval:
|
|
if (int(time.time()) - checkLastUpdateInterval_lastRun) > checkLastUpdateInterval:
|
|
|
|
+
|
|
|
|
+ # exit program if nothing has been received from JeeLink for 5 min - will be restarted by systemd
|
|
|
|
+ now = int(time.time())
|
|
|
|
+ if (now - serialReceivedLastTime) > serialReceived_maxAge:
|
|
|
|
+ print("Nothing received from JeeLink for " + str(now - serialReceivedLastTime) + "s - there is something wrong. Exiting program so that it will be restarted by systemd.")
|
|
|
|
+ quit()
|
|
|
|
+
|
|
checkLastUpdateInterval_lastRun = int(time.time())
|
|
checkLastUpdateInterval_lastRun = int(time.time())
|
|
#print("check lastUpdate")
|
|
#print("check lastUpdate")
|
|
for key in sensors_yaml:
|
|
for key in sensors_yaml:
|