Advertisement
Guest User

Ethernet e Link (Arduino)

a guest
Jun 22nd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <String.h>
  3. #include <Ethernet.h>
  4.  
  5. byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x9B, 0x36 };
  6. byte ip[] = { 192, 168, 0, 91 };
  7. EthernetServer server(8090);
  8.  
  9. String readString = String(30);
  10.  
  11. void setup() {
  12.   Ethernet.begin(mac, ip);
  13. }
  14.  
  15. void loop() {
  16.  
  17.   EthernetClient client = server.available();
  18.  
  19.   if(client)
  20.   {
  21.     while(client.connected())
  22.     {
  23.       if(client.available())
  24.       {
  25.         char c = client.read();
  26.        
  27.         if(readString.length() < 30) {
  28.           readString += (c);
  29.         }
  30.        
  31.         if(c == '\n')
  32.         {
  33.           // cabeçalho http padrão
  34.           client.println("HTTP/1.1 200 OK");
  35.           client.println("Content-Type: text/html");
  36.           client.println();
  37.          
  38.           client.println("<!doctype html>");
  39.           client.println("<html>");
  40.           client.println("<head>");
  41.           client.println("<title>Exemplo Link</title>");
  42.           client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
  43.           client.println("<meta charset=\"utf-8\">");
  44.           client.println("</head>");
  45.           client.println("<body>");
  46.           client.println("<center>");
  47.          
  48.           client.println("<h1>Exemplo de link - Arduino e Ethernet</h1>");
  49.           // no html seria assim:  <a href="https://www.google.com.br">Acesse o Google</a>
  50.          
  51.           // então no arduino fica assim
  52.           client.println("<a href=\"https://www.youtube.com/user/TecnoEduardo\">Visite o link aqui!</a>");
  53.        
  54.           client.println("</center>");
  55.           client.println("</body>");
  56.           client.println("</html>");
  57.          
  58.           readString = "";
  59.          
  60.           client.stop();
  61.         }
  62.       }
  63.      
  64.     }
  65.   }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement