Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  #include <SPI.h>
  2. #include <Ethernet.h>
  3. #define fotocelda A3
  4. #define LM01 A0        // sensor de temperatura
  5. #define pot A1        // potenciometro
  6.  
  7. // Enter a MAC address and IP address for your controller below.
  8. // The IP address will be dependent on your local network:
  9. byte mac[] = {
  10.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  11. IPAddress ip(192,168,1,14); //direccion ip configurada para funcionar con el servidor.
  12.  
  13. // Initialize the Ethernet server library
  14. // with the IP address and port you want to use
  15. // (port 80 is default for HTTP):
  16. EthernetServer server(80);
  17.  
  18. void setup() {
  19.  // Open serial communications and wait for port to open:
  20.   Serial.begin(9600);
  21.   pinMode(fotocelda, INPUT);
  22.   pinMode(LM01, INPUT);
  23.   pinMode(pot, INPUT);
  24.    while (!Serial) {
  25.     ; // wait for serial port to connect. Needed for Leonardo only
  26.   }
  27.  
  28.  
  29.   // start the Ethernet connection and the server:
  30.   Ethernet.begin(mac, ip);
  31.   server.begin();
  32.   Serial.print("server is at ");
  33.   Serial.println(Ethernet.localIP());
  34. }
  35.  
  36.  
  37. void loop() {
  38.   // listen for incoming clients
  39.   EthernetClient client = server.available();
  40.   if (client) {
  41.     Serial.println("new client");
  42.     // an http request ends with a blank line
  43.     boolean currentLineIsBlank = true;
  44.     while (client.connected()) {
  45.       if (client.available()) {
  46.         char c = client.read();
  47.         Serial.write(c);
  48.         // if you've gotten to the end of the line (received a newline
  49.         // character) and the line is blank, the http request has ended,
  50.         // so you can send a reply
  51.         if (c == '\n' && currentLineIsBlank) {
  52.           // send a standard http response header
  53.           client.println("HTTP/1.1 200 OK");
  54.           client.println("Content-Type: text/html");
  55.           client.println("Connection: close");  // the connection will be closed after completion of the response
  56.    client.println("Refresh: 5");  // refresh the page automatically every 5 sec
  57.           client.println();
  58.           client.println("<!DOCTYPE HTML>");
  59.           client.println("<html>");
  60.           // output the value of each analog input pin
  61.      
  62.             int valorL = analogRead(fotocelda);
  63.             int luminosidad =  map(valorL, 0, 1023, 0, 100);
  64.             client.print("luminosidad");
  65.             client.print(" is ");
  66.             client.print(luminosidad);
  67.             client.println("<br />");
  68.      
  69.             int valorT1 = analogRead(LM01);
  70.             int TEMP1 =  map(valorT1, 0, 1023, 0, 100);
  71.             client.print("temperatura 1");
  72.             client.print(" is ");
  73.             client.print(TEMP1);
  74.             client.println("<br />");  
  75.  
  76.             int valorT2 = analogRead(pot);
  77.             int TEMP2 =  map(valorT2, 0, 1023, 0, 100);
  78.             client.print("resis pot");
  79.             client.print(" is ");
  80.             client.print(TEMP2);
  81.             client.println("<br />");              
  82.          
  83.           client.println("</html>");
  84.           break;
  85.         }
  86.         if (c == '\n') {
  87.           // you're starting a new line
  88.           currentLineIsBlank = true;
  89.         }
  90.         else if (c != '\r') {
  91.           // you've gotten a character on the current line
  92.           currentLineIsBlank = false;
  93.         }
  94.       }
  95.     }
  96.     // give the web browser time to receive the data
  97.     delay(1);
  98.     // close the connection:
  99.     client.stop();
  100.     Serial.println("client disonnected");
  101.   }
  102. }