|
@@ -42,6 +42,7 @@ lastDataReceiveTime = time.time()
|
|
deviceConfigFile = config['main'].get('devices_config_yml')
|
|
deviceConfigFile = config['main'].get('devices_config_yml')
|
|
|
|
|
|
log_enable = config['main'].getboolean('log_enable')
|
|
log_enable = config['main'].getboolean('log_enable')
|
|
|
|
+logSuccessfulCommands = config['main'].getboolean('logSuccessfulCommands')
|
|
log_path = config['main'].get('log_path')
|
|
log_path = config['main'].get('log_path')
|
|
if not os.path.exists(log_path):
|
|
if not os.path.exists(log_path):
|
|
os.makedirs(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
|
|
log_last_date = None
|
|
logfilehandle = False
|
|
logfilehandle = False
|
|
|
|
|
|
-
|
|
|
|
def log_start():
|
|
def log_start():
|
|
global logfilehandle, log_last_date
|
|
global logfilehandle, log_last_date
|
|
if log_enable:
|
|
if log_enable:
|
|
@@ -132,7 +132,7 @@ def log_start():
|
|
|
|
|
|
try:
|
|
try:
|
|
_log_current_date = strftime("%Y%m%d")
|
|
_log_current_date = strftime("%Y%m%d")
|
|
- _logfilename = _log_current_date + ".log"
|
|
|
|
|
|
+ _logfilename = _log_current_date + "_debug.log"
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
log_last_date = _log_current_date
|
|
log_last_date = _log_current_date
|
|
except:
|
|
except:
|
|
@@ -147,12 +147,12 @@ def log_rotate():
|
|
if log_last_date != _log_current_date:
|
|
if log_last_date != _log_current_date:
|
|
try:
|
|
try:
|
|
logfilehandle.close()
|
|
logfilehandle.close()
|
|
- _logfilename = _log_current_date + ".log"
|
|
|
|
|
|
+ _logfilename = _log_current_date + "_debug.log"
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
logfilehandle = open(log_path + '/' + _logfilename, 'a')
|
|
log_last_date = _log_current_date
|
|
log_last_date = _log_current_date
|
|
except:
|
|
except:
|
|
pass
|
|
pass
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
def log_write(_msg):
|
|
def log_write(_msg):
|
|
global logfilehandle
|
|
global logfilehandle
|
|
@@ -165,8 +165,59 @@ def log_write(_msg):
|
|
except:
|
|
except:
|
|
# guat dann hoit ned...
|
|
# guat dann hoit ned...
|
|
pass
|
|
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()
|
|
log_start()
|
|
|
|
+logSC_start()
|
|
|
|
|
|
log_write("CUL2MQTT v" + str(version))
|
|
log_write("CUL2MQTT v" + str(version))
|
|
log_write("=====================================")
|
|
log_write("=====================================")
|
|
@@ -374,7 +425,10 @@ def publish_device_statusupdate(device, cmd, value):
|
|
else:
|
|
else:
|
|
if verbose: log_write(" MQTT publish: '" + cmd + "' -> '" + statTopic + "'")
|
|
if verbose: log_write(" MQTT publish: '" + cmd + "' -> '" + statTopic + "'")
|
|
mqttc.publish(statTopic, cmd, qos=0, retain=False)
|
|
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 'add_statTopics_on' in devdata[device].keys():
|
|
if verbose: log_write(" MQTT publish add_statTopics_on:")
|
|
if verbose: log_write(" MQTT publish add_statTopics_on:")
|
|
for res in devdata[device].get('add_statTopics_on'):
|
|
for res in devdata[device].get('add_statTopics_on'):
|