diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/.env b/.env index dbeea4a..9caf140 100644 --- a/.env +++ b/.env @@ -4,4 +4,4 @@ KNX_TOPOLOGY=export-addresses.csv INFLUX_BUCKET=my_bucket INFLUX_ORG=example.com INFLUX_TOKEN=change_me -INFLUX_URL=http://localhost:8086 \ No newline at end of file +INFLUX_URL=http://10.0.0.27:40086 \ No newline at end of file diff --git a/.gitignore b/.gitignore index d0877b7..6ff67dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ venv/ requirements/ -__py*/ \ No newline at end of file +__py*/ +.env +./*.csv \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 42d7d08..19ec8df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,12 +15,8 @@ ENV INFLUX_TOKEN=change_me ENV INFLUX_URL=http://localhost:8086 COPY ./*.py /code/knx -COPY ./.env /code/knx +COPY ./defaults/.env /code/knx +COPY ./defaults/export-addresses.csv /code/knx - -ENV CONFIG_STRUCTURE=/code/data/export-addresses.csv - -VOLUME ["/code/data/export-addresses.csv", "/code/knx/.env"] - - -CMD ["python", "knx_monitor.py"] \ No newline at end of file +CMD ["python", "knx_monitor.py"] +# CMD ["ls", "-lsrtaR"] \ No newline at end of file diff --git a/db.py b/db.py index e5a15ab..dbcc18c 100644 --- a/db.py +++ b/db.py @@ -3,6 +3,7 @@ from influxdb_client.client.write_api import SYNCHRONOUS from dotenv import load_dotenv import os +from os.path import dirname, join dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) @@ -16,5 +17,9 @@ write_api = client.write_api(write_options=SYNCHRONOUS) def publish_measurement(value): - p = influxdb_client.Point(f'KNX-{value["type"]}').tag("name", f'{value["name"]}').tag("destination", f'{value["destination"]}').tag("description", f'{value["description"]}').field("value", value["value"]) - write_api.write(bucket=bucket, org=org, record=p) \ No newline at end of file + try: + p = influxdb_client.Point(f'KNX-{value["type"]}').tag("name", f'{value["name"]}').tag("destination", f'{value["destination"]}').tag("description", f'{value["description"]}').field("value", value["value"]) + write_api.write(bucket=bucket, org=org, record=p) + except Exception as e: + print(f"Could not send value {value} to {url}") + print(e) \ No newline at end of file diff --git a/defaults/export-addresses.csv b/defaults/export-addresses.csv new file mode 100644 index 0000000..d6975a2 --- /dev/null +++ b/defaults/export-addresses.csv @@ -0,0 +1 @@ +"Group name";"Address";"Central";"Unfiltered";"Description";"DatapointType";"Security" \ No newline at end of file diff --git a/export-addresses-guest-12-12.csv b/export-addresses.csv similarity index 100% rename from export-addresses-guest-12-12.csv rename to export-addresses.csv diff --git a/knx_monitor.py b/knx_monitor.py index 61fc896..38fffa2 100644 --- a/knx_monitor.py +++ b/knx_monitor.py @@ -3,6 +3,8 @@ import asyncio import getopt import sys +import os +from os.path import dirname, join from xknx import XKNX from xknx.io import ConnectionConfig, ConnectionType from xknx.telegram import AddressFilter @@ -18,9 +20,6 @@ from db import publish_measurement config = {} mapping = {} - - - async def telegram_received_cb(telegram): """Do something with the received telegram.""" val = parse_message(config, mapping, telegram) diff --git a/structure.py b/structure.py index c78a649..b670f26 100644 --- a/structure.py +++ b/structure.py @@ -56,6 +56,7 @@ def init_value_mapping(): def load_structure(filename): + print(f"Configuration file: {filename}") config = {} with open(filename, newline='') as csvFile: line = 0 @@ -98,6 +99,7 @@ def parse_message(structure, mapping, telegram): if __name__ == '__main__': + from os.path import dirname, join from dotenv import load_dotenv dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path)