Viva, I managed to solve my problem.
Now only one point missing out ... I can not give and ask for help solving.
The code that is working and this:
Code: [Select]
Include <Ethernet.h>
Include <SPI.h>
/ *
Simple Ethernet Test
Arduino server outputs simple text to browser
The circuit:
- Arduino Duemilanove
- Arduino Ethernet shield
- Basic FTDI 5V breakout
- LED connected to digital pin 4 and GND via resistor
* /
Byte mac [] = {0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6};
IP Byte [] = {} 192,168,1,70 / / IP address of WiShield
Gateway Byte [] = {} 192,168,1,254 / / router or gateway IP address
Subnet Byte [] = {} 255,255,255,0;
Server server (6969) / / server port
LedPin Int = 4 / / LED pin
Int ledPin = 7;
String state = String (3);
Word Adc = 0;
ReadString String = String (30) / / string for fetching data from address
LEDON Boolean = false; / / LED status flag
Void Pasword ();
Carried Void ();
Void setup () {
/ / Start Ethernet
Ethernet.begin (mac, IP, gateway, subnet);
/ / Set to output pin 4
PinMode (ledPin, OUTPUT);
DigitalWrite (ledPin, LOW);
State = "OFF";
String state = String (3);
/ / Enable serial print dated
Serial.begin (9600);
}
Void loop () {
/ / Create a client connection
Client client = server.available ();
If (client) {
While (client.connected ()) {
Char client.read c = ();
If (readString.length () <30) {
ReadString + = c;
}
Serial.print (c);
If (c == '\ n') {
if (readString.trim () == ("GET /? C = 1678 HTTP/1.1")) {
/ / Client.println ("Clave <h1> Ok </ h1>");
Carried ();
Else {}
/ / Client.println ("erroneous <h1> Clave </ h1>");
}
/ / Client.println ("HTTP/1.1 200 OK");
/ / Client.println ("Content-Type: text / html");
Client.println ();
Client.print ("<body style=background-color:#ffffff>");
Client.println ("Control de Acceso <h1> </ h1>");
Client.println ("<form method=get name=LED>");
Client.println ("<input type=""password"" name=C>");
Client.println ("<input type=submit value=submit> </ form>");
/ / Read next string is clearing
ReadString = "";
/ / Stopping client
Client.stop ();
}
}
}
}
Void Homepage () {
While (1) {
/ / Create a client connection
Client client = server.available ();
If (client) {
/ / An http request ends with a blank line
CurrentLineIsBlank Boolean = true;
While (client.connected ()) {
If (client.available ()) {
Char client.read 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 Can you send a reply
If (readString.length () <30) {
ReadString.concat (c);
}
If (c == '\ n' && currentLineIsBlank) {
/ / Send a standard http response header
LED Int readString.indexOf = ("LED =");
If (readString.substring (LED, +5) == '= LED T ") {
DigitalWrite (ledPin, HIGH);
State = "ON";
}
Else if (readString.substring (LED, +5) == "LED = F") {
DigitalWrite (ledPin, LOW);
State = "OFF";
}
Client.println ("HTTP/1.1 200 OK");
Client.println ("Content-Type: text / html");
Client.println ();
Client.println ("<form method=get name=form>");
Client.println ("<img src = 'http://dl.dropbox.com/u/6916111/tvoff.png' style = \" position: fixed; left: 68px; top: 80px; width: 636px; height: 431px; z-index: 1; padding: 0; \ ">");
If (state == "ON") {
/ / Client.print ("TEST");
Client.println ("<img src = 'http://dl.dropbox.com/u/6916111/tvon.png' type =" image "style = \" position: fixed; left: 254px; top: 146px; width : 146px; height: 93px; z-index: 2; padding: 0; \ ">");
Client.println ("<a href = \". /? LED = F \ "src = 'http://dl.dropbox.com/u/6916111/off.png' type =" image "style = \" position : fixed; left: 254px; top: 146px; width: 146px; height: 93px; z-index: 2; padding: 0; \ ">");
}
else {
client.println ("<img src = 'http://dl.dropbox.com/u/6916111/off.png' type =" image "style = \" position: fixed; left: 254px; top: 146px; width : 146px; height: 93px; z-index: 2; padding: 0; \ ">");
client.println ("<a href = \". /? LED T = \ "src = 'http://dl.dropbox.com/u/6916111/tvon.png' type =" image "style = \" position : fixed; left: 254px; top: 146px; width: 146px; height: 93px; z-index: 2; padding: 0; \ ">");
}
/ / Client.print ("LED is");
/ / Client.print (state);
client.print ("
");
break;
}
if (c == '\ n') {
/ / You're starting a new line
currentLineIsBlank = true;
}
else if (c! = '\ r') {
/ / You've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
/ / Give the web browser time to receive the data
delay (1);
ReadString = "";
/ / Close the connection:
client.stop ();
}
}
}
what is happening is this:
how do I access my shield through the browser
it goes OK, and do what you have to do is:
Show a field where you put the password and then do a submit button and proceed to the main page.
Ate there all right.
What is bad is if I close the browser and return the ip of my shield in the browser, it does not already asking for the password but goes directly to the main page and I do not want it.
Thank you