Add files via upload

master
Alan 2021-01-10 17:37:25 +00:00 zatwierdzone przez GitHub
rodzic 177af00d8b
commit a57424aa88
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 30 dodań i 23 usunięć

Wyświetl plik

@ -13,18 +13,17 @@
// Wifi Settings // Wifi Settings
#include <wifiSettings.h> // delete this line, un-comment the below two lines and enter your wifi details
const char *SSID = "your_wifi_ssid"; //const char *SSID = "your_wifi_ssid";
const char *PWD = "your_wifi_pwd"; //const char *PWD = "your_wifi_pwd";
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
bool serialDebug = 1; // enable debugging info on serial port bool serialDebug = 1; // enable debugging info on serial port
@ -220,33 +219,40 @@ void handleButton(){
// HTML header // HTML header
const char HTML_Header[] = R"=====( const char HTML_Header[] = R"=====(
<!DOCTYPE html>
<html lang='en'> <!DOCTYPE html>
<head> <html lang='en'>
<title>AJAX Demo</title> <head>
</head> <title>AJAX Demo</title>
<body> </head>
)====="; )=====";
// HTML Body // HTML Body
const char HTML_Body[] = R"=====( const char HTML_Body[] = R"=====(
<div id='demo'>
<body>
<div id='demo'>
<h1>Update web page using AJAX</h1> <h1>Update web page using AJAX</h1>
<button type='button' onclick='sendData(1)'>LED ON</button> <button type='button' onclick='sendData(1)'>LED ON</button>
<button type='button' onclick='sendData(0)'>LED OFF</button><BR> <button type='button' onclick='sendData(0)'>LED OFF</button><BR>
</div> </div>
<div> <div>
Current Millis : <span id='MillisValue'>0</span><br> Current Millis : <span id='MillisValue'>0</span><br>
Received text : <span id='ReceivedText'>NA</span><br> Received text : <span id='ReceivedText'>NA</span><br>
LED State is : <span id='LEDState'>NA</span><br> LED State is : <span id='LEDState'>NA</span><br>
</div> </div>
)=====";
)=====";
// Javascript
// functions: sendData - triggered when a html button is pressed // Javascript
// getData - refreshes data on page - received as a comma deliminated list - triggers every 2 seconds // functions: sendData - triggered when a html button is pressed
const char HTML_JavaScript[] = R"=====( // getData - refreshes data on page - received as a comma deliminated list - triggers every 2 seconds
<script> const char HTML_JavaScript[] = R"=====(
<script>
function sendData(led) { function sendData(led) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
@ -274,8 +280,9 @@ void handleButton(){
getData(); getData();
}, 2000); }, 2000);
</script> </script>
)=====";
)=====";
void handleAJAX() { void handleAJAX() {
@ -286,7 +293,7 @@ void handleAJAX() {
client.print(HTML_Body); client.print(HTML_Body);
client.print(HTML_JavaScript); client.print(HTML_JavaScript);
client.print("</body></html>\n"); // close HTML client.print("</body></html>\n"); // close HTML
delay(3); delay(3);
client.stop(); client.stop();