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?
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