Hi ,
I would like to connect telegraph to a mosquitto broker by subscribing to the topic “+/update/#”.
This is how the received message look like
topic: 02000001000047F9/update/zb/dev/6/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00[Europe/Copenhagen]","value":34.0}
topic: 02000001000047F9/update/zb/dev/6/ldev/temperature/data/temperature
message: {"key":"temperature","name":"Measured Temperature","type":"double","unit":"°C","access":"r","lastUpdated":"2019-01-09T15:32:31.921+01:00[Europe/Copenhagen]","value":26.0}
topic: 02000001000047F9/update/zb/dev/1/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00[Europe/Copenhagen]","value":34.0}
topic: 02000001000047F9/update/zb/dev/1/ldev/temperature/data/temperature
message: {"key":"temperature","name":"Measured Temperature","type":"double","unit":"°C","access":"r","lastUpdated":"2019-01-09T15:32:31.921+01:00[Europe/Copenhagen]","value":26.0}
The topic name keeps on changing based on the device (1/2/3/…) , ldev (temperature/humidity/voc/…), data(temperature/humidity/voc/…). Hence i would like to parse the topic name into the metrics field for example
topic: 02000001000047F9/update/zb/dev/6/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00","value":34.0}
After conversion it should look like this.
measurement: humidity
tags: "id": "6", "data" : "humidity"
fields: "humidity" : 34.0
Going through the documentation, i understood the dataflow go like this “MQTT Consumer Input Plugin” → " Input Data Formats" → JSON But i am not sure how achieve the above conversion from topic name to the measurement and tags fields.
Thanks .