|
@@ -18,7 +18,7 @@ import os
|
|
|
import re
|
|
|
import configparser
|
|
|
|
|
|
-version = 0.3
|
|
|
+version = 0.4
|
|
|
|
|
|
|
|
|
os.chdir(sys.path[0])
|
|
@@ -36,7 +36,7 @@ devdata = {}
|
|
|
RXcodesToDevFunction_IT = {}
|
|
|
RXcodesToDevFunction_RAW = {}
|
|
|
InTopicsToDevIds = {}
|
|
|
-
|
|
|
+lastDataReceiveTime = time.time()
|
|
|
|
|
|
|
|
|
deviceConfigFile = config['main'].get('devices_config_yml')
|
|
@@ -580,7 +580,11 @@ def encodeInterTechnoRX(itname, cmd):
|
|
|
if debug: log_write(" unknown or invalid IT code '" + rx_code + "'")
|
|
|
|
|
|
def cul_received(payload, source_cul):
|
|
|
- global lastReceivedTime, lastReceivedMaxAge
|
|
|
+ global lastReceivedTime, lastReceivedMaxAge, lastDataReceiveTime
|
|
|
+
|
|
|
+ lastDataReceiveTime = time.time()
|
|
|
+ if debug:
|
|
|
+ print("lastDataReceiveTime=" + str(lastDataReceiveTime))
|
|
|
|
|
|
if payload[:2] == 'is':
|
|
|
pass
|
|
@@ -853,29 +857,40 @@ if mqtt_user is not None and mqtt_password is not None:
|
|
|
mqttc.connect(mqtt_server, mqtt_port, 60)
|
|
|
mqttc.loop_start()
|
|
|
|
|
|
-while True:
|
|
|
- if receive_from_serial_cul:
|
|
|
- serLine = ser.readline()
|
|
|
- if len(serLine) > 0:
|
|
|
- now = int(round(time.time() * 1000))
|
|
|
- recvCmd = serLine.decode('ascii')
|
|
|
- recvCmd = recvCmd.rstrip('\r\n')
|
|
|
+try:
|
|
|
+ while True:
|
|
|
+ if receive_from_serial_cul:
|
|
|
+ serLine = ser.readline()
|
|
|
+ if len(serLine) > 0:
|
|
|
+ now = int(round(time.time() * 1000))
|
|
|
+ recvCmd = serLine.decode('ascii')
|
|
|
+ recvCmd = recvCmd.rstrip('\r\n')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if recvCmd == lastSentCmd and (now - lastSentCmdTime) < filterSelfSentIncomingTimeout:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ if verbose:
|
|
|
+ log_write("")
|
|
|
+ log_write("UART-CUL RX: '" + recvCmd + "'")
|
|
|
+ cul_received(recvCmd, "UART")
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if config['main'].get('dataReceiveTimeout') is not None:
|
|
|
+ if (time.time() - lastDataReceiveTime) >= float(config['main'].get('dataReceiveTimeout')):
|
|
|
+ print("WARNING: received no data from CUL for >" + str(config['main'].get('dataReceiveTimeout')) + "s -> something has gone wrong -> quitting program.")
|
|
|
+ quit()
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- if recvCmd == lastSentCmd and (now - lastSentCmdTime) < filterSelfSentIncomingTimeout:
|
|
|
- pass
|
|
|
- else:
|
|
|
- if verbose:
|
|
|
- log_write("")
|
|
|
- log_write("UART-CUL RX: '" + recvCmd + "'")
|
|
|
- cul_received(recvCmd, "UART")
|
|
|
|
|
|
- sleep(0.05)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ sleep(0.05)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+except KeyboardInterrupt:
|
|
|
+ print("\n")
|