TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Web Server Arduino

Pesquisas Acadêmicas: Web Server Arduino. Pesquise 862.000+ trabalhos acadêmicos

Por:   •  9/2/2015  •  1.054 Palavras (5 Páginas)  •  388 Visualizações

Página 1 de 5

/* http://bildr.org/2011/06/arduino-ethernet-pin-control/ */

#include <Ethernet.h>

#include <SPI.h>

boolean reading = false;

////////////////////////////////////////////////////////////////////////

//CONFIGURE

////////////////////////////////////////////////////////////////////////

//byte ip[] = { 192, 168, 0, 199 }; //Manual setup only

//byte gateway[] = { 192, 168, 0, 1 }; //Manual setup only

//byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only

// if need to change the MAC address (Very Rare)

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetServer server = EthernetServer(80); //port 80

////////////////////////////////////////////////////////////////////////

void setup(){

Serial.begin(9600);

//Pins 10,11,12 & 13 are used by the ethernet shield

pinMode(2, OUTPUT);

/*pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);*/

Ethernet.begin(mac);

//Ethernet.begin(mac, ip, gateway, subnet); //for manual setup

server.begin();

Serial.print("server is at ");

Serial.println(Ethernet.localIP());

}

/////////////////////////////////// loop //////////////////////////////

void loop(){

// listen for incoming clients, and process qequest.

checkForClient();

}

//////////////////////////// checkForClient //////////////////////////

void checkForClient(){

EthernetClient client = server.available();

if (client) {

// an http request ends with a blank line

boolean currentLineIsBlank = true;

boolean sentHeader = false;

while (client.connected()) {

if (client.available()) {

if(!sentHeader){

// send a standard http response header

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

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

client.println();

sentHeader = true;

}

char c = client.read();

if(reading && c == ' ')

reading = false;

if(c == '?')

reading = true; //found the ?, begin reading the info

if(reading){

Serial.print(c);

switch (c) {

case '2':

//add code here to trigger on 2

triggerPin(2, client);

break;

case '3':

//add code here to trigger on 3

triggerPin(3, client);

...

Baixar como (para membros premium)  txt (4 Kb)  
Continuar por mais 4 páginas »
Disponível apenas no TrabalhosGratuitos.com