Skip to content

Instantly share code, notes, and snippets.

@li2hub
Last active November 26, 2018 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li2hub/5ff448340453e7fcdacd8606d1d4bc0f to your computer and use it in GitHub Desktop.
Save li2hub/5ff448340453e7fcdacd8606d1d4bc0f to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
ESP8266WebServer server(80);
void setup() {
Serial.begin(115200);
Serial.println("Start");
WiFi.begin("Brahma3", "Plutonine"); //Connect to your router
while ((!(WiFi.status() == WL_CONNECTED))) {
delay(300);
Serial.print(".");
}
Serial.println("Connected");
Serial.print("Type this IP in your browser:");
Serial.println((WiFi.localIP().toString())); //Your IP address, the URL to visit
server.on ( "/", handleRoot ); //Event handling function attachment
server.onNotFound ( handleNotFound );
server.begin(); //Begin the server
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
void handleRoot() {
server.send ( 200, "text/html", getPage() );
}
String getPage() {
String page = "<!DOCTYPE html>\n<html>\n<title>W3.CSS Template</title>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<link rel=\"stylesheet\" href=\"https://www.w3schools.com/w3css/4/w3.css\">\n<style>\nbody {font-family: \"Times New Roman\", Georgia, Serif;}\nh1,h2,h3,h4,h5,h6 {\n font-family: \"Playfair Display\";\n letter-spacing: 5px;\n}\n</style>\n<body>\n\n<!-- Navbar (sit on top) -->\n<div class=\"w3-top\">\n <div class=\"w3-bar w3-white w3-padding w3-card\" style=\"letter-spacing:4px;\">\n <a href=\"#home\" class=\"w3-bar-item w3-button\">Gourmet au Catering</a>\n <!-- Right-sided navbar links. Hide them on small screens -->\n <div class=\"w3-right w3-hide-small\">\n <a href=\"#about\" class=\"w3-bar-item w3-button\">About</a>\n <a href=\"#menu\" class=\"w3-bar-item w3-button\">Menu</a>\n <a href=\"#contact\" class=\"w3-bar-item w3-button\">Contact</a>\n </div>\n </div>\n</div>\n\n<!-- Header -->\n<header class=\"w3-display-container w3-content w3-wide\" style=\"max-width:1600px;min-width:500px\" id=\"home\">\n <img class=\"w3-image\" src=\"/w3images/hamburger.jpg\" alt=\"Hamburger Catering\" width=\"1600\" height=\"800\">\n <div class=\"w3-display-bottomleft w3-padding-large w3-opacity\">\n <h1 class=\"w3-xxlarge\">Le Catering</h1>\n </div>\n</header>\n\n<!-- Page content -->\n<div class=\"w3-content\" style=\"max-width:1100px\">\n\n <!-- About Section -->\n <div class=\"w3-row w3-padding-64\" id=\"about\">\n <div class=\"w3-col m6 w3-padding-large w3-hide-small\">\n <img src=\"www.w3schools.com/w3css/tryw3css_templates_gourmet_catering.htm/w3images/tablesetting2.jpg\" class=\"w3-round w3-image w3-opacity-min\" alt=\"Table Setting\" width=\"600\" height=\"750\">\n </div>\n\n <div class=\"w3-col m6 w3-padding-large\">\n <h1 class=\"w3-center\">About Catering</h1><br>\n <h5 class=\"w3-center\">Tradition since 1889</h5>\n <p class=\"w3-large\">The Catering was founded in blabla by Mr. Smith in lorem ipsum dolor sit amet, consectetur adipiscing elit consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute iruredolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.We only use <span class=\"w3-tag w3-light-grey\">seasonal</span> ingredients.</p>\n <p class=\"w3-large w3-text-grey w3-hide-medium\">Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n </div>\n </div>\n \n <hr>\n \n <!-- Menu Section -->\n <div class=\"w3-row w3-padding-64\" id=\"menu\">\n <div class=\"w3-col l6 w3-padding-large\">\n <h1 class=\"w3-center\">Our Menu</h1><br>\n <h4>Bread Basket</h4>\n <p class=\"w3-text-grey\">Assortment of fresh baked fruit breads and muffins 5.50</p><br>\n \n <h4>Honey Almond Granola with Fruits</h4>\n <p class=\"w3-text-grey\">Natural cereal of honey toasted oats, raisins, almonds and dates 7.00</p><br>\n \n <h4>Belgian Waffle</h4>\n <p class=\"w3-text-grey\">Vanilla flavored batter with malted flour 7.50</p><br>\n \n <h4>Scrambled eggs</h4>\n <p class=\"w3-text-grey\">Scrambled eggs, roasted red pepper and garlic, with green onions 7.50</p><br>\n \n <h4>Blueberry Pancakes</h4>\n <p class=\"w3-text-grey\">With syrup, butter and lots of berries 8.50</p> \n </div>\n \n <div class=\"w3-col l6 w3-padding-large\">\n <img src=\"/w3images/tablesetting.jpg\" class=\"w3-round w3-image w3-opacity-min\" alt=\"Menu\" style=\"width:100%\">\n </div>\n </div>\n\n <hr>\n\n <!-- Contact Section -->\n <div class=\"w3-container w3-padding-64\" id=\"contact\">\n <h1>Contact</h1><br>\n <p>We offer full-service catering for any event, large or small. We understand your needs and we will cater the food to satisfy the biggerst criteria of them all, both look and taste. Do not hesitate to contact us.</p>\n <p class=\"w3-text-blue-grey w3-large\"><b>Catering Service, 42nd Living St, 43043 New York, NY</b></p>\n <p>You can also contact us by phone 00553123-2323 or email catering@catering.com, or you can send us a message here:</p>\n <form action=\"/action_page.php\" target=\"_blank\">\n <p><input class=\"w3-input w3-padding-16\" type=\"text\" placeholder=\"Name\" required name=\"Name\"></p>\n <p><input class=\"w3-input w3-padding-16\" type=\"number\" placeholder=\"How many people\" required name=\"People\"></p>\n <p><input class=\"w3-input w3-padding-16\" type=\"datetime-local\" placeholder=\"Date and time\" required name=\"date\" value=\"2017-11-16T20:00\"></p>\n <p><input class=\"w3-input w3-padding-16\" type=\"text\" placeholder=\"Message \\ Special requirements\" required name=\"Message\"></p>\n <p><button class=\"w3-button w3-light-grey w3-section\" type=\"submit\">SEND MESSAGE</button></p>\n </form>\n </div>\n \n<!-- End page content -->\n</div>\n\n<!-- Footer -->\n<footer class=\"w3-center w3-light-grey w3-padding-32\">\n <p>Powered by <a href=\"https://www.w3schools.com/w3css/default.asp\" title=\"W3.CSS\" target=\"_blank\" class=\"w3-hover-text-green\">w3.css</a></p>\n</footer>\n\n</body>\n</html>\n";
return page;
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}
server.send ( 404, "text/plain", message );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment