MQTT Telegraf JSON - trailing NULL character - payload parsing problem

Hello All,

following input quasi JSON:
‘{“TimeStamp”:1679156093057,“WorkCenter”:“MyPlant1”,“PlantCode”:“4183”,“LineName”:“Line001”,“MachineName”:“AssemblerNo1”,“StationName”:“10N1”,“DeviceName”:“HardStop”,“TagName”:“ExtCmd_T”,“Value”:50,“Anomaly”:0,“AvgWindow”:50.0,“StdWindow”:0.0} NULL’

as you can see last character in this string is NULL which is produced by PLC. I can’t get rid of it.

Now how can I convert this in fact non-JSON into valid line protocol for InfluxDB ver2.0?

How to parse tags and fields from payload (not topic) os this JSON?
How to create measurement name as hard-coded name (not parsed from topic or payload) ?

I tried many configurations and read all topics in internet.
There is no clear documentation with examples how to handle such issue.

What I found is:

So probably parsing the non-Json from string to valid JSON is needed. But I use InfluxDB >=2.0
I used also docker.

Here is my telegraf.conf:

[agent]
  interval = "1s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = true

##############################################################################
[[inputs.mqtt_consumer]]
  servers = ["tcp://MQTT_Broker:1883"]
  topics = ["PPS_L1/AssemblerNo1/10N1/HardStop/ExtCmd_T"]
  username = "mqttbroker"
  password = "LoopEdge.123"

  #data_format = "json"
  ##data_format = "influx"
  data_format = "value"
  data_type = "string"
  #data_format = "json_v2"
  topic_tag = ""

  [[inputs.mqtt_consumer.json_v2]]
    measurement_name = "measurement1"
    timestamp_path = "TimeStamp"
    timestamp_format = "unix"
    [[inputs.mqtt_consumer.json_v2.tag]]
      path = "LineName"

    [[inputs.mqtt_consumer.json_v2.field]]
      path = "Value"
      type = "float"

    [[inputs.mqtt_consumer.json_v2.field]]
      path = "AvgWindow"
      type = "float"


###############################################################################
[[processors.parser]]
 parse_fields = ["Value", "Anomaly", "AvgWindow"]
 parse_tags = ["LineName", "MachineName"]

 merge = "override"
 data_format = "json"

###############################################################################
[[outputs.influxdb_v2]]
  urls = ["http://InfluxDB:8086"]
  token = "firToJO9jjn0USZfpmAg5RfU5-R5BCKYjDFHNL8j3oI3VmVAjEQxLmPRq3uGzQw5w6t8PuBGy-A5KRzjv_7EBA=="
  organization = "Company"
  namepass = ["measurement1"]
  bucket = "BUCKET_TEST"

So please, please any hint and clear answers with vallid telegraf.conf file are appreciated.

Regards
Tom

Hello @Tom999,
I like to use the --test flag to see what the resulting line protocol looks like and then fix my config based off of that.
As well as setting debug=true in the agent portion of the config.

Can you please use that and share the output?

OK, I managed to fix it on the PLC level to send valid JSON.
Thank you.