Diferencia entre revisiones de «WebServer»

De ArduWiki
Saltar a: navegación, buscar
(Web Server)
(Web Server)
Línea 4: Línea 4:
  
 
<syntaxhighlight lang="c++">
 
<syntaxhighlight lang="c++">
 +
/*
 +
created 18 Dec 2009
 +
by David A. Mellis
 +
modified 9 Apr 2012
 +
by Tom Igoe
 +
modified 02 Sept 2015
 +
by Arturo Guadalupi
 +
* Ethernet shield attached to pins 10, 11, 12, 13
 +
* Analog inputs attached to pins A0 through A5 (optional)
 +
*/
  
 +
#include <SPI.h>
 +
#include <Ethernet.h>
  
 +
//Enter a MAC address and IP address for your controller below.
 +
//The IP address will be dependent on your local network:
 +
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
 +
IPAddress ip(192, 168, 1, 177);
 +
 +
//Initialize the Ethernet server library
 +
//with the IP address and port you want to use
 +
//(port 80 is default for HTTP):
 +
EthernetServer server(80);
 +
 +
void setup() {
 +
  //Open serial communications and wait for port to open:
 +
  Serial.begin(9600);
 +
  while (!Serial) {
 +
      ;  //wait for serial port to connect. Needed for native USB port only
 +
  }
 +
  //start the Ethernet connection and the server:
 +
  Ethernet.begin(mac, ip);
 +
  server.begin();
 +
  Serial.print("server is at ");
 +
  Serial.println(Ethernet.localIP());
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revisión del 21:49 22 jun 2018

Web Server

En este ejemplo, con Ethernet Shield y Arduino se crea un servidor web simple. Con la biblioteca Ethernet, su dispositivo podrá responder a una solicitud HTTP. Después de abrir un navegador y navegar a la dirección IP de su escudo Ethernet, su Arduino responderá con HTML para que un navegador muestre los valores de entrada de los seis pines analógicos.

/*
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
*/

#include <SPI.h>
#include <Ethernet.h>

//Enter a MAC address and IP address for your controller below.
//The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);

//Initialize the Ethernet server library
//with the IP address and port you want to use
//(port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
   //Open serial communications and wait for port to open:
   Serial.begin(9600);
   while (!Serial) {
      ;  //wait for serial port to connect. Needed for native USB port only
   }
   //start the Ethernet connection and the server:
   Ethernet.begin(mac, ip);
   server.begin();
   Serial.print("server is at ");
   Serial.println(Ethernet.localIP());
}