Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <WiFiClient.h>
- #include<SoftwareSerial.h>
- #include <stdlib.h>
- SoftwareSerial s(3,1);
- /* Put your SSID & Password */
- const char* ssid = "Keenetic-9068"; // Enter SSID here
- const char* password = ""; //Enter Password here
- /* Put IP Address details */
- IPAddress local_ip(192,168,1,1);
- IPAddress gateway(192,168,1,1);
- IPAddress subnet(255,255,255,0);
- ESP8266WebServer server(80);
- const int led = LED_BUILTIN;
- const String postForms = "<html>\
- <head>\
- <title>Controller Settings</title>\
- <style>\
- body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
- </style>\
- </head>\
- <body>\
- <h1>POST form data to /postform/</h1><br>\
- <form action=\"/mode_one/\" target=\"_blank\">\
- <button>First mode<button>\
- </form>\
- </body>\
- </html>";
- const String modeOne= "<html>\
- <head>\
- <title> Mode 1 Settings </title>\
- <style>\
- body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
- </style>\
- </head>\
- <body>\
- <h1>Mode 1</h1><br>\
- <form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
- <div>\Mode code <input type=\"text\" name=\"mode\" value=\"100\"></div>\
- <div>\ Red \<input type=\"text\" name=\"red\"> </div>\
- <div>\ Green \<input type=\"text\" name=\"green\"> </div>\
- <div>\ Blue \<input type=\"text\" name=\"blue\"> </div>\
- <input type=\"submit\" value=\"Submit\">\
- </form>\
- </body>\
- </html>";
- void handleRoot() {
- server.send(200, "text/html", postForms);
- }
- void handleForm() {
- if (server.method() != HTTP_POST) {
- digitalWrite(led, 1);
- server.send(405, "text/plain", "Method Not Allowed");
- digitalWrite(led, 0);
- } else {
- digitalWrite(led, 1);
- String message;
- for (uint8_t i = 0; i < server.args()-1; i++) {
- message+=server.arg(i);
- Serial.print(atoi(server.arg(i).c_str()),DEC);
- }
- server.send(200, "text/plain", message);
- }
- }
- void handleModeOne() {
- server.send(200, "text/html", modeOne);
- }
- void setup(void) {
- pinMode(led, OUTPUT);
- Serial.begin(9600);
- 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());
- if (MDNS.begin("esp8266")) {
- Serial.println("MDNS responder started");
- }
- server.on("/", handleRoot);
- server.on("/postform/", handleForm);
- server.on("/mode_one/", handleModeOne);
- server.on("/mode_one/postform", handleForm);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void) {
- server.handleClient();
- }
Add Comment
Please, Sign In to add comment