Hello,
I have incoming bluetooth beacon data as per the below (where the obj array will contain one or more entries depending on the number of beacons that are proximity to the gateway):
{"msg":"advData","gmac":"94A408B02508","obj":
[
{"type":32,"dmac":"BC57290123B5","data1":"0201060DFF530ABC57290123B51A5A0C63","rssi":-44,"time":"2022-10-17 05:48:05"}
]
}
I need to extract the gmac attribute and associate it with the dmac and rssi attributes for each entry in the obj array. The last part of my telegraf config is below which is correctly ingesting the data into a bucket in InfluxDBCloud:
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "json_v2"
tagexclude = ["topic"]
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "a"
timestamp_path = "obj.#.time"
timestamp_format = "unix"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "gmac"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "obj.#.dmac"
[[inputs.mqtt_consumer.json_v2.field]]
path = "obj.#.rssi"
data_type = "integer"
I also need to extract some values from the data1 attribute, where I need to get characters 13 and 14, and 15-16 and then convert them from hexadecimal to integer values and then store these as two separate fields in influxDB.
I started by trying to extract the data1 attribute and store this in influxDB, but I noticed the incoming data was now being split across two tables (I want each entry to have gmac, dmac, rssi, and data1 together):
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "json_v2"
tagexclude = ["topic"]
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "a"
timestamp_path = "obj.#.time"
timestamp_format = "unix"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "gmac"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "obj.#.dmac"
[[inputs.mqtt_consumer.json_v2.field]]
path = "obj.#.rssi"
data_type = "integer"
[[inputs.mqtt_consumer.json_v2.field]]
path = "obj.#.data1"
data_type = "string"
I also tried using the regex processor but found this wasn’t working as I couldn’t see the new batt field in influxDB:
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "json_v2"
tagexclude = ["topic"]
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "a"
timestamp_path = "obj.#.time"
timestamp_format = "unix"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "gmac"
[[inputs.mqtt_consumer.json_v2.tag]]
path = "obj.#.dmac"
[[inputs.mqtt_consumer.json_v2.field]]
path = "obj.#.rssi"
data_type = "integer"
[[processors.regex]]
[[processors.regex.fields]]
key = "obj.#.data1"
pattern = ".{2}$"
result_key = "batt"
Can anyone help me as I’m not sure how to properly combine multiple plugins in my telegraf config or why my first attempt saw data split across two tables?
Many thanks.