Skip to content
Snippets Groups Projects
Commit 1d08ccc4 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Update mqtt2influx.py

parent 5e425682
No related branches found
No related tags found
No related merge requests found
...@@ -28,9 +28,10 @@ def on_connect(client, userdata, flags, rc): ...@@ -28,9 +28,10 @@ def on_connect(client, userdata, flags, rc):
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
loaded_json = json.loads(msg.payload.decode("utf-8")) loaded_json = json.loads(msg.payload.decode("utf-8"))
if("wetterstation" in msg.topic and "SENSOR" in msg.topic): if(msg.topic.split(config[mqtt_server]['subscribe'].split("#")[0])[0] in msg.topic and "SENSOR" in msg.topic):
print("write to influxDB: wetterstation") print("write to influxDB: " + config[influx_server]['database'])
print("Sensor: " + msg.topic.split("/wetterstation/")[1].split("/SENSOR")[0]) client = msg.topic.split(config[mqtt_server]['subscribe'].split("#")[0])[1].split("/SENSOR")[0]
print("Sensor: " + client)
for key in loaded_json.keys(): for key in loaded_json.keys():
if("Unit" not in key and "Time" not in key): if("Unit" not in key and "Time" not in key):
...@@ -46,7 +47,7 @@ def on_message(client, userdata, msg): ...@@ -46,7 +47,7 @@ def on_message(client, userdata, msg):
json_body = [{ json_body = [{
"measurement": "Sensors", "measurement": "Sensors",
"tags": { "tags": {
"client": msg.topic.split("/wetterstation/")[1].split("/SENSOR")[0], "client": client,
"sensor": key "sensor": key
}, },
"fields": fields "fields": fields
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment