Diferencia entre revisiones de «WebServer»

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

Revisión del 14:40 23 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.

/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi

 */

#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
  }

void loop() {
  // listen for incoming clients
  EthernetClient client=server.available();
  if(