Hi
i have arduino uno
when i upload the code the web server run but when i add more code you can't open the webserver anymore in the browser but still i can ping it
here the code:
I put login to be able to control if you know another way to login like this one please Help me
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // ip in lan
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString; //string
boolean LED1ON = false; //LED1 status flag
boolean LED2ON = false; //LED2 status flag
boolean LED3ON = false; //LED3 status flag
boolean login=false;
int light = 0; // variabile da calcolare
int potenvalue = 0;
int servo = 9;
float tempC;
int reading;
int tempPin = 0;
/////////////////////////////////
void setup(){
Ethernet.begin(mac, ip);
login = false;
pinMode(servo, OUTPUT);
login=false;
Serial.begin(9600);
}
void loop(){
light = digitalRead(A1);
potenvalue = analogRead(A0);
reading = analogRead(A3);
tempC = reading / 9.31;
/*inizio client*/
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c);
if (c == '\n' && currentLineIsBlank) {
// Serial.print(readString);
if(readString.indexOf("Nome=user&Pwd=user") > 0) {
login=true;
}
////////////////////////////////////////////////////////////////////////////
if(login==true){
if(readString.indexOf("L=1") > 0) {
// in steps of 1 degree
digitalWrite(servo,50);
LED1ON = true;
}else
if(readString.indexOf("L=01") > 0)
{
digitalWrite(servo, 0); // tell servo to go to position in variable 'pos'
LED1ON = false;
}
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
if(readString.indexOf("Logout") > 0) {//lets check if LED should be lighted
//led has to be turned ON
login=false;
}
}
/////////////////////////////////////////////////////
// INIZIO DICHIARAZIONE PAGINA HTML
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>Room security system</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ><center></head><body>");
client.println("<h1><center>Welcome to room security system</center></h1><hr />");
// Finestra di login
if (login == false) {
client.println("<h1><center>Please login to control!</center></h1>");
client.print("<form action='http://192.168.1.102/'><center>");
client.print("");
client.print("Username: <input name='Nome' value=''>");
client.print("Password: <input type='Password' name='Pwd' value=''>");
client.print("<input type='submit' value=' Login '>");
client.print("</center><hr /></form><hr />");
client.print("<marquee behavior='slide' direction='left' loop='40' >Welcome to room security system website, please login to use this website, project by Zhiran, Thank's for visiting</marquee>");
}
////////////////////////////////////////////////////////////////////////////
if (login==true) {
client.println("<h1>Sensors & Light & Alert:</h1><hr />"); //Scrive sul browser il valore del termistore
client.print("<p><strong>Potentiometer value:</strong></p>");
client.println(potenvalue);
client.println("
</p>");
client.print("<p><strong>Room temptreature:</strong></p>");
client.println(tempC);
client.println("Celsius");
client.println("
</p>");
client.print("<p><strong>Light sensor: </strong></p>");
if (light == HIGH) { // scrive sul web luce se il valore della fotoresistenza è alto
client.print("<p><strong>There is enough light to see</strong></p>"); }
else { // scrive sul web buio se il valore della fotoresistenza è basso
client.print(" <p><strong>Light level is low, lights are turned on automatically</strong></p>"); } // link per aggiornare pagina e valori
//////////////////////////////////
/////////////////////////////////////////////////
client.print("<h2>Refreash sensors: <a href=''>click here</a></h2><hr />");
client.println("<h1>Door control</h1>");
client.println("
");
//printing LED status
///////////////////////////////////////////////
client.print("<span>Door state </span>");
if (LED1ON) {
client.println("<span style='color:green'>open</span>");
}
else
{
client.println("<span style='color:grey'>closed</span>");
}
client.print("<h2><a href='/?L=1'>open</a> | <a href='/?L=01'>close</a></h2>");
client.println("<hr />");
//Secondo led
client.println("
");
//printing LED status
client.print("<h2><a href='/?Logout'>Logout</a>");
client.println("<hr />");
client.print("<span><strong>Project by Zhiran</strong?</span>");
} //chiude if login=true
client.println("</center></body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}