Problem with LEDON

Good afternoon guys!

Sorry.. I don't know to speak and write English very well..

I have Arduino duemilanove atmega 328 + ethernet shield.
I'm doing a code that turn ON and turn off a LED.

My problem is: I turn ON the ledPin 4 and I close my browser. When I open the browser with the ethernet IP, automatically the ledpin turn OFF.

I want that the ledPin 4 keeps the previous status.

#include <String.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 243 }; // IP
byte gateway[] = {
192, 168, 1, 10 }; // roteador
byte subnet[] = {
255, 255, 255, 0 }; //Subnet
Server server(80); //Porta
byte sampledata=50;//some sample data - outputs 2 (ascii = 50 DEC)

int ledPin = 4;//Pino do Led
int fanPin = 5;// Pino do Fan
int analogPin = 0; //Pino Termistor
int tempc= 0, tempf=0,tempk=0;
int samples[8];
int i;
String readString = String(30);
boolean LEDON = false;
boolean FANON = false;//LED status flag

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
pinMode(fanPin, OUTPUT);
Serial.begin(9600); //enable serial datada print
}
void loop(){

Client client = server.available();// Cria uma conexao cliente
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30)
{
//store characters to string
readString += c;
}

for(i = 0; i<=7 ;i++){
samples = ( 5.0 * analogRead(analogPin) * 100.0) / 1024.0;
_ tempc = tempc + samples*; // somando os 8 valores lidos*_
* }*
* tempc = tempc/8.0; // tirando a media dos 8 valores*
_ tempf = (tempc * 9)/ 5 + 32; // converte para fahrenheit_
* tempk= tempc+273; // converte para Kelvin*
* delay(100);*

* if (tempc >= 33){*
* digitalWrite(fanPin, LOW);*
* FANON = true;*
* }*
* else{*
* digitalWrite(fanPin, HIGH);*
* FANON = false;*
* }*
* //output chars to serial port*
* Serial.print(c);*
* //if HTTP request has ended*
* if (c == '\n') {*
* //lets check if LED should be lighted*
* if(readString.indexOf("L=1") >=0)*
* {*
* //led has to be turned OFF*
* digitalWrite(ledPin, LOW); // set the LED off*
* LEDON = true;*
* }*
* else{*
* //led has to be turned ON*
* digitalWrite(ledPin, HIGH); // set the LED on*
* LEDON = false;*
* }*
* // now output HTML data starting with standart header*
* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type: text/html");*
* client.println();*
* //set background to yellow*
* client.print("");*
* //send first heading*
* client.print("<meta http-equiv='refresh' content='10' ; url='192.168.1.243'>");*
* client.println("");*
* client.println("

Casa Inteligente

");*

* client.println("");*
* client.println("");*
* client.println("

");*
* client.println("");*
* client.println("

Luz do Quintal

");*

* //controlling led via checkbox*
* client.println("LUZ*
");
* client.println("*
(1=ON / 0=OFF)
");
* //printing LED status*
* client.print("Status: ");*
* if (LEDON){*
* client.println("ON");*
* }*
* else{*
* client.println("OFF");*
* }*
* client.println("");*
* client.println("
*
");

* client.println("Temperatura C:"); //Mostra as temperaturas em C F e K*
* client.println(tempc);*
* client.println("\t");*
* client.println("Temperatura F:");*
* client.println(tempf);*
* client.println("\t");*
* client.println("Temperatura K:");*
* client.println(tempk);*
* client.println("\n");*
* client.println("");*

* client.println("");*
* readString=""; //clearing string for next read*
* client.stop(); //stopping client*
* }*
* }*
* }*
* }*
}
Thanks. :slight_smile: