Removed dns and moved script.js
This commit is contained in:
88
WifiLamp.ino
88
WifiLamp.ino
@@ -1,9 +1,7 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
|
|
||||||
const char* host = "debug1";
|
|
||||||
const char* ssid = "McDonalds Free WiFi 2.4GHz";
|
const char* ssid = "McDonalds Free WiFi 2.4GHz";
|
||||||
const char* password = "Passwort_123";
|
const char* password = "Passwort_123";
|
||||||
|
|
||||||
@@ -39,7 +37,7 @@ const char* indexContent = "<!doctype html>"
|
|||||||
|
|
||||||
"<script src=\"https://code.jquery.com/jquery-3.3.1.min.js\" integrity=\"sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT\" crossorigin=\"anonymous\"></script>"
|
"<script src=\"https://code.jquery.com/jquery-3.3.1.min.js\" integrity=\"sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT\" crossorigin=\"anonymous\"></script>"
|
||||||
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\" integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl\" crossorigin=\"anonymous\"></script>"
|
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\" integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl\" crossorigin=\"anonymous\"></script>"
|
||||||
"<script src=\"script.js\"></script>"
|
"<script src=\"https://brunner.ninja/relais.js\"></script>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>";
|
"</html>";
|
||||||
|
|
||||||
@@ -74,78 +72,6 @@ const char* updateContent = "<!doctype html>"
|
|||||||
"</body>"
|
"</body>"
|
||||||
"</html>";
|
"</html>";
|
||||||
|
|
||||||
const char* scriptContent = "jQuery(document).ready(function() {"
|
|
||||||
"var refreshStatus = function() {"
|
|
||||||
"$('#status')"
|
|
||||||
".text('Loading status...')"
|
|
||||||
".show();"
|
|
||||||
|
|
||||||
"$.ajax({"
|
|
||||||
"url: 'status'"
|
|
||||||
"}).done(function(data) {"
|
|
||||||
"console.log(data);"
|
|
||||||
|
|
||||||
"if(data=='on') {"
|
|
||||||
"$('#linkOn').removeClass('hidden');"
|
|
||||||
"$('#linkOff').addClass('hidden');"
|
|
||||||
"} else if(data=='off') {"
|
|
||||||
"$('#linkOn').addClass('hidden');"
|
|
||||||
"$('#linkOff').removeClass('hidden');"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
"$('#status')"
|
|
||||||
".hide();"
|
|
||||||
"});"
|
|
||||||
"};"
|
|
||||||
|
|
||||||
"$('#linkOn').click(function(e) {"
|
|
||||||
"e.preventDefault();"
|
|
||||||
|
|
||||||
"$('#status')"
|
|
||||||
".text('Sending On-command...')"
|
|
||||||
".show();"
|
|
||||||
|
|
||||||
"$('#linkOn').addClass('hidden');"
|
|
||||||
|
|
||||||
"$.ajax({"
|
|
||||||
"url: $('#linkOn').attr('href')"
|
|
||||||
"}).done(function(data) {"
|
|
||||||
"console.log(data);"
|
|
||||||
|
|
||||||
"if(data != 'success') {"
|
|
||||||
"alert('error');"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
"refreshStatus();"
|
|
||||||
"});"
|
|
||||||
"});"
|
|
||||||
|
|
||||||
"$('#linkOff').click(function(e) {"
|
|
||||||
"e.preventDefault();"
|
|
||||||
|
|
||||||
"$('#status')"
|
|
||||||
".text('Sending Off-command...')"
|
|
||||||
".show();"
|
|
||||||
|
|
||||||
"$('#linkOff').addClass('hidden');"
|
|
||||||
|
|
||||||
"$.ajax({"
|
|
||||||
"url: $('#linkOff').attr('href')"
|
|
||||||
"}).done(function(data) {"
|
|
||||||
"console.log(data);"
|
|
||||||
|
|
||||||
"if(data != 'success') {"
|
|
||||||
"alert('error');"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
"refreshStatus();"
|
|
||||||
"});"
|
|
||||||
"});"
|
|
||||||
|
|
||||||
"setInterval(refreshStatus, 15000);"
|
|
||||||
"refreshStatus();"
|
|
||||||
"});";
|
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -157,9 +83,6 @@ void setup() {
|
|||||||
|
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
|
|
||||||
MDNS.begin(host);
|
|
||||||
|
|
||||||
server.on("/", HTTP_GET, []() {
|
server.on("/", HTTP_GET, []() {
|
||||||
server.sendHeader("Connection", "close");
|
server.sendHeader("Connection", "close");
|
||||||
server.send(200, "text/html", indexContent);
|
server.send(200, "text/html", indexContent);
|
||||||
@@ -170,11 +93,6 @@ void setup() {
|
|||||||
server.send(200, "text/html", updateContent);
|
server.send(200, "text/html", updateContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/script.js", HTTP_GET, []() {
|
|
||||||
server.sendHeader("Connection", "close");
|
|
||||||
server.send(200, "text/javascript", scriptContent);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("/on", HTTP_GET, []() {
|
server.on("/on", HTTP_GET, []() {
|
||||||
digitalWrite(relaisPin, HIGH);
|
digitalWrite(relaisPin, HIGH);
|
||||||
|
|
||||||
@@ -232,10 +150,8 @@ void setup() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
MDNS.addService("http", "tcp", 80);
|
|
||||||
|
|
||||||
Serial.printf("Ready! Open http://%s.local in your browser\n", host);
|
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||||
} else {
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
digitalWrite(relaisPin, LOW);
|
digitalWrite(relaisPin, LOW);
|
||||||
delay(500);
|
delay(500);
|
||||||
|
48
cdn/relais.js
Normal file
48
cdn/relais.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
jQuery(document).ready(function() {
|
||||||
|
var refreshStatus = function() {
|
||||||
|
$('#status').text('Loading status...').show();
|
||||||
|
$.ajax({
|
||||||
|
url: 'status'
|
||||||
|
}).done(function(data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data == 'on') {
|
||||||
|
$('#linkOn').removeClass('hidden');
|
||||||
|
$('#linkOff').addClass('hidden');
|
||||||
|
} else if (data == 'off') {
|
||||||
|
$('#linkOn').addClass('hidden');
|
||||||
|
$('#linkOff').removeClass('hidden');
|
||||||
|
}
|
||||||
|
$('#status').hide();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
$('#linkOn').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$('#status').text('Sending On-command...').show();
|
||||||
|
$('#linkOn').addClass('hidden');
|
||||||
|
$.ajax({
|
||||||
|
url: $('#linkOn').attr('href')
|
||||||
|
}).done(function(data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data != 'success') {
|
||||||
|
alert('error');
|
||||||
|
}
|
||||||
|
refreshStatus();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#linkOff').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$('#status').text('Sending Off-command...').show();
|
||||||
|
$('#linkOff').addClass('hidden');
|
||||||
|
$.ajax({
|
||||||
|
url: $('#linkOff').attr('href')
|
||||||
|
}).done(function(data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data != 'success') {
|
||||||
|
alert('error');
|
||||||
|
}
|
||||||
|
refreshStatus();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setInterval(refreshStatus, 15000);
|
||||||
|
refreshStatus();
|
||||||
|
});
|
Reference in New Issue
Block a user