Why does ui-chart send an output on deploy?

I think the point of saving it in context is in order to reload after a reboot or deploy. I can't think of a use case where one would want the data to be cleared on a deploy/restart. If you did then what is the point of keeping it in the first place?

1 Like

so right now the two sides are effectively independent. On reload any existing data gets sent from the back end. When the chart sees a change it redraws itself and outputs the latest set of points. We must be able to send at connection time or you won't get the current state - so we cant stop doing that. We could perhaps not send the points out if the table was blank... BUT - sometimes you do want to clear the graph by sending an empty array - so we do want to send it out if it's empty. If you want to restore from context - read that first thing on deploy before you overwrite then write those values to the chart on connect - which will then cause the chart to output those existing points again... or filer as you suggested,

Sorry, I don't understand what you mean by that. How would one read the context before the chart sends the empty message which clears the context?
Also I don't know what you mean by 'on connect'

When you deploy you immediately read the stored data (disk context or wherever) into local context. Then when the dashboard connects you use that event from ui_control to send the data to the chart

Do you mean use an inject node configured to inject on startup to read the disk context? If so then what guarantee is there that that will happen before the chart node clears that context by sending its empty message?
If you wait for a connection before sending a set of data to the chart then at that time there will already be new data added to the chart. Are you allowed to send when data has already been added in real time by the rest of the flow, so that it adds to existing data rather than emptying the chart and replacing it with the new set?
In fact there is no need for that complexity anyway, as all it needs is a Switch node on the output of the chart, blocking messages with no payload. I thought there was an example flow somewhere showing how to implement a chart that is persistent over restart but I can't find one.

Are we sure that this is causing the problem?
I've been doing something similar for years, and never get blank charts despite rebooting, stopping and starting node-RED etc.

chart

Or (as per usual) I haven't fully grasped the issue as described?

Well I certainly see it, with an inject configured for msg.payload with global.chartcontext and the change node set to Set the global to msg.payload. Only on a node red restart, not a full deploy, which doesn't clear the chart I am surprised to see, even if the restore inject is disconnected.

