I'm kind of new to node-red and JS. I've been trying to create a cumulative function to help with industrial monitoring.
We have some variables that we bring with PLC node, we want know how many % per day the machine pass out of range.
This is what I was trying to do, at midnight I set the "zeraDia" to 1 and this function was suposed to 0 the cumulative variables and restart the counting, and save the percentage on the PIT370115result. But it's not working.
Hi Celio, welcome to Node-red.
Each time a mesage arrives at this function node, your variables PIT370115dR & PIT370115f are created again. So they can only ever get a value of 0 or 1.
You can use context variables to store the counts, like you do with PIT370115result, though it would be better to use context.set("PIT370115fR", n) than flow.set("PIT370115fR", n) or global.set("PIT370115fR", n).
But surely a better approach is to store your msg.payload.PIT370115 data in a database.
Then you can use SQL to analyse the out-of-range time, identify log term trends or patterns in time of day, even correlate with climatic or other data.
Hello!
I'm gonna try it with context.set, the bigger issue for me is to zero the variables and where to declare it.
We already have it on influxdb and we use Grafana to monitor them, I'm trying to create a informative with our KPIs and the % per day out-of-range for ech one.
"... the bigger issue for me is to zero the variables and where to declare it."
A simple trigger can be set to inject at midnight, feeding a change mode to zero your variables.
(That implies using flow.blah rather than context.blah)
In that case you should be able to query influx for a count of the number of out of range samples.
I did it, and it's working. Thanks!
I'll try talking to the IT team, to see if we can get to a better solution using Influx Query.
This is triggered at midnight
And this is the cumulative function now
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.