Refresh text values only when using Dashboard

Hi,
I'm updating multiple (text) values in my Node-Red dashboard, which I GET from a local web-server. I update this by simply polling every 2 seconds and update the new value into my ui_text node (it's very dynamic data).
However if I'm not using the Node-Red dashboard, the data is still retrieved from my local server. Causing unnecessary network traffic.
Can I for-instance only retreive data if the dashboard is active? I know it's more a design question.
Any best practice that anyone can share?
Thanks a ton!
bram

Hi @brammh, welcome.

Take a look at the ui-control node of the dashboard. It emits a message very time a client connects or get lost with an unique socket-id. What you have to do is create a function node to keep record (i would suggest a array or object in flow or global context) creating an entry when a client logs in and deleting it if it gets lost. You even keep track if the client opens the specific tab where your text nodes are to signal your polling only if it makes sense.

Chris

Do you mean a web server that is under your control? If so then you could (should?) run node red in the server too and publish the data to MQTT, then the other node red can pick it up, much simplifying that flow and reducing the network bandwidth. MQTT is designed to be network efficient so publishing something every two seconds is trivial.

Thanks Gents!
The ui-control node is helpfull, I can make it work with that.
Will move over to MQTT. was thinking about that earlier.
regards,
bram

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