|
@@ -42,6 +42,7 @@ lastDataReceiveTime = time.time()
|
|
|
deviceConfigFile = config['main'].get('devices_config_yml')
|
|
|
|
|
|
log_enable = config['main'].getboolean('log_enable')
|
|
|
+logSuccessfulCommands = config['main'].getboolean('logSuccessfulCommands')
|
|
|
log_path = config['main'].get('log_path')
|
|
|
if not os.path.exists(log_path):
|
|
|
os.makedirs(log_path)
|
|
@@ -123,7 +124,6 @@ yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, no_duplicat
|
|
|
log_last_date = None
|
|
|
logfilehandle = False
|
|
|
|
|
|
-
|
|
|
def log_start():
|
|
|
global logfilehandle, log_last_date
|
|
|
if log_enable:
|
|
@@ -132,7 +132,7 @@ def log_start():
|
|
|
|
|
|
try:
|
|
|
_log_current_date = strftime("%Y%m%d")
|
|
|
- _logfilename = _log_current_date + ".log"
|
|
|
+ _logfilename = _log_current_date + "_debug.log"
|
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
|
log_last_date = _log_current_date
|
|
|
except:
|
|
@@ -147,12 +147,12 @@ def log_rotate():
|
|
|
if log_last_date != _log_current_date:
|
|
|
try:
|
|
|
logfilehandle.close()
|
|
|
- _logfilename = _log_current_date + ".log"
|
|
|
+ _logfilename = _log_current_date + "_debug.log"
|
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
|
log_last_date = _log_current_date
|
|
|
except:
|
|
|
pass
|
|
|
-
|
|
|
+
|
|
|
|
|
|
def log_write(_msg):
|
|
|
global logfilehandle
|
|
@@ -165,8 +165,59 @@ def log_write(_msg):
|
|
|
except:
|
|
|
# guat dann hoit ned...
|
|
|
pass
|
|
|
+
|
|
|
+
|
|
|
+# Log successfully received (known) codes
|
|
|
+
|
|
|
+logSC_last_date = None
|
|
|
+logSCfilehandle = False
|
|
|
+
|
|
|
+def logSC_start():
|
|
|
+ global logSCfilehandle, logSC_last_date
|
|
|
+ if logSuccessfulCommands:
|
|
|
+ if not os.path.exists(log_path):
|
|
|
+ os.makedirs(log_path)
|
|
|
+
|
|
|
+ try:
|
|
|
+ _log_current_date = strftime("%Y%m%d")
|
|
|
+ _logfilename = _log_current_date + "_received.log"
|
|
|
+ logSCfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
|
+ logSC_last_date = _log_current_date
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+def logSC_rotate():
|
|
|
+ global logSCfilehandle, logSC_last_date
|
|
|
+ if logSuccessfulCommands:
|
|
|
+ _log_current_date = strftime("%Y%m%d")
|
|
|
+
|
|
|
+ if logSC_last_date != _log_current_date:
|
|
|
+ try:
|
|
|
+ logSCfilehandle.close()
|
|
|
+ _logfilename = _log_current_date + "_received.log"
|
|
|
+ logSCfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
|
+ logSC_last_date = _log_current_date
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+def logSC_write(_msg):
|
|
|
+ global logSCfilehandle
|
|
|
+ if not quiet: print(_msg)
|
|
|
+ log_rotate()
|
|
|
+ if logSuccessfulCommands:
|
|
|
+ try:
|
|
|
+ logSCfilehandle.write("[" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + "] " + _msg + "\n")
|
|
|
+ logSCfilehandle.flush()
|
|
|
+ except:
|
|
|
+ # guat dann hoit ned...
|
|
|
+ pass
|
|
|
+
|
|
|
+###
|
|
|
|
|
|
log_start()
|
|
|
+logSC_start()
|
|
|
|
|
|
log_write("CUL2MQTT v" + str(version))
|
|
|
log_write("=====================================")
|
|
@@ -374,7 +425,10 @@ def publish_device_statusupdate(device, cmd, value):
|
|
|
else:
|
|
|
if verbose: log_write(" MQTT publish: '" + cmd + "' -> '" + statTopic + "'")
|
|
|
mqttc.publish(statTopic, cmd, qos=0, retain=False)
|
|
|
-
|
|
|
+
|
|
|
+ if logSuccessfulCommands:
|
|
|
+ logSC_write("received from device: " + device + ", cmd: " + cmd + ", value: " + str(value) + ", topic: " + statTopic)
|
|
|
+
|
|
|
if 'add_statTopics_on' in devdata[device].keys():
|
|
|
if verbose: log_write(" MQTT publish add_statTopics_on:")
|
|
|
for res in devdata[device].get('add_statTopics_on'):
|