Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans IJntema committed Apr 15, 2023
1 parent 523e928 commit d527258
Show file tree
Hide file tree
Showing 6 changed files with 661 additions and 615 deletions.
25 changes: 14 additions & 11 deletions kamstrup-mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
v1.1.0
- update for mqtt lib v5
"""

__version__ = "1.0.2"
__version__ = "1.1.0"
__author__ = "Hans IJntema"
__license__ = "GPLv3"

Expand Down Expand Up @@ -118,15 +120,16 @@ def main():
t_mqtt_stopper = threading.Event()

# MQTT thread
t_mqtt = mqtt.mqttclient(cfg.MQTT_BROKER,
cfg.MQTT_PORT,
cfg.MQTT_CLIENT_UNIQ,
cfg.MQTT_RATE,
cfg.MQTT_QOS,
cfg.MQTT_USERNAME,
cfg.MQTT_PASSWORD,
t_mqtt_stopper,
t_threads_stopper)
t_mqtt = mqtt.MQTTClient(mqtt_broker=cfg.MQTT_BROKER,
mqtt_port=cfg.MQTT_PORT,
mqtt_client_id=cfg.MQTT_CLIENT_UNIQ,
mqtt_qos=cfg.MQTT_QOS,
mqtt_cleansession=True,
mqtt_protocol=mqtt.MQTTv5,
username=cfg.MQTT_USERNAME,
password=cfg.MQTT_PASSWORD,
mqtt_stopper=t_mqtt_stopper,
worker_threads_stopper=t_threads_stopper)

# List of kamstrup.TaskReadHeatMeter objects
list_of_heatmeters = list()
Expand Down Expand Up @@ -156,7 +159,7 @@ def main():

# Set MQTT status to online and publish SW version of MQTT parser
t_mqtt.set_status(cfg.MQTT_TOPIC_PREFIX + "/status", "online", retain=True)
t_mqtt.do_publish(cfg.MQTT_TOPIC_PREFIX + "/sw-version", f"main={__version__};mqtt={mqtt.__version__}", retain=True)
t_mqtt.do_publish(cfg.MQTT_TOPIC_PREFIX + "/sw-version", f"main={__version__}; mqtt={mqtt.__version__}", retain=True)

# block till last TaskReadHeatMeter thread stops receiving telegrams/exits
for i in range(len(cfg.MBUS_KAMSTRUP_DEVICES)):
Expand Down
6 changes: 6 additions & 0 deletions log/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . log import logger


__version__ = "1.2.0"
__author__ = "Hans IJntema"
__license__ = "GPLv3"
51 changes: 25 additions & 26 deletions log.py → log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
script=os.path.splitext(script)[0]
logger = logging.getLogger(script + "." + __name__)
====================================================================
V1.2.0
11-4-2023
Restructering directory; __init__.py; no code change
V1.1.0
31-10-2021
Expand All @@ -30,7 +33,6 @@
V0.1:
- initial version
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -48,48 +50,45 @@
"""

__version__ = "1.1.0"
__author__ = "Hans IJntema"
__license__ = "GPLv3"



# ------------------------------------------------------------------------------------
# Logging
# ------------------------------------------------------------------------------------
import __main__
import logging
from logging.handlers import SysLogHandler
from logging.handlers import SysLogHandler
import os
import sys
import getpass


currentuser = getpass.getuser()

script=os.path.basename(__main__.__file__)
script=os.path.splitext(script)[0]
script = os.path.basename(__main__.__file__)
script = os.path.splitext(script)[0]

logger = logging.getLogger(script)

# This setLevel determines wich messages are passed on to lower handlers
# This setLevel determines which messages are passed on to lower handlers
logger.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, CRITICAL
logger.propagate = False

# Console stdout
c_handler = logging.StreamHandler(sys.stdout)
# This setLevel determines wich messages are processed by this handler (assuming it arrives from global logger
# This setLevel determines wich messages are processed by this handler (assuming it arrives from global logger)
c_handler.setLevel(logging.DEBUG)
c_format = logging.Formatter('%(name)s %(levelname)s: FUNCTION:%(funcName)s LINE:%(lineno)d: %(message)s')
c_handler.setFormatter(c_format)
logger.addHandler(c_handler)

# Syslog
if sys.platform == "linux":
s_handler = logging.handlers.SysLogHandler( address=('/dev/log') )
# This setLevel determines wich messages are processed by this handler (assuming it arrives from global logger
s_handler = logging.handlers.SysLogHandler(address='/dev/log')
# This setLevel determines which messages are processed by this handler (assuming it arrives from global logger)
s_handler.setLevel(logging.INFO)
s_format = logging.Formatter('%(name)s[%(process)d] %(levelname)s: %(asctime)s FUNCTION:%(funcName)s LINE:%(lineno)d: %(message)s', datefmt='%H:%M:%S')
s_format = logging.Formatter('%(name)s[%(process)d] %(levelname)s: '
'%(asctime)s FUNCTION:%(funcName)s LINE:%(lineno)d: %(message)s',
datefmt='%H:%M:%S')
s_handler.setFormatter(s_format)
logger.addHandler(s_handler)

Expand All @@ -103,17 +102,17 @@
f_handler = logging.FileHandler(f"/tmp/{script}.{currentuser}.log", 'a')

f_handler.setLevel(logging.ERROR)
f_format = logging.Formatter('%(name)s[%(process)d] %(levelname)s: %(asctime)s FUNCTION:%(funcName)s LINE:%(lineno)d: %(message)s', datefmt='%Y-%m-%d,%H:%M:%S')
f_format = logging.Formatter('%(name)s[%(process)d] %(levelname)s: '
'%(asctime)s FUNCTION:%(funcName)s LINE:%(lineno)d: %(message)s',
datefmt='%Y-%m-%d,%H:%M:%S')
f_handler.setFormatter(f_format)
logger.addHandler(f_handler)
except:
print(f"ERROR: /dev/shm/{script}.log permission denied")

#logger.debug('This is a debug message')
#logger.info('This is an info message')
#logger.warning('This is a warning message')
#logger.error('This is an error message')
#logger.critical('This is a critical message')
#logger.exception("Exception occurred")


except Exception as e:
print(f"Exception {e}: /dev/shm/{script}.log permission denied")

# logger.debug('This is a debug message')
# logger.info('This is an info message')
# logger.warning('This is a warning message')
# logger.error('This is an error message')
# logger.critical('This is a critical message')
# logger.exception("Exception occurred")
Loading

0 comments on commit d527258

Please sign in to comment.