Browse Source

working webinterface

master
Thorsten Riess 2 years ago
parent
commit
c6a43e713b
1 changed files with 47 additions and 17 deletions
  1. +47
    -17
      webinterface/webinterface.ino

+ 47
- 17
webinterface/webinterface.ino View File

@@ -1,34 +1,55 @@
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "Twilight";
const char* password = "V4ffwSzLMd7i";
const char* ssid = "RelaisAddierer";
const char* password = "hacKNology";

// DNS server
const byte DNS_PORT = 53;
DNSServer dnsServer;

ESP8266WebServer server(80); //creating the server at port 80

/* Soft AP network parameters */
IPAddress apIP(192, 168, 4, 1);
IPAddress netMsk(255, 255, 255, 0);

void setup() {
Serial.begin(115200);
// put your setup code here, to run once:

WiFi.begin(ssid, password);
Serial.println("");
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAPConfig(apIP, apIP, netMsk);
WiFi.softAP(ssid, password);
delay(500); // Without delay I've seen the IP address blank
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());

/* Setup the DNS server redirecting all the domains to the apIP */
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(DNS_PORT, "*", apIP);

//WiFi.begin(ssid, password);
//Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
//while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
//}
//Serial.println("");
//Serial.print("Connected to ");
//Serial.println(ssid);
//Serial.print("IP address: ");
//Serial.println(WiFi.localIP());

if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
//if (MDNS.begin("esp8266")) {
// Serial.println("MDNS responder started");
//}
server.on("/form", formdata);
server.on("/", handleroot);
@@ -40,11 +61,17 @@ void setup() {
}

void handleroot() {
server.send(200, "text/html", "<html><head></head><body><h1>Relais-Rechner-Steuerung</h1><form action=\"/form\" method=\"post\"><ul><li><label><input type=\"checkbox\" name=\"switch1\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch2\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch3\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch4\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch5\" value=\"on\">2^0</label></li><li><label><input type=\"checkbox\" name=\"switch6\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch7\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch8\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch9\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch10\" value=\"on\">2^0</label></li></ul><button type=\"submit\">Go!</button></form></body></html>");
server.send(200, "text/html", "<html><head></head><body><h1>Relais-Rechner-Steuerung</h1><form action=\"/form\" method=\"post\"><fieldset><input type=\"radio\" id=\"opplus\" name=\"op\" value=\"p\" checked><label for=\"opplus\"> +</label><br><input type=\"radio\" id=\"opminus\" name=\"op\" value=\"m\"><label for=\"opminus\"> -</label></fieldset><ul><li><label><input type=\"checkbox\" name=\"switch1\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch2\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch3\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch4\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch5\" value=\"on\">2^0</label></li><li><label><input type=\"checkbox\" name=\"switch6\" value=\"on\">2^4</label><label><input type=\"checkbox\" name=\"switch7\" value=\"on\">2^3</label><label><input type=\"checkbox\" name=\"switch8\" value=\"on\">2^2</label><label><input type=\"checkbox\" name=\"switch9\" value=\"on\">2^1</label><label><input type=\"checkbox\" name=\"switch10\" value=\"on\">2^0</label></li></ul><button type=\"submit\">Go!</button></form></body></html>");
}

void formdata() {
char op='+';
char sw1='0',sw2='0',sw3='0',sw4='0',sw5='0',sw6='0',sw7='0',sw8='0',sw9='0',sw10='0';
if(server.hasArg("op")) {
if(server.arg("op").equals("m")) {
op = '-';
}
}
if(server.hasArg("switch1")) {
sw1 = '1';
}
@@ -76,6 +103,7 @@ void formdata() {
sw10 = '1';
}
Serial.print('A');
Serial.print(op);
Serial.print(sw1);
Serial.print(sw2);
Serial.print(sw3);
@@ -92,5 +120,7 @@ void formdata() {
}

void loop() {
//DNS
dnsServer.processNextRequest();
server.handleClient();
}

Loading…
Cancel
Save