frank water tank
This commit is contained in:
commit
57d0aaa6f4
BIN
data/favicon.ico
Normal file
BIN
data/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
102
data/index.html
Normal file
102
data/index.html
Normal file
|
@ -0,0 +1,102 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link
|
||||
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
<title>ESP8266 Servo Control</title>
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container jumbotron text-center">
|
||||
<h1 class="display-4">Water Heater Control</h1>
|
||||
<br />
|
||||
|
||||
<h2 id="currentSeconds" class="display-4">Number of Seconds: 5</h2>
|
||||
<input type="range" id="seconds" name="seconds" min="1" max="9" onchange="setSeconds(this.value)">
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<button type="button" class="btn btn-primary btn-lg" id="down">Down</button>
|
||||
<button type="button" class="btn btn-danger btn-lg" id="stop">Stop</button>
|
||||
<button type="button" class="btn btn-primary btn-lg" id="up">Up</button>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<h2 id="currentAngle" class="display-4">Current Action: STOPPED</h2>
|
||||
</div>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script
|
||||
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
|
||||
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
<script>
|
||||
|
||||
var seconds = 5;
|
||||
var currentTimeout = null;
|
||||
|
||||
const DOWN_ANGLE = 150;
|
||||
const STOP_ANGLE = 160;
|
||||
const UP_ANGLE = 170;
|
||||
|
||||
function setSeconds(to) {
|
||||
seconds = to;
|
||||
$("#currentSeconds").text("Number of Seconds: " + seconds);
|
||||
}
|
||||
|
||||
|
||||
function action(angle, direction) {
|
||||
console.log(angle, direction)
|
||||
if (currentTimeout !== null) {
|
||||
console.log(currentTimeout)
|
||||
clearTimeout(currentTimeout);
|
||||
}
|
||||
|
||||
$.post("192.168.1.232/angle", {
|
||||
angle: angle,
|
||||
});
|
||||
$("#currentAngle").text("Current Action: " + direction);
|
||||
|
||||
|
||||
|
||||
if (angle == STOP_ANGLE){
|
||||
$("#down").prop("disabled", false)
|
||||
$("#up").prop("disabled", false)
|
||||
} else {
|
||||
$("#down").prop("disabled", true)
|
||||
$("#up").prop("disabled", true)
|
||||
currentTimeout = setTimeout(() => {
|
||||
action(STOP_ANGLE, "STOPPED");
|
||||
}, seconds * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(() => {
|
||||
$("#down").on("click", () => {
|
||||
action(DOWN_ANGLE, "decreasing")
|
||||
});
|
||||
$("#stop").on("click", () => {
|
||||
action(STOP_ANGLE, "STOPPED")
|
||||
});
|
||||
$("#up").on("click", () => {
|
||||
action(UP_ANGLE, "increasing")
|
||||
});
|
||||
|
||||
action(STOP_ANGLE, "STOPPED")
|
||||
|
||||
setSeconds(seconds);
|
||||
document.getElementById("seconds").value = seconds;
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
90
frank_tank.ino
Normal file
90
frank_tank.ino
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
Project made and maintained by Kumar Aditya
|
||||
|
||||
ESP8266 Servo Controller
|
||||
|
||||
Create a ESP8266 Webserver for controlling the real-time position of the servo motor attached to ESP8266.
|
||||
|
||||
Change these lines as per yours:
|
||||
const char *ssid = "REPLACE_WITH_YOUR_SSID"; // replace with your SSID
|
||||
const char *password = "REPLACE_WITH_YOUR_PASSWORD"; // replace with your Password
|
||||
const uint8_t servoPin = D4; // replace with servo pin
|
||||
|
||||
Parts list:
|
||||
|
||||
NodeMCU :
|
||||
https://amzn.to/397GzNe
|
||||
|
||||
Servo Motor :
|
||||
https://amzn.to/2SmyFtJ
|
||||
|
||||
The source code can be found at:
|
||||
https://git.io/JfOQv
|
||||
|
||||
Download ESPAsyncWebServer library :
|
||||
https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
|
||||
|
||||
Download ESPAsyncTCP library :
|
||||
https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip
|
||||
|
||||
Download ESP8266 Filesystem Uploader :
|
||||
https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.5.0/ESP8266FS-0.5.0.zip
|
||||
|
||||
*/
|
||||
|
||||
// Import libraries
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Servo.h>
|
||||
|
||||
|
||||
const char *ssid = "TARDIS"; // replace with your SSID
|
||||
const char *password = "EvangelionUnit-01"; // replace with your Password
|
||||
const uint8_t servoPin = D1; // replace with servo pin
|
||||
/* Create Servo Object */
|
||||
Servo servo;
|
||||
// Create Server instance
|
||||
AsyncWebServer server(80);
|
||||
void setup()
|
||||
{
|
||||
// Attach Servo, start SPIFFS and Connect to WiFi
|
||||
Serial.begin(115200);
|
||||
servo.attach(servoPin);
|
||||
servo.write(160);
|
||||
if (!SPIFFS.begin())
|
||||
{
|
||||
Serial.println("An Error has occurred while mounting SPIFFS");
|
||||
return;
|
||||
}
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.print("Connecting to WiFi..");
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(1000);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.print("\nConnected to the WiFi network: ");
|
||||
Serial.print(WiFi.SSID());
|
||||
Serial.print("IP address:");
|
||||
Serial.print(WiFi.localIP());
|
||||
// Send home page from SPIFFS
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
Serial.println("Send index.html.");
|
||||
request->send(SPIFFS, "/index.html", "text/html");
|
||||
});
|
||||
// Receive Angle from client and process it
|
||||
server.on("/angle", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||
String angle = request->arg("angle");
|
||||
Serial.println("Current Position: " + angle + "°");
|
||||
servo.write(angle.toInt());
|
||||
request->send(200);
|
||||
});
|
||||
// Send Favicon
|
||||
server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico");
|
||||
// Begin Server
|
||||
server.begin();
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user