[{"id":"2b8db4ab.e04304","type":"inject","z":"18a77e7c.4fbf72","name":"redraw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"chartcontext","payloadType":"msg","x":450,"y":260,"wires":[["7efed36c.48e5f4"]]},{"id":"7efed36c.48e5f4","type":"ui_chart","z":"18a77e7c.4fbf72","name":"","group":"a8e4a3.d31edb6","order":4,"width":6,"height":8,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"10","ymax":"70","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":592,"y":274,"wires":[["36634f37.f603d","a1c8d0d3.82f898"]]},{"id":"36634f37.f603d","type":"change","z":"18a77e7c.4fbf72","name":"","rules":[{"t":"set","p":"#:(file)::chartcontext","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":340,"wires":[[]]},{"id":"a8e4a3.d31edb6","type":"ui_group","z":"","name":"Chart","tab":"8032fe72.980b98","order":3,"disp":false,"width":"6","collapse":false},{"id":"8032fe72.980b98","type":"ui_tab","z":"","name":"PnH","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

@Colin your inject node is injecting a string value instead of global context

Using your flow with the inject node set to retrieve the global context, and set to inject once after 0.1 seconds, the chart is redrawn from context.

Sorry, wrong nodes exported, try this

[{"id":"2b8db4ab.e04304","type":"inject","z":"18a77e7c.4fbf72","name":"redraw","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"#:(file)::chartcontext","payloadType":"global","x":530,"y":220,"wires":[["7efed36c.48e5f4"]]},{"id":"7efed36c.48e5f4","type":"ui_chart","z":"18a77e7c.4fbf72","name":"","group":"a8e4a3.d31edb6","order":4,"width":6,"height":8,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"10","ymax":"70","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":592,"y":274,"wires":[["a1c8d0d3.82f898","36634f37.f603d"]]},{"id":"36634f37.f603d","type":"change","z":"18a77e7c.4fbf72","name":"","rules":[{"t":"set","p":"#:(file)::chartcontext","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":340,"wires":[[]]},{"id":"a8e4a3.d31edb6","type":"ui_group","z":"","name":"Chart","tab":"8032fe72.980b98","order":3,"disp":false,"width":"6","collapse":false},{"id":"8032fe72.980b98","type":"ui_tab","z":"","name":"PnH","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Yes that's how I've reconfigured your old flow.

Since I'm the one that opened this thread my question or need is understanding when the chart node will inject a msg into a flow - i.e. what actions will cause it to do that.

For example, if you change tabs in the dashboard, the chart node will send a message. If you have a screen open to the dashboard and then connect a node (like an inject node) to the charts input and deploy, you get multiple msgs sent from the chart node.

I've been quiet for the last little bit because our yard was invaded by grandkids and I mixed up a batch of bubble juice and (socialy distancing) I created a LOT of bubbles for them to pop. My plan is to try to figure out all the actions that cause the chart node to send a message and document them.

But that won't be till tomorrow since I'm beat.

Using this flow;

[{"id":"fae33fc.0ddadc","type":"inject","z":"a444a9ff.e7a408","name":"restore","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"flow","x":310,"y":2220,"wires":[["94cd08b4.456708"]]},{"id":"c28e47e3.0be1f8","type":"change","z":"a444a9ff.e7a408","name":"save context","rules":[{"t":"set","p":"test","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":2220,"wires":[[]]},{"id":"94cd08b4.456708","type":"ui_chart","z":"a444a9ff.e7a408","name":"temp chart","group":"61d2dced.3db8f4","order":7,"width":6,"height":4,"label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#00ff80","#0080c0","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":470,"y":2220,"wires":[["c28e47e3.0be1f8"]]},{"id":"539cb20c.6c0ffc","type":"inject","z":"a444a9ff.e7a408","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"30","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"40","payloadType":"num","x":320,"y":2270,"wires":[["94cd08b4.456708"]]},{"id":"61d2dced.3db8f4","type":"ui_group","z":0,"name":"flowtest","tab":"3c94630c.13381c","order":1,"disp":true,"width":16,"collapse":false},{"id":"3c94630c.13381c","type":"ui_tab","z":0,"name":"Test","icon":"dashboard","order":9}]

I get

The restore occurs at 0.1 seconds, whilst the flow starts at 0.2 seconds, so the chart is restored before the next datapoint is recorded.

Is that also true for a node red restart? I only see the problem on a restart, when the node sends the empty payload even if there is no input connected at all.

In general Node-RED will start - then the browser / dashboard will reconnect - it can't connect until the server is up - so the flow should always be able to read it's data first. If you have no input to the chart then of course you can't write the "correct' old data to it - so when the dashboard does finally connect it will think the backend will send "all the data" it has ie. none - and will send out none...

It isn't necessary to have a browser connected at all. With a chart node with no input and a debug node on the output, set to log to the console, and no browser connected (I shut down the browser to make sure) then a node red restart shows the empty message being sent.

[Edit] I made the point about no input connected in order that it is clear that the empty message sent is not as a result of a received message. Obviously in order to setup the chart the previous data must be passed in. The empty message being sent is not a result of a browser connection or an input message.

Yes it is

Perhaps there is a race condition then, it is a matter of whether the inject node picks up the data before or after it is cleared by the empty message. Are you seeing an empty message from the chart? Use a debug node set to output to the console and restart node-red from a terminal rather than in the flow.
Interesting that you don't get a connection lost message as I do while node-red is restarting.
My node-red is running on a Pi 3B with the browser on my PC.

Also if you just have a chart with no inputs and debug node sending to console, and you restart in a terminal with no browser connected, do you see the empty message?

There's no trickery here Colin, it is restarting!

I'm running node-RED in a Oracle Cloud VM with browser on my PC, (this is my last post until later). Here is the result;

I think that confirms that on your system the restore inject gets in before the chart node sends its empty message, so it doesn't send it, it sends the restored data, whereas on mine and for the poster in the original thread then they seem to happen the other way round.

I wasn't suggesting any trickery, just noting the difference, possibly indicating timing differences between our systems.

More information, I notice that if I do have a browser open on the dashboard and then restart node-red then I see two empty messages from the unconnected chart. One immediately and one a second or so later, presumably when the browser connects. I notice you are seeing only one. When you have time it would be interesting to know whether you do see the message if you don't have a browser open.

OK - finally on same page now... does seem a pain that it blanks when absolutely nothing is input. It should in all other cases - ie old existing data, manual flush of data, sending null data... so I will see if there is a sensible fix.

EDIT : - ok - fixed in master (not on npm yet)