From de5422cbe5e7012fffd3bd29fa15f27472281bad Mon Sep 17 00:00:00 2001
From: Alan <60433566+alanesq@users.noreply.github.com>
Date: Mon, 11 Jan 2021 08:46:20 +0000
Subject: [PATCH] Add files via upload
---
Misc/VeryBasicWebserver.ino | 133 +++++++++++++++++-------------------
1 file changed, 64 insertions(+), 69 deletions(-)
diff --git a/Misc/VeryBasicWebserver.ino b/Misc/VeryBasicWebserver.ino
index 37ca22b..f2c4152 100644
--- a/Misc/VeryBasicWebserver.ino
+++ b/Misc/VeryBasicWebserver.ino
@@ -1,7 +1,7 @@
// ----------------------------------------------------------------
//
//
-// ESP32 / ESp8266 very basic web server demo - 10Jan21
+// ESP32 / ESp8266 very basic web server demo - 11Jan21
//
// shows use of AJAX to show updating info on the web page
//
@@ -224,66 +224,61 @@ void handleAJAX() {
Serial.println("Ajax page requested from: " + String(cip[0]) +"." + String(cip[1]) + "." + String(cip[2]) + "." + String(cip[3]) );
- // ------------------- send the html -------------------
+ // ---------------------- html ----------------------
- client.print (R"=====(
+ client.print (R"=====(
-
-
-
- AJAX Demo
-
+
+
+
+ AJAX Demo
+
-
-
-
Update web page using AJAX
-
-
-
-
- Current Millis : 0
- Received text : NA
- LED State is : NA
-
+
+
+
Update web page using AJAX
+
+
+
+
+ Current Millis : 0
+ Received text : NA
+ LED State is : NA
+
- )=====");
+ )=====");
+
+ // ------------------- JavaScript -------------------
- // ------------------- JavaScript -------------------
+ client.print (R"=====(
-
- )=====");
-
+ if (this.readyState == 4 && this.status == 200) {
+ var receivedArr = this.responseText.split(',');
+ document.getElementById('MillisValue').innerHTML = receivedArr[0];
+ document.getElementById('ReceivedText').innerHTML = receivedArr[1];
+ }
+ };
+ xhttp.open('GET', 'senddata', true);
+ xhttp.send();}
+
+ setInterval(function() {
+ getData();
+ }, 2000);
+
+ )=====");
// --------------------------------------------------
// close html page
@@ -295,29 +290,29 @@ void handleAJAX() {
// send data to AJAX web page
-// it replies with two items comma seperated: the value in millis and some text
+// it replies with two items comma separated: the value in millis and some text
void handleSendData() {
- String reply = String(millis()); // item 1
- reply += ",";
- reply += "This text sent by handleSendtime()"; // item 2
- server.send(200, "text/plane", reply); //Send millis value only to client ajax request
+ String reply = String(millis()); // item 1
+ reply += ",";
+ reply += "This text sent by handleSendtime()"; // item 2
+ server.send(200, "text/plane", reply); //Send millis value only to client ajax request
}
// handle button clicks on AJAX web page
// it sets the onboard LED status and replies with it's status as plain text
void handleLED() {
- String ledState = "OFF";
- String t_state = server.arg("LEDstate"); //Refer xhttp.open("GET", "setLED?LEDstate="+led, true);
- Serial.println(t_state);
- if(t_state == "1") {
- digitalWrite(LEDpin,LOW); //LED ON
- ledState = "ON"; //Feedback parameter
- } else {
- digitalWrite(LEDpin,HIGH); //LED OFF
- ledState = "OFF"; //Feedback parameter
- }
- server.send(200, "text/plane", ledState); //Send web page
+ String ledState = "OFF";
+ String t_state = server.arg("LEDstate"); //Refer xhttp.open("GET", "setLED?LEDstate="+led, true);
+ Serial.println(t_state);
+ if(t_state == "1") {
+ digitalWrite(LEDpin,LOW); //LED ON
+ ledState = "ON"; //Feedback parameter
+ } else {
+ digitalWrite(LEDpin,HIGH); //LED OFF
+ ledState = "OFF"; //Feedback parameter
+ }
+ server.send(200, "text/plane", ledState); //Send web page
}