Hi,
I have a problem that need some solving, I am collecting data from a PLC via Modbus, each pulse adds to my counter this information is reset everyday in my PLC, how can I save this data for each gauge with a condition that is the right day of the week.
If today is sunday all the other gauges are frozen with the last value saved and only the right day can add value. I know how to reset everything in the end of the week, but not the rest of the problem.
Save your counts as an array of 7 elements. You can use a context variable for this.
A function node like this should work to maintain the counts
const day = new Date().getDay() // sunday - 0, saturday = 6
let daycounts = context.get("daycounts") || [0,0,0,0,0,0,0] // Hold counters as an array
daycounts[day] ++ // Increment today's counter
context.set("daycounts", daycounts) // save it
msg.payload = daycounts
return msg;
And a node-red-dashboard gauge can be set to display eg Wednesday's count like this
Hello,
I did how you told me but it is increasing the value every modbus pulse.
Is there a way to send the value my modbus is reading?
My suggestion above was based on you saying "each pulse adds to my counter".
If in fact each pulse includes the total count for that day I imagine that you can store the value passed in the array rather than incrementing a counter.
I'm kind of new with node-red how do I do a command like that?
Have you tried any variations of the code I posted?
If you show me your incoming data (not a picture, post actual data) I may be persuaded to give you another hint.
Sadly I have no idea what modbus addresses or holding registers are so I can't offer any more advice.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.