ESP8266 html updates

Hello all,

I’m using the ESP8266 for a weather station development.
Everything seems to be working fine except the fact that the htmlpage values update at non-commanded times.
Basically I have the following script after the html weather sensor values contents:

  htmlPage += "</section>";
  htmlPage += "<script>\r\n";
  htmlPage += "var x = setInterval(function() {loadData('htmltudo',updateData)}, 5000);\r\n";
  htmlPage += "function loadData(url, callback){\r\n";
  htmlPage += "var xhttp = new XMLHttpRequest();\r\n";
  htmlPage += "xhttp.onreadystatechange = function(){\r\n";
  htmlPage += " if(this.readyState == 4 && this.status == 200){\r\n";
  htmlPage += " callback.apply(xhttp);\r\n";
  htmlPage += " }\r\n";
  htmlPage += "};\r\n";
  htmlPage += "xhttp.open(\"GET\", url, true);\r\n";
  htmlPage += "xhttp.send();\r\n";
  htmlPage += "}\r\n";
  htmlPage += "function updateData(){\r\n";
  htmlPage += " document.getElementById('htmltudo').innerHTML = this.responseText;\r\n";
  htmlPage += "}\r\n";
  htmlPage += "</script>\r\n"; 
  htmlPage += "</body>";
  htmlPage += "</html>";

Instead of getting always 5s update time in html page values I get sometimes 5, sometimes 6 or even 7seconds. I would like to have precisely 5 seconds between updates.

Any help please?

Thank you

Instead of getting always 5s update time in html page values I get sometimes 5, sometimes 6 or even 7seconds. I would like to have precisely 5 seconds between updates.

How long does your server need to supply the requested data? Just requesting the data after 5 seconds doesn’t mean that it’s delivered exactly at that time.

Thanks for the quick reply pylon.
This is related to a weather station with temp, rain and wind sensors attached to the board. Since windspeed measurements are taken at 3s interval (hw interrupts) I would like to update all the values at a rate not much higher than 5s in order to see live changes when I’m connecting to the web page. I have a clock also running and I realize that sometimest there is more than 5seconds in time count.

I don’t know how much long it really takes to get new data…

This is related to a weather station with temp, rain and wind sensors attached to the board. Since windspeed measurements are taken at 3s interval (hw interrupts) I would like to update all the values at a rate not much higher than 5s in order to see live changes when I'm connecting to the web page. I have a clock also running and I realize that sometimest there is more than 5seconds in time count.

I already did understand that. BTW, using hardware interrupts for a 3 second interval is a huge overkill.

I don't know how much long it really takes to get new data...

If you post your code me might be able to tell you where you loose that time.

3 second intervals don't fit in 5 second updates.
So it's indeed going to be 6, 7, then 5 second updates.