# MODBUS timestamp

**URL:** <https://discourse.nodered.org/t/modbus-timestamp/89122>\
**Category:** General\
**Created:** [30 June 2024 19:32 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122 "2024-06-30T19:32:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dr.Turki](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dr.Turki](https://discourse.nodered.org/u/Dr.Turki)\
**Post date:** [30 June 2024 19:32 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122/1 "2024-06-30T19:32:13Z")

</div>

I am in need of some assistance with a project I'm currently working on. I need to monitor an energy meter through MODBUS, and while all the energy measurements are assigned to registers, there is no timestamp included.

To capture the timestamp of the measurement, the closest we can get is by using the time of the request with an inject node and passing it in the flow as the timestamp of the measured values. However, the issue I'm encountering is that the output of the MODBUS node is fixed to only pass the register values, resulting in the timestamp being lost.

Here is a summary of what I'm trying to achieve:

1. Use an inject node to initiate the request and capture the current timestamp.
2. Pass this timestamp through the flow.
3. Ensure the MODBUS node output includes the timestamp along with the register values.

Has anyone faced a similar issue or has any suggestions on how to achieve this? Any advice or examples would be greatly appreciated.

Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [30 June 2024 20:17 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122/2 "2024-06-30T20:17:14Z")

</div>

Save the timestamp in a flow variable? [Storing Data in Node-Red Variables](https://stevesnoderedguide.com/node-red-variables)

Then route the output of the MODBUS node to a calculation where you add it back in without changing anything of the message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 June 2024 20:19 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122/3 "2024-06-30T20:19:29Z")

</div>

If the modbus node does not pass a timestamp through in a msg property that is not payload, then you should raise this issue with the node maintainer, as well behaved nodes should pass msg properties on.

As work around you have three methods

- Set the timestamp to a context var and recall it after the modbus node [Working with context : Node-RED](https://nodered.org/docs/user-guide/context)
- Split the wire and assign the timestamp to payload, then rejoin the wires with a join node in manual key object mode. [Create a single message from separate streams of messages : Node-RED](https://cookbook.nodered.org/basic/join-streams)
- Add the timestamp after the modbus node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 June 2024 20:48 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122/4 "2024-06-30T20:48:57Z")

</div>

I would add the timestamp after the modbus node. You can do that by passing it through a Change node configured to set `msg.timestamp` to the current time. Or if the payload is an object then set `msg.payload.timestamp` to the time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 September 2024 20:49 UTC](https://discourse.nodered.org/t/modbus-timestamp/89122/5 "2024-09-28T20:49:10Z")

</div>

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