^Volver Arriba
Get Adobe Flash player

Cheats del día

Team Speak 3

Cod2

Contador de visítas

839490
Hoy
Ayer
Esta semana
Semana pasada
Este mes
Mes pasado
En total
20
137
1401
835301
5553
12806
839490

Tu IP: 3.22.181.209
Server Time: 2024-04-20 03:46:09

No a los Cheats

 

Formulario de acceso

Servidor web Arduino + SD card

 

 

En este tutorial montaremos un servidor web con nuestro arduino y utilizaremos en este caso nuestra sd card donde le pondremos nuestro archivo index.html en la raíz de nuestra sd.

crearemos el index.html con el siguiente código.

<!DOCTYPE html>

<html>

    <head>

        <title>Arduino SD Card Web</title>

    </head>

    <body>

        <h1>Hola desde Arduino SD Card!</h1>

        <p>Pagina web alojada en Arduino SD card server.</p>

    </body>

</html>

 

 

 

 

Ahora este es el código de nuestro arduino.

/*--------------------------------------------------------------

  servercanary.sytes.net

--------------------------------------------------------------*/

 

#include <SPI.h>

#include <Ethernet.h>

#include <SD.h>

 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address from Ethernet shield sticker under board

IPAddress ip(192,168,1,100); // Asignamo una ip

EthernetServer server(80);  // Creamos el server con el  80

 

File webFile;

 

void setup()

{

    Ethernet.begin(mac, ip);  // iniciamos ethernet

    server.begin();           // iniciamos la escucha de clientes

    Serial.begin(9600);       // puerto serial

   

    // configuracion SD card

    Serial.println("Initializing SD card...");

    if (!SD.begin(4)) {

        Serial.println("ERROR - SD card initialization failed!");

        return;    // init failed

    }

    Serial.println("SUCCESS - SD card initialized.");

    // check for index.htm file

    if (!SD.exists("index.htm")) {

        Serial.println("ERROR - Can't find index.htm file!");

        return;  // can't find index file

    }

    Serial.println("SUCCESS - Found index.htm file.");

}

 

void loop()

{

    EthernetClient client = server.available();  // try to get client

 

    if (client) {  // got client?

        boolean currentLineIsBlank = true;

        while (client.connected()) {

            if (client.available()) {   // client data available to read

                char c = client.read(); // read 1 byte (character) from client

                // last line of client request is blank and ends with \n

                // respond to client only after last line received

                if (c == '\n' && currentLineIsBlank) {

                    // send a standard http response header

                    client.println("HTTP/1.1 200 OK");

                    client.println("Content-Type: text/html");

                    client.println("Connection: close");

                    client.println();

                    // send web page

                    webFile = SD.open("index.htm");        // open web page file

                    if (webFile) {

                        while(webFile.available()) {

                            client.write(webFile.read()); // send web page to client

                        }

                        webFile.close();

                    }

                    break;

                }

                // every line of text received from the client ends with \r\n

                if (c == '\n') {

                    // last character on line of received text

                    // starting new line with next character read

                    currentLineIsBlank = true;

                }

                else if (c != '\r') {

                    // a text character was received from client

                    currentLineIsBlank = false;

                }

            } // end if (client.available())

        } // end while (client.connected())

        delay(1);      // give the web browser time to receive the data

        client.stop(); // close the connection

    } // end if (client)

}