Message counter help

Hello,
I am catching the string "null" from a msg and i am incrementing a counter every time it shows up (normally there is a number), at least i'm trying to.
But the output counts up until a random number, then it starts over.
Is something wrong with my flow? Maybe the node?
Is there a node-redish best practice for counting messages?
Thank you,

[{"id":"85923c47.f410a","type":"ui_text","z":"ae6391de.2859e","group":"f42bf895.3ba998","order":5,"width":0,"height":0,"name":"Error","label":"Errors:","format":"{{msg.count}}","layout":"row-spread","x":890,"y":280,"wires":[]},{"id":"5689035d.d0cc8c","type":"counter","z":"ae6391de.2859e","name":"TotalError","init":"0","step":"1","lower":"0","upper":"9999999","mode":"increment","outputs":"1","x":700,"y":280,"wires":[["85923c47.f410a"]]},{"id":"1dbe4955.f43227","type":"switch","z":"ae6391de.2859e","name":"NullTemp","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"null","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":500,"y":280,"wires":[["5689035d.d0cc8c"]]},{"id":"95536c53.0368f","type":"string","z":"ae6391de.2859e","name":"Temperature","methods":[{"name":"between","params":[{"type":"str","value":"Temperature\":"},{"type":"str","value":",\"Humidity"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":310,"y":160,"wires":[["ae95209c.e2466","1dbe4955.f43227"]]},{"id":"e450e73e.e84a28","type":"mqtt in","z":"ae6391de.2859e","name":"Sensors","topic":"Meteo/STATUS8","qos":"2","datatype":"utf8","broker":"a36e2f8a.1c6a6","x":100,"y":40,"wires":[["95536c53.0368f","bc8bf14c.cb43b","88cefe9d.3c3b3"]]},{"id":"f42bf895.3ba998","type":"ui_group","name":"Default","tab":"fcbe61ec.286c6","order":1,"disp":false,"width":"6","collapse":false},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"3","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"fcbe61ec.286c6","type":"ui_tab","name":"Info","icon":"dashboard","disabled":false,"hidden":false}]

Is it counting up correctly when it should?

If yes then either you are sending a message with msg.reset set, or there is a bug in the counter node or (and this is my best guess) node red is restarting for some reason. Or you could be doing a deploy but I assume you would have said if that was the case.

Stop node red and start it again in a terminal and leave the terminal open while you watch it and see if node-red restarts or if anything else odd happens.

Yes it is.
I can recreate the issue, although I don't know if this is a bug of the counter node or this is what we get.
Yesterday I left it like that and closed everything, the counter was ok until today when i started fiddling again in node-red.
Turns out, if the editor is open and something gets deployed (even something independent from the counter node or flow) the counter resets, then it starts counting up to random numbers then resets randomly until i close the browser tab. (If i open the editor again, but don't change anything, it works, the trigger is the first deploy).
I am new to node-red, the only thing i can reference to is my work where we store some counter values in retentive memories where it "survives" a reload of the program or cold/warm restarts. Is this possible in nr?

You could very easily create your own counter that uses context & If you enable file backed context the counter will survive a reboot.

Here is an example of creating a counter using a function node and context.

It should not reset unless you Deploy or restart node-red. If it is resetting randomly then something odd is going on.

There was deploy involved definitely, although different flows and or nodes got involved, not this.
I activated the file backed context then pasted the counter function from the other post.
Thank you.

That sounds as if you were doing full deploys. If you click on the down arrow next to the deploy button you can select Modified Nodes Only, then when you deploy it will not restart nodes that have not been modified.

Yes I was doing full deploys, thanks for the tip.

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