diff --git a/mqtt2influx.py b/mqtt2influx.py index 8e14797ef13400e73cf546642fafd0a15ddaf4cf..7b698025f93a6ca459d2d8722238729a407d7750 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