From 73640cc0f180a2e006eea053267e7a4ceb1288c3 Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 11 Nov 2019 17:50:42 +0100 Subject: [PATCH] Asynchronous --- esp32-cjmcu-531-demo.ino | 9 ++++----- index.h | 13 +++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/esp32-cjmcu-531-demo.ino b/esp32-cjmcu-531-demo.ino index 6588d73..5691258 100644 --- a/esp32-cjmcu-531-demo.ino +++ b/esp32-cjmcu-531-demo.ino @@ -203,9 +203,6 @@ void setup(void){ // HTTP request responders server.on("/", handleRoot); // Main page - // Info requests - server.on("/data", handleData); // Update of distance and status - // Settings server.on("/near", handleNearMode); // mode seting server.on("/mid", handleMidMode); // mode seting @@ -235,7 +232,10 @@ void setup(void){ server.on("/s-scanplus", handleScanStepPlus); // increase scan delta server.on("/s-scanminus", handleScanStepMinus); // decrease scan delta #endif - + + // Info requests + server.on("/data", handleData); // Update of distance and status + // Start web server server.begin(); Serial.println("HTTP server started"); @@ -631,5 +631,4 @@ void loop(void){ } #endif #endif - delay(1); } diff --git a/index.h b/index.h index a742958..43b7760 100644 --- a/index.h +++ b/index.h @@ -187,7 +187,7 @@ const char MAIN_page[] PROGMEM = R"=====( // Master interval (update rate) setting. updateInterval = 250; - minUpdateInterval = 200; // fastest we can go, even at higher sensor speeds + minUpdateInterval = 100; // fastest we can go, even at higher sensor speeds // Create the recurring interval task to refresh the reading data setInterval(function() { @@ -198,9 +198,8 @@ const char MAIN_page[] PROGMEM = R"=====( function httpGet(theUrl) { var xmlHttp = new XMLHttpRequest(); - xmlHttp.open( "GET", theUrl, true); // false for synchronous request + xmlHttp.open( "GET", theUrl, true); // asynchronous, and we dont care about return. xmlHttp.send( null ); - return xmlHttp.responseText; } // Loop to get, process and display value readings @@ -330,10 +329,12 @@ const char MAIN_page[] PROGMEM = R"=====( xhttp.send(); xhttp.timeout = 300; // time in milliseconds xhttp.ontimeout = function () { - document.getElementById("signal").innerHTML = "Network Timeout"; timeout++; // increment timeout counter - // if timeout reached, clear the range value - if (timeout > 10) document.getElementById("RANGEValue").innerHTML = "n/a"; + // if 4xtimeout reached without any valid replies, clear the range value + if (timeout > 4) { + document.getElementById("RANGEValue").innerHTML = "n/a"; + document.getElementById("signal").innerHTML = "Network Timeout"; + }; }; }