Advertisement
RuiViana

ESP_Teste_Html

Nov 28th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266WebServer.h>
  3.  
  4. ESP8266WebServer server(80);
  5.  
  6. void handleRoot()
  7. {
  8.   // HTML da pagina principal
  9.   String html = "<html><head><title>Exemplo 1</title>";
  10.   html += "<style>body { background-color: #cccccc; ";
  11.   html += "font-family: Arial, Helvetica, Sans-Serif; ";
  12.   html += "Color: #000088; }</style>";
  13.   html += "</head><body>";
  14.   html += "<h1>Exemplo 1</h1>";
  15.   html += "<p>Pagina Principal</p>";
  16.   html += "<p><a href=/updateATMega></a></p>";
  17.   html += "</body></html>";
  18.   // Enviando HTML para o servidor
  19.   server.send(200, "text/html", html);
  20. }
  21.  
  22. void setup()
  23. {
  24.   // Iniciando Serial
  25.   Serial.begin(115200);
  26.  
  27.   // Iniciando WiFi
  28.   WiFi.begin("ssid", "pword");
  29.   IPAddress subnet(255, 255, 255, 0);  
  30.   WiFi.config(IPAddress(192, 168, 0, 26),
  31.               IPAddress(192, 168, 0, 1), subnet);
  32.  
  33.   // Aguardando conectar na rede
  34.   Serial.println("");
  35.   while (WiFi.status() != WL_CONNECTED)
  36.   {
  37.     delay(500);
  38.     Serial.print('.');
  39.   }
  40.  
  41.   // Mostrando IP
  42.   Serial.println("");
  43.   Serial.print("IP address: ");
  44.   Serial.println(WiFi.localIP());
  45.  
  46.   // Atribuindo urls para funções
  47.   server.on("/", handleRoot);
  48.  
  49.   // Iniciando servidor
  50.   server.begin();
  51.  
  52.   // Apenas informando que servidor iniciou
  53.   Serial.println("HTTP server started");
  54. }
  55.  
  56. void loop()
  57. {
  58.   // No loop só precisa dessa função
  59.   server.handleClient();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement