• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Asynchronous Web Server

Q&A Forum › Category: ESP32 › Asynchronous Web Server
0 Vote Up Vote Down
ChinGuan Quek asked 2 years ago

Bases on the note in page 243 of the Learn ESP32 with Arduino IDE, it is stated the DHT sensors are quite slow in getting the readings and if we have multiple clients connected to the ESP32 DHT server at the same time, we should consider increasing the request time interval or remove the automatic update.
Kindly clarify “remove automatic update”. Which part of the code has to be removed to achieve this?

Question Tags: asynchronous web server
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
 
To increase the delay time (you can change the 10000 to a bigger number on all similar functions on the code):

setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("temperature").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/temperature", true);
  xhttp.send();
}, 10000 ) ;

 
To remove the updates, you just need to remove the setInterval() javascript functions from the code, as well as the following lines:

server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTTemperature().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTHumidity().c_str());
});

I don’t think it is necessary to remove the automatic update, and the 10000 milliseconds interval should be fine for multiple clients.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.