How to include timestamp in modbus read out

Hi everyone,

I want to use modbustcp to gather some data from a modbus over tcp server. And I want to attach a timestamp on the output message. Which one is the best solution:

  1. modify the original modbustcp source code. I am not so familiar with the coding. It used some promise and async feature.
  2. modify use injection to add timestamp at both start and end of modbustcp read node and calculate the average timestamp to set the time of msg result.
  3. Is there any internal mechanism to include the timestamp to output result?

How accurate a value do you need? I assume the actual read process will take only fractions of a second, surely you do not need to get the time before and after and take the average.
Would it not be good enough to add a node after the modbus node that adds the timestamp? A function node containing this should do it:

msg.timestamp = new Date()
return msg;

Thanks a lot for your advice.

It cost a little time in my LAN environment though I did not know how to measure it. But I think it is not so important for my application.

Currently I am using a function node to get result from modbustcp node and add msg.time = to the msg because of following reasons:

  1. It is an UTC timestamp in ms precision. It can be write into my influxdb directly without further adjustment;
  2. The timestamp of modbustcp readout do not include delay time from sampling and measurement process of the instrument behind of the modbus tcp server. I still need to calibrate it and align the data. So I just choose a convenient way to add timestamp.

This issue is probably resolved but another neat way to add a timestamp without writing code in a function node is to use a Change node with the Jasonata option.

Jasonata has a couple of easy to use time evaluation functions. I'm not saying this is better than a function node but it does avoid coding and I believe it solves this in one line (one statement). I just tried it with $millis() and it does provide millisecond resolution you are seeking. The Epoch number format can can then be written directly to InfluxDB in this format... See below...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.