I have a device that publishes both floating-point sensor values and “status” strings via MQTT. I have configured Telegraf to subscribe to these topics, however I’ve had to add two separate instances of the MQTT Consumer plugin in order to handle the different types of data formats:
[[inputs.mqtt_consumer]] servers = ["mosquitto:1883"] qos = 0 topics = [ "mydevice/#" ] data_format = "value" data_type = "float" [[inputs.mqtt_consumer]] name_override = "mqtt_consumer_string" servers = ["mosquitto:1883"] qos = 0 topics = [ "mydevice/#" ] data_format = "value" data_type = "string"
This results in duplicate data in InfluxDB, because some topics are caught by both consumers and written to the database. The topics for values that are actual strings never appear in the mqtt_consumer measurement, but the topics for float values do appear in the mqtt_consumer_string measurement, as strings.
Apart from creating a list of explicit topics, is there a better way to do this? Or does the data agnostic nature of MQTT mean that there’s no way for Telegraf to know whether a topic is a float or a string (does MQTT not have a data type field?), and having two consumers (one for float topics, one for string topics) is the only way to deal with this?
Alternatively, what if I collected all my data as strings? Will InfluxDB (and downstream services like Grafana) interpret those values as numerical, or will I need to convert them (e.g. Kapacitor TICKscript)?