Use remote requests for controlling,
rather than refreshing the page
This commit is contained in:
26
src/main.cpp
26
src/main.cpp
@@ -51,7 +51,7 @@ const char* loginIndex =
|
||||
"<table width='20%' bgcolor='A09F9F' align='center'>"
|
||||
"<tr>"
|
||||
"<td colspan=2>"
|
||||
"<center><font size=4><b>ESP32 Login Page</b></font></center>"
|
||||
"<center><font size=4><b>BLIND-Controller Login Page</b></font></center>"
|
||||
"<br>"
|
||||
"</td>"
|
||||
"<br>"
|
||||
@@ -134,6 +134,7 @@ const char* serverIndex =
|
||||
const char* movePage =
|
||||
"<html>"
|
||||
"<head>"
|
||||
"<title>Blind-POC</title>"
|
||||
"<style type='text/css'>"
|
||||
"button {"
|
||||
"width: 25%;"
|
||||
@@ -141,12 +142,19 @@ const char* movePage =
|
||||
"font-size:20px;"
|
||||
"} "
|
||||
"</style>"
|
||||
"<script>"
|
||||
"let rq=url=>{"
|
||||
" let xhr=new XMLHttpRequest();"
|
||||
" xhr.open('PUT',url);"
|
||||
" xhr.send();"
|
||||
"}"
|
||||
"</script>"
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<a href='http://192.168.10.141/close'><button>CLOSE (Full)</button></a>"
|
||||
"<a href='http://192.168.10.141/open'><button>OPEN (Full)</button></a>"
|
||||
"<a href='http://192.168.10.141/rev'><button>Close (A bit)</button></a>"
|
||||
"<a href='http://192.168.10.141/fwd'><button>Open (A bit)</button></a>"
|
||||
"<button onclick='rq(\"/close\")'>CLOSE (Full)</button>"
|
||||
"<button onclick='rq(\"/open\")'>OPEN (Full)</button>"
|
||||
"<button onclick='rq(\"/rev\")'>Close (A bit)</button>"
|
||||
"<button onclick='rq(\"/fwd\")'>Open (A bit)</button>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
|
||||
@@ -216,7 +224,7 @@ void setup(void) {
|
||||
server.send(200, "text/html", movePage);
|
||||
});
|
||||
|
||||
server.on("/open", HTTP_GET, []() {
|
||||
server.on("/open", HTTP_PUT, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
Serial.println("Opening");
|
||||
digitalWrite(motor1Pin1, LOW);
|
||||
@@ -227,7 +235,7 @@ void setup(void) {
|
||||
|
||||
server.send(200, "text/html", movePage);
|
||||
});
|
||||
server.on("/close", HTTP_GET, []() {
|
||||
server.on("/close", HTTP_PUT, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
Serial.println("Closing");
|
||||
digitalWrite(motor1Pin1, HIGH);
|
||||
@@ -239,7 +247,7 @@ void setup(void) {
|
||||
server.send(200, "text/html", movePage);
|
||||
});
|
||||
|
||||
server.on("/fwd", HTTP_GET, []() {
|
||||
server.on("/fwd", HTTP_PUT, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
// Move the DC motor forward at maximum speed
|
||||
Serial.println("Moving Forward");
|
||||
@@ -251,7 +259,7 @@ void setup(void) {
|
||||
|
||||
server.send(200, "text/html", movePage);
|
||||
});
|
||||
server.on("/rev", HTTP_GET, []() {
|
||||
server.on("/rev", HTTP_PUT, []() {
|
||||
server.sendHeader("Connection", "close");
|
||||
Serial.println("Moving Backward");
|
||||
digitalWrite(motor1Pin1, HIGH);
|
||||
|
||||
Reference in New Issue
Block a user