Boas pessoal!!
Podem-me explicar, porque é que ao acrescentar a parte do código correspondente a INTERRUPTOR WC 2 na parte final do códido, o browser fica a moer e não abre a página? Faço o upload do scketch, carrega sem erros, mas ao ir abrir, fica sempre a moer e não sai dali....
#include <SPI.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
*LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 66 }; // ip in lan
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50;
//some sample data - outputs 2 (ascii = 50 DEC)
int luzDaCozinha = 9; // LED pin 8
int luzDaSalaDeEstar = 8;
int luzDoHall = 7;
int luzDoQuarto1 = 6;
int luzDoWc1 = 5;
int luzDoQuartoDoSimao= 4;
int luzDoQuarto2 = 3;
String readString = String(30); //string for fetching data from address
boolean luzDaCozinhaON = false; //LED status flag
boolean luzDaSalaDeEstarON = false;
boolean luzDoHallON = false;
boolean luzDoQuarto1ON = false;
boolean luzDoWc1ON = false;
boolean luzDoQuartoDoSimaoON = false;
boolean luzDoQuarto2ON = false;
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, subnet);
//--------------------------------------INDICAR PINos COMO OUTPUT--------------------
pinMode(luzDaCozinha, OUTPUT);
pinMode(luzDaSalaDeEstar, OUTPUT);
pinMode(luzDoHall, OUTPUT);
pinMode(luzDoQuarto1, OUTPUT);
pinMode(luzDoWc1, OUTPUT);
pinMode(luzDoQuartoDoSimao, OUTPUT);
pinMode(luzDoQuarto2, OUTPUT);
//-----------------------------------------------------------------------------------
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
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.append(c);
readString.concat(c);
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
//**********************************************************************************************************************************************************************
//-----------------------------------------------------------------------------------------------------------------------
//------------LE INTERRUPTOR LUZ DA COZINHA-----------------------------------
if (readString.substring(6,11) == "L9=ON")
{
digitalWrite(luzDaCozinha, HIGH); // set the LED on
luzDaCozinhaON = true;
}
else if (readString.substring(6,12) == "L9=OFF")
{
digitalWrite(luzDaCozinha, LOW); // set the LED OFF
luzDaCozinhaON = false;
}
//---------------LUZ DA SALA DE ESTAR-----------------------------------------------------------
if (readString.substring(6,11) == "L8=ON")
{
digitalWrite(luzDaSalaDeEstar, HIGH); // set the LED on
luzDaSalaDeEstarON = true;
}
else if (readString.substring(6,12) == "L8=OFF")
{
digitalWrite(luzDaSalaDeEstar, LOW); // set the LED OFF
luzDaSalaDeEstarON = false;
}
//----------------LUZ DO HALL-----------------------------------------------------------------------
if (readString.substring(6,11) == "L7=ON")
{
digitalWrite(luzDoHall, HIGH); // set the LED on
luzDoHallON = true;
}
else if (readString.substring(6,12) == "L7=OFF")
{
digitalWrite(luzDoHall, LOW); // set the LED OFF
luzDoHallON = false;
}
//-------------------------LUZ DO QUARTO 1-------------------------------------------------------
if (readString.substring(6,11) == "L6=ON")
{
digitalWrite(luzDoQuarto1, HIGH); // set the LED on
luzDoQuarto1ON = true;
}
else if (readString.substring(6,12) == "L6=OFF")
{
digitalWrite(luzDoQuarto1, LOW); // set the LED OFF
luzDoQuarto1ON = false;
}
//-------------------------LUZ DO WC1-------------------------------------------------------
if (readString.substring(6,11) == "L5=ON")
{
digitalWrite(luzDoWc1, HIGH); // set the LED on
luzDoWc1ON = true;
}
else if (readString.substring(6,12) == "L5=OFF")
{
digitalWrite(luzDoWc1, LOW); // set the LED OFF
luzDoWc1ON = false;
}
//-------------------------quarto 2-------------------------------------------------------
if (readString.substring(6,11) == "L4=ON")
{
digitalWrite(luzDoQuartoDoSimao, HIGH); // set the LED on
luzDoQuartoDoSimaoON = true;
}
else if (readString.substring(6,12) == "L4=OFF")
{
digitalWrite(luzDoQuartoDoSimao, LOW); // set the LED OFF
luzDoQuartoDoSimaoON = false;
}
//------------------------- INTERRUPTOR WC 2------------------------------------------------------
if (readString.substring(6,11) == "L3=ON")
{
digitalWrite(luzDoQuartoDoSimao, HIGH); // set the LED on
luzDoQuartoDoSimaoON = true;
}
else if (readString.substring(6,12) == "L3=OFF")
{
digitalWrite(luzDoQuartoDoSimao, LOW); // set the LED OFF
luzDoQuartoDoSimaoON = 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("<body style=background-color:yellow>");
client.println("<h1><center>Controlo Interruptores</center></h1>");
client.println("<font color='black'>");
client.println("<br />");
//************************************************************MODOS***************************************************************************************************
//------------------------------------------------------------------------------------------------------------
client.println("<form method=get name=LED><input type=submit name=L9 value=ON> Interruptor da Cozinha..........<form>");
client.println("<form method=get name= LED><input type=submit name=L9 value=OFF ><form>");
if (luzDaCozinhaON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>");
//-----------------SALA DE ESTAR---------------------------------------------------------------.------------------------------------
client.println("<form method=get name=LED><input type=submit name=L8 value=ON> Interruptor da Sala de Estar..<form>");
client.println("<form method=get name= LED><input type=submit name=L8 value=OFF ><form>");
if (luzDaSalaDeEstarON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//----------------HALL------------------------------------------------HALL--------------------------------------------------------------
client.println("<form method=get name=LED><input type=submit name=L7 value=ON> Interruptor do Hall...............<form>");
client.println("<form method=get name= LED><input type=submit name=L7 value=OFF ><form>");
if (luzDoHallON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//----------------MUDA A COR LUZ DO QUARTO 1-----------------------------------------------------Interruptor da Sala de Estar----------------------------------------------
client.println("<form method=get name=LED><input type=submit name=L6 value=ON> Interruptor do Hall Quarto 1<form>");
client.println("<form method=get name= LED><input type=submit name=L6 value=OFF ><form>");
if (luzDoQuarto1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//----------------MUDA A COR LUZ DO WC 1----------------------------------------------------- Interruptor da Sala de Estar----------------------------------------------
client.println("<form method=get name=LED><input type=submit name=L5 value=ON> Interruptor dO WC 1...........<form>");
client.println("<form method=get name= LED><input type=submit name=L5 value=OFF ><form>");
if (luzDoWc1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
//---------------------------------luz do quarto do QUARTO2 ---------------------------------------------
client.println("<form method=get name=LED><input type=submit name=L4 value=ON> Interruptor do Quarto 2...........<form>");
client.println("<form method=get name= LED><input type=submit name=L4 value=OFF ><form>");
if (luzDoQuartoDoSimaoON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
/*----------------------------------------------INTERRUPTOR WC 2----------------------------------------
Ao acrestar esta parte do código, o browser fica a moer, nao abrindo a pagina
client.println("<form method=get name=LED><input type=submit name=L3 value=ON> Interruptor do WC 2.......<form>");
client.println("<form method=get name= LED><input type=submit name=L3 value=OFF ><form>");
if (luzDoWc1ON)
{
client.print("<font color='green' size='3'> ON");
}
else
{
client.print("<font color='red' size = '3'> OFF");
}
client.println("<font color='black' <br /><br>"); //muda de linha
*/
//------------------------------------------------------------------------------------------------------********
//**************************************************************************************************************
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}
Obrigado