From 1d08ccc4c4c61f8ae1a94e07852347d7f0169bac Mon Sep 17 00:00:00 2001
From: Dennis Eisold <de@itstall.de>
Date: Mon, 27 Jan 2020 18:41:07 +0100
Subject: [PATCH] Update mqtt2influx.py

---
 mqtt2influx.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mqtt2influx.py b/mqtt2influx.py
index 8e14797..7b69802 100644
--- a/mqtt2influx.py
+++ b/mqtt2influx.py
@@ -28,9 +28,10 @@ def on_connect(client, userdata, flags, rc):
 def on_message(client, userdata, msg):
     loaded_json = json.loads(msg.payload.decode("utf-8"))
 
-    if("wetterstation" in msg.topic and "SENSOR" in msg.topic):
-        print("write to influxDB: wetterstation")
-        print("Sensor: " + msg.topic.split("/wetterstation/")[1].split("/SENSOR")[0])
+    if(msg.topic.split(config[mqtt_server]['subscribe'].split("#")[0])[0] in msg.topic and "SENSOR" in msg.topic):
+        print("write to influxDB: " + config[influx_server]['database'])
+        client = msg.topic.split(config[mqtt_server]['subscribe'].split("#")[0])[1].split("/SENSOR")[0]
+        print("Sensor: " + client)
 
         for key in loaded_json.keys():
             if("Unit" not in key and "Time" not in key):
@@ -46,7 +47,7 @@ def on_message(client, userdata, msg):
                 json_body = [{
                     "measurement": "Sensors",
                         "tags": {
-                            "client": msg.topic.split("/wetterstation/")[1].split("/SENSOR")[0],
+                            "client": client,
                             "sensor": key
                         },
                         "fields": fields
-- 
GitLab