-
Notifications
You must be signed in to change notification settings - Fork 1
HTTP header
m3nd3s edited this page Oct 29, 2011
·
1 revision
/*
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 4 Sep 2010
by Tom Igoe
*/
#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, 0xDF, 0xDE, 0xEE };
byte 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):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
char post_data[100];
byte index = 0;
if (client.connected()) {
while( client.available() ) {
char c = client.read();
if ( c != '\r' && c != '\n' ) {
post_data[index++] = c;
} else {
if( c == '\r' ) {
Serial.print("Dados: ");
Serial.println(post_data);
}
memset(post_data, 0, 100);
index = 0;
}
//Serial.print(c);
}
Serial.print("Dados: ");
Serial.println(post_data);
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("<br />");
}
client.println("<form action='./' method='post'><input type='text' name='nome' value='m3nd3s' /><input type='text' name='email' value='m3nd3s' /> <input type='submit' value='Vai!' /></form>");
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}