Parsing an array from mqtt topic

I have a go-eCharger that can be managed also with MQTT.
Two of the topics it send are arrays such as:

go-eCharger/201397/nrg = [233.74,2.48,3.41,1.24,0,0,0,0,0,0,0,0,0,0,0,0]
go-eCharger/201397/tma = [35.5,30.5]

No I am able to parse the fields in new keys t1 and t2 with:

  [[inputs.mqtt_consumer.topic_parsing]]
    topic = "go-eCharger/+/+"
    measurement = "measurement/_/_"
    tags = "_/chargerid/field"

  [[processors.regex]]
    [[processors.regex.fields]]
      key = "value"
      pattern = '^\[(\d+\.?\d*),(\d+\.?\d*)\]$'
      replacement = "${1}"
      result_key = "t1"

    [[processors.regex.fields]]
      key = "value"
      pattern = '^\[(\d+\.?\d*),(\d+\.?\d*)\]$'
      replacement = "${2}"
      result_key = "t2"

  [[processors.converter]]
    [processors.converter.fields]
      float = ["t1", "t2"]

However that result the new values to be strings, when running telegraf --test for the configuration.

> go-eCharger,chargerid=201397,host=pi.oh2th.fi t1="35.5",t2="30",tma="[35.5,30]" 1663598657338594386

How can I make sure that the result_keys would be float? Even with the converter but that does not change anything for the result.

I would immediately going to suggest the converter. Did you set an order to your processors when you used that? Was there some sort of error message that showed up?

Found the bug in the configuration:
key = "value"
should have of course been
key = "tma"

1 Like

Hi oh2th,
hope you’re reading this after such a long time :slight_smile:
Is it possible to publish your telegraf config? With my config I get error “must be an object”

I have that in Github
https://github.com/oh2th/fi.oh2th.pi-telegraf.conf

1 Like

Do you have another URL for me?

Please try the same url again

1 Like

@oh2th did you try to use the xpath_json parser to parse the payload?