Hey guys,
yesterday I coded the following code. Today I started the arduino and it did not work anymore.
My Laptops IP Adress is: 192.168.178.56
The serial Monitor says "server not available" and "no client".
a ping works fine.
Please help me...
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xBA, 0xFF, 0xAB, 0xCA, 0xCB, 0xAF }; // MAC ID of your Arduino
byte ip[] = { 192, 168, 178, 3 }; // The IP address will be dependent on your local network
byte gateway[] = { 192, 168, 178, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server = EthernetServer(80);
String readString;
void setup()
{
pinMode(6, OUTPUT);
pinMode(7,OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet); //Start Ethernet connection and Server
server.begin();
Serial.begin(9600);
Serial.println("Arduino connected"); //To keep on track
}
void loop(){
EthernetClient client = server.available(); //Listen for the incoming ports
if(server.available()){
Serial.println("server available");
}else{
Serial.println("server not available");
}
if (client) //Connects to clinet
{
Serial.println("client available");
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100) {
readString += c;
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //Print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //Send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
//client.println("<meta http-equiv='refresh' content='15'>");
client.println("<TITLE>Arduino Ethernet LEDn</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='white'>");
client.println("<H1>Arduino SMART HOME</H1>");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?light1on\"\">light1 on</a>");
client.println("<a href=\"/?light1off\"\">light1 off</a>
");
client.println("<a href=\"/?light2on\"\">light2 on</a>");
client.println("<a href=\"/?light2off\"\">light2 off</a>
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//Stoping Client
client.stop();
//Control Arduino Pin
if(readString.indexOf("?light1on") >0) //Checking for ON
{
digitalWrite(6, LOW); // Set Pin 6 to HIGH
Serial.println("LED On");
}
if(readString.indexOf("?light1off") >0)//Checking for OFF
{
digitalWrite(6, HIGH); // Set Pin 6 to LOW
Serial.println("LED Off");
}
if(readString.indexOf("?light2on") >0) //Checking for ON
{
digitalWrite(7, LOW); // Set Pin 6 to HIGH
Serial.println("LED On");
}
if(readString.indexOf("?light2off") >0)//Checking for OFF
{
digitalWrite(7, HIGH); // Set Pin 6 to LOW
Serial.println("LED Off");
}
readString=""; //Clearing string for next read
}
}
}
}else{
Serial.println("no client");
}
}