A big lag in chart data visualization

Hello All,

I would like to stream sensor data (in Real-time) on a chart in the Node-red dashboard. The rate that the data is read from the sensor is about 0.2 seconds. But I can see a lag of 1 second when seeing the data on the chart. Can anyone help with this?

Thank you

What hardware are you running node-red and the browser on? Is the browser running on the same machine as node-red?

Does the lag start immediately or does it only show when the chart fills up with data?
What time range have you configured the chart for?

Hi Colin,

I am running node-red and the chrome browser on my laptop (core i7, 16 GB RAM, intel IrisX).
I need it for a course of, for example, 2 min. The lag starts from the beginning. It does not show the data in real-time mode, I feel. It is like that for example, my sensor is changing gradually from 10 to 5 (like 10, 9, 8, 7, 6, and then 5, each change in one second (so in total, it takes 5 seconds)), but node-red receives and shows all of the changes in one second.

In the Chart node have you got Interpolate set to Step? If not then try that and see what the chart looks like. You can paste an image here.

Does this work for you, it does for me.


[{"id":"5f4b328f464177a0","type":"ui_chart","z":"bdd7be38.d3b55","name":"","group":"903a6ab8.4f4ca8","order":4,"width":0,"height":0,"label":"Fast chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":330,"y":3300,"wires":[[]]},{"id":"c57ee6549d3ddf4f","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":3300,"wires":[["5f4b328f464177a0"]]},{"id":"903a6ab8.4f4ca8","type":"ui_group","name":"Home","tab":"e2e6f4f5.56f91","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"e2e6f4f5.56f91","type":"ui_tab","name":"Homet","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

The speed in the one you sent is perfect. Therefore, the problem is not because of the hardware or browser. Is that possible that the lag is because of MTQQ speed in transferring data?

Here is a snapshot of my nodes:

Do that and show us the chart.
Let it run for just a few seconds after clearing the chart before the screenshot.

For example, when I took this screenshot, the sensor reading was on 4095, but nothing was showing in the chart:

until it was shown up after a lag as below:

What do you see in the log from the debug node at that time?

I can see that the data reaches node-red with that lag. That is why I think the lag is not because of the nodes in the node-red itself.

Do you mean that the lag is there coming out of the MQTT node? Are there the right number of messages (five per second)?

Try using something like MQTTExplorer (which is a very useful tool to install) whether you see the lag there.

Also check in the system monitor (or using top if you are using a Linux system) that nothing is hogging the processor.

Your second graph looks odd, it appears to jump back and forward in time.
Presumably data arriving at the two MQTT-in nodes has different topics?
Are you trying to draw two lines on one chart?
Can you show us a sample of the data that you are feeding into the chart?

If you look back at the flows image it can be seen that it is being fed from two MQTT nodes, so one would expect there to be two lines.

Yes Colin. I see the lag on MQTTExplorer too. I am using an MQTT broker on my android. The application name is "MQTT broker app". Maybe that is not a wise choice.

No, probably not. Why have you done that?
I suggest using Mosquitto on the PC as the broker.

I tried for a whole two days trying to connect my ESP32 to the mosquito. It was not possible in the end. The node-red was completely fine with mosquito (, port 1883). But I was always receiving this error in my Arduino IDE serial monitor:
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds

I searched for the error through the net, and I did everything that everyone suggested as a solution. No success. That is why I tried a broker on my phone.

Did you configure mosquitto to allow remote access? If so then show us exactly what you did.

I am not sure how to configure it for remote access. These are what I read through the web as solutions and I tried so far.

  1. I added two lines in the mosquito config file as below:
  2. I disabled the firewall on my PC completely.
  3. I tried other listener ports instead ( that I can see through netstat -a in CMD.
  4. I added an incoming and outgoing rule in my firewall to allow all TCP ports.

Exactly which file is that? It doesn't look like the default config file.

How are you running mosquitto?

This is where the file is located:

I open a command prompt, and I run these code one by one:

cd "C:\Program Files\mosquitto"
net start mosquitto