Diferencia entre revisiones de «WebServer»

De ArduWiki
Saltar a: navegación, buscar
(Vea también)
(Web Server)
Línea 1: Línea 1:
== 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.
 
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.
  
Línea 11: Línea 9:
  
 
  Circuit:
 
  Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
 
* Analog inputs attached to pins A0 through A5 (optional)
 
  
 
  created 18 Dec 2009
 
  created 18 Dec 2009
Línea 28: Línea 24:
 
// 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[] = {
+
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
 
};
 
 
IPAddress ip(192, 168, 1, 177);
 
IPAddress ip(192, 168, 1, 177);
  
// Initialize the Ethernet server library
+
//Ethernet shield attached to pins 10, 11, 12, 13
// with the IP address and port you want to use
+
//Analog inputs attached to pins A0 through A5 (optional)
// (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:
 
 
   Serial.begin(9600);
 
   Serial.begin(9600);
  while (!Serial) {
+
}
    ; // wait for serial port to connect. Needed for native USB port only
 
  }
 
  
 
void loop() {
 
void loop() {

Revisión del 19:34 30 may 2019

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:

 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);

//Ethernet shield attached to pins 10, 11, 12, 13
//Analog inputs attached to pins A0 through A5 (optional)
EthernetServer server(80);

void setup() {
  Serial.begin(9600);
}

void loop() {
  // listen for incoming clients
  EthernetClient client=server.available();
  if(client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

Vea también


Referencias