How to get MicroSeconds "μs" on node red flow?

HI.

We are reading 3 precision sensors using a round robbin method each sensor read is
83.333ms apart then loops over and over again. We are doing this as no 2 sensors read at the same time due to cross interference.

When the sensor is read it is run through a function node and formatted with a ISO time stamp then streamed to AWS. All this works OK with the occasional error of +- 1.3ms.
What we would like to do is see the .333 μs as an integer. I have scrolled through the internet and it seems this inst something discussed in node red. We are using the Moment node for the ISO time stamp, and i must add it is an amazing bit of kit. There are also a few npm packages that handle μs but im not sure how to use the API for these in node red.

Can anyone offer any advice, have a flow that handles the μs?

Thanks

There's no way of getting 1ms accuracy once the information is inside of Node-RED.

if you need this sort of accuarcy, I'd suggest a real-time clock running on an Arduino type micro-controller that timestamps the readings at source before they are sent off to a recording computer

Could you explain why please ?

Micro controller is a method yes.

The reason is JavaScript and your underlying platform/OS not specifically Node-RED.

Firstly, a general purpose computing platform is not a real-time system and so ms accuracy is rarely, if ever, possible.

Secondly, JavaScript generally and Node.js specifically runs using an implicit loop. Rather like the loop function you might use when programming an Arduino for example. The difference being that all manner of things may impact the loop in JS and most of them you have no control over. So even if you use one of the JavaScript timer functions, the trigger time is only ever approximate. This is why JavaScript and Node.js has such an emphasis on asynchronous tasks, they allow the implicit loop to continue whereas a synchronous task such as a synch file read function will block the loop from continuing until completed.

So while JavaScript certainly uses microsecond accuracy for its Date objects (so you can record it), it is incapable of doing things down to the microsecond accuracy level.

When you add Node-RED on top of that, the flow-based approach also will add further unknown and variable delays.

So your microcontrollers may have microsecond level responses (as long as you program them carefully), once you pass that data to Node-RED, the timing will always be slightly variable.

You may be able to get around this by outputting a timing value from the microprocessor but you would need to synchronise this somehow to a real-world time so that all of the sensors timings could be compared.

Of course, we don't really know why you want such timing accuracy so we may be barking up entirely the wrong tree here.

PS: Thanks for your kind words regarding the moment node. Of course, I cannot take credit for the underlying MomentJS library which is a monumental thing light-years beyond my capacity to build.

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