Skip to content

Commit

Permalink
Asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
easytarget committed Nov 11, 2019
1 parent d943504 commit 73640cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 4 additions & 5 deletions esp32-cjmcu-531-demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -631,5 +631,4 @@ void loop(void){
}
#endif
#endif
delay(1);
}
13 changes: 7 additions & 6 deletions index.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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";
};
};
}

Expand Down

0 comments on commit 73640cc

Please sign in to comment.