How to time difference using CoAP

I want to get time1 which is the sending time(in milliseconds) and time2 for received time to calculate the time it takes to receive packet data. However, I am only getting one time(for received time) . Can anyone suggest me how can I get two different times in debug messages?

Welcome to the forum @sura45.

You have not told use what node type the time nodes are. node-red-contrib-something possibly.
What to you see if you add a debug node showing the output of the first time node?

The time nodes are "moment" nodes (node-red-contrib-moment).


I added a debug node for the first time node but it shows like this(time1 is in the first debug message and C value is time2). I can see the time1 but I want to get both time1 and time2 in same debug message. Is there any way to do this?

Add a debug node showing what is coming out of the coap node and see if it has lost msg.time1. If it has that that is an issue with the coap node, it should not remove properties that are not relevant to its operation, so I suggest you submit an issue on the node on its github page. In the meantime the easiest solution is probably to save it to a flow context variable after the first moment node and then you can pick it up again later. However, I know there are nodes on the node-red flows site that will tell you the time between received messages, if that is actually what you are after, so you could feed both the incoming message and the coap node output message into that to get the time difference.
Another alternative, that would do away with the moment node, which is very heavy on resources I believe would be to instead use a Change node on the input and use that to directly write the date to the flow variable on the way in. Configure it like this

image

Then after the coap node have another change node configured as

image

and you will then have the two times in msg.time1 and msg.time2.

This is what I use to easily make that calculation (courtesy of @E1cid) , and the time taken is displayed beneath the debug node.

[{"id":"a10c485a.fa75c","type":"inject","z":"c9c4eeb8.bad8e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":160,"y":2150,"wires":[["4f4ae899.fee218"]]},{"id":"4f4ae899.fee218","type":"change","z":"c9c4eeb8.bad8e","name":"","rules":[{"t":"set","p":"start","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":2150,"wires":[["980601d0.59c2a"]]},{"id":"ae47bbde.84a0a","type":"debug","z":"c9c4eeb8.bad8e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"$millis()-start","statusType":"jsonata","x":630,"y":2150,"wires":[]},{"id":"980601d0.59c2a","type":"http request","z":"c9c4eeb8.bad8e","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://api.ipify.org","tls":"","persist":false,"proxy":"","authType":"","x":470,"y":2150,"wires":[["ae47bbde.84a0a"]]}]

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