Help for a newbie formating PLC inputs

Sorry for posting this, I feel a bit ashamed. I'm an absolute newbie to node-red, and I cannot find how to do something that I assume should be quite easy to do. I want to read several inputs from an external device (a Siemens S7 PLC). I managed to do that and it's working. I am also writing some values in MQTT broker.

But the problem I am trying to solve is the following one: I wan't to format these inputs, naming them with a fix name (different for each input), and adding a timestamp for each input (It can be the same), and then pack all the lines in a message before sending to the MQTT broker.

And the truth is that I am not being able to even format just one input. I don't find the way to go on with this.

Any advice? Or any place that I can find information that could help me?

Many thanks in advance.

I would start by reading the node red docs page Working with Messages which may give you some clues.
What do you mean names? Do you mean properties in an object?
You say you want to publish the data to MQTT, do you know what you want the message to look like in MQTT?

Thanks for your reply Colin. I'll try to explain better (excuse me, because I know I need to improve my English) with an example:

  • Let's assume that the input value is 10.
  • I would like to write something like "Temperature=" 10.
  • And then add the timestap.

I will read again the page you suggested. Thank you so much!

For sending to MQTT you would probably be better not to do that. You would be better to send it as an object, something like {timestamp: 1234567890, temperature: 10). Then it is much easier to decode at the other end. So if it is picked up in node red again then you would be able to reference the values as msg.payload.timestamp and msg.payload.temperature.
If that isn't what you want to do then tell us what is happening to the data.

1 Like

Hi Colin, thank you so much for your message. At last I did it like you mentioned, and it's working fine. I've spent some time working around, and now I think that I understand how this is intended to work. Once you understand it, is quite easy to manage the data.

Thank you so much

1 Like