Advertisement
martinius96

ESP8266 - webserver - Handleroot connections

Feb 8th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ESP8266 (NodeMCU) - webserver - handling Root connections
  2. //Author: Martin Chlebovec
  3. //Web: https://arduino.php5.sk?lang=en
  4. //Donate: https://paypal.me/chlebovec
  5. //Date: 9. Feb. 2020
  6.  
  7. #include <ESP8266WiFi.h>
  8. #include <ESP8266WebServer.h>
  9. const char *ssid = "MY_WIFI";
  10. const char *password = "MY_PASSWORD";
  11. ESP8266WebServer server(80);
  12.  
  13. void handleRoot() {
  14.   String response;
  15.   response = "<!DOCTYPE html>\n";
  16.   response += "<html>\n";
  17.   response += "<head>\n";
  18.   response += "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\">\n";
  19.   response += "<style>\n";
  20.   response += "body {background-color: #F5B041;}\n";
  21.   response += "</style>\n";
  22.   response += "<title>Login V16</title>\n";
  23.   response += "</head>\n";
  24.   response += "<body>\n";
  25.   response += "<center><button type=\"button\" class=\"btn btn-success\">OLA</button></center>\n";
  26.   response += "</body>\n";
  27.   response += "</html>";
  28.   server.send(200, "text/html", response);
  29. }
  30.  
  31. void setup() {
  32.   Serial.begin(115200);
  33.   delay(1000);
  34.   WiFi.mode(WIFI_STA);
  35.   WiFi.begin(ssid, password);
  36.   Serial.println("");
  37.   while (WiFi.status() != WL_CONNECTED) {
  38.     delay(500);
  39.     Serial.println(".");
  40.   }
  41.   Serial.print("IP address: ");
  42.   Serial.println(WiFi.localIP());
  43.   server.on("/", handleRoot);
  44.   server.begin();
  45. }
  46.  
  47. void loop() {
  48.   while (WiFi.status() != WL_CONNECTED) {
  49.     delay(500);
  50.     Serial.println(".");
  51.   }
  52.   server.handleClient();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement