Mqtt and string parsing

christianr
Tue, 30 May 2023 12:00:05 +0000
Telegraf

Hello,

I would like to read data from a CNC machine using mqtt. The broker data is not key/value pairs but a comma separated string and depending on the MQTT topic the strings are of different length. E.G.:

200,DMG.PRODUCTION.TIMES.ACT_CYCLE,DEFAULT,16496,s,2023-05-30T13:44:40.246+02:00
400,DMG.TOOL_ACT.NUMBER_1,800,2023-05-30T13:44:17.264+02:00

Using CSV I was able to parse the data, but there are 2 problems:

1. is there any way to define the CSV structure for each MQTT Topic separately? At the moment I create a completely new section for each topic which establishes an additional connection to the broker.

2. it was not possible to parse date and time correctly. When I remove the miliseconds in the date definition, the date is parsed, but is wrong. With the specification of the miliseconds I get the message that the “. cannot be processed as +02:00”.

Many greetings
Christian

3 posts - 2 participants