Problem getting Integer and float into DB

Hi,
I am quite new to that topic. I am trying since days to sort that out but I can’t find the right syntax.
I have values in my MQTT server:

PWR_MPII = 14
PWR_L1 = 576.7000122070312
PWR_L2 = 466.6000061035156
PWR_L3 = 2283.39990234375
PWR_SB5-1 = 0
PWR_SB5-2 = 0
PWR_SBS5 = 0

Sometimes the L1, L2, L3 values are without decimal points.

So I have integer and float values.

I tried the following code to import them:

[[inputs.mqtt_consumer]]
  name_override = "mqtt_home"
  servers = ["tcp://myip:1883"]
  topics = [
     "victron/PWR_L1",
     "victron/PWR_L2",
     "victron/PWR_L3",
  ]
  qos = 0
  connection_timeout = "60s"
  max_undelivered_messages = 1
  persistent_session = false
  client_id = "telegraf_victron_mqtt"
  username = "xxx"
  password = "xxx"
  data_format = "value"
  data_type = "float"   
  interval = "5s"
    [inputs.mqtt_consumer.tags]
      destination = "Victron_bucket"

[[inputs.mqtt_consumer]]
  name_override = "mqtt_home"
  servers = ["tcp://myip:1883"]
  topics = [
     "victron/PWR_MPII",
     "victron/PWR_SB5-1",
     "victron/PWR_SB5-2",
     "victron/PWR_SBS5",
  ]
  qos = 0
  connection_timeout = "60s"
  max_undelivered_messages = 1
  persistent_session = false
  client_id = "telegraf_victron_mqtt2"
  username = xxx"
  password = "xxx"
  data_format = "value"
  data_type = "integer"   
  interval = "5s"
    [inputs.mqtt_consumer.tags]
      destination = "Victron_bucket"

Unfortunately this still throws errors:

2023-01-20T07:26:09Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T07:26:09Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T07:26:19Z E! [outputs.influxdb_v2] When writing to [http://myip:8086]: 500 Internal Server Error: internal error: unexpected error writing points to database: field type conflict
2023-01-20T07:26:19Z E! [agent] Error writing to outputs.influxdb_v2: failed to send metrics to any configured server(s)
2023-01-20T07:26:29Z E! [outputs.influxdb_v2] Failed to write metric to Victron_bucket (will be dropped: 422 Unprocessable Entity): unprocessable entity: failure writing points to database: partial write: field type conflict: input field "value" on measurement "mqtt_home" is type integer, already exists as type float dropped=1

I tried with type conversion and deleted the data values in the bucket completey - but I don’t get it to work.

Can someone please help me? :slight_smile:

Can we have some sample output?

You just need to write to a file in influx format, or to run telegraf with the --test option which will output the data in the console.

My understanding is that you are writing data from both mqtt inputs in the same measurement (mqtt_home) with the same filed key (value), and a field must have only one datatype (enforced at shard level). Why don’t you just write everything as float?

I don*t know what you mean with output?

If I start it with the --test option, then it shows me:

2023-01-20T10:50:52Z I! Starting Telegraf 1.25.0
2023-01-20T10:50:52Z I! Available plugins: 228 inputs, 9 aggregators, 26 processors, 21 parsers, 57 outputs, 2 secret-stores
2023-01-20T10:50:52Z I! Loaded inputs: mqtt_consumer (2x)
2023-01-20T10:50:52Z I! Loaded aggregators:
2023-01-20T10:50:52Z I! Loaded processors:
2023-01-20T10:50:52Z I! Loaded secretstores:
2023-01-20T10:50:52Z W! Outputs are not used in testing mode!
2023-01-20T10:50:52Z I! Tags enabled: host=srv-lnx-hometools
2023-01-20T10:50:52Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T10:50:52Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]

Everything as float would be ok for me. However, when I try this, he will just skip the integer values.
But if I only have the config with the integer values, then they land in the DB.

I am not writing the same values since that are different keys. But ok, I changes that mqtt_home value in one instance and it worked instantly. Thank you!

So the data type is defined at that level?

let’s pretend a measurement is equivalent to a table in a SQL DB… each column must have a unique name and a datatype…

In InfluxDB the “columns” are tags and fields, tags are string only, fields can have a bunch of datatypes but a single field can only have one… having mixed datatypes is an issue that can happen since this is not enforced globally but by shard, meaning that in the first value inserted (in a new shard) will define that “column” datatype

Thank you for the information :slight_smile: This explains the wasted hours :slight_smile: