i want to integrate PIR sensor code into web server home control project , in coding http request is not obtained please help me out here is the code plz help me through this
/*
Arduino with Ethernet Shield
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
int aled = 4;
int bled = 5;
int cled = 8;
int dled = 9;
const byte ledPin = 3; // LED pin
const byte motionPin = 2; // motion detector input pin
byte senseMotion = 0 ;
Servo microservo;
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 169, 254, 109, 80 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 169, 254, 109, 254 }; // internet access via router
byte subnet[] = { 255, 255, 0, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(ledPin, OUTPUT);
pinMode(motionPin, INPUT);
pinMode(aled, OUTPUT);
pinMode(bled, OUTPUT);
pinMode(cled, OUTPUT);
pinMode(dled, OUTPUT);
microservo.attach(7);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
// Now watch for burglers
senseMotion = digitalRead(motionPin);
if (senseMotion == HIGH) { // burgler found!
digitalWrite(ledPin, HIGH);
} else { // no burgler, yet...
digitalWrite(ledPin, LOW);
}
//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("<body bgcolor=\"#22e3c3\">");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>Random Nerd Tutorials Project</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Home Automation by Technology Department</H1>");
client.println("<hr />");
client.println("
");
client.println("<H2>Arduino with Ethernet Shield</H2>");
client.println("
");
client.println("<a href=\"/?button1on\"\">Turn On 1LED</a>");
client.println("<a href=\"/?button1off\"\">Turn Off 1LED</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button2on\"\">Turn On 2LED</a>");
client.println("<a href=\"/?button2off\"\">Turn Off 2LED</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button3on\"\">Turn On 3LED</a>");
client.println("<a href=\"/?button3off\"\">Turn Off 3LED</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button4on\"\">Turn On 4LED</a>");
client.println("<a href=\"/?button4off\"\">Turn Off 4LED</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button5on\"\">Rotate Left Direction</a>");
client.println("<a href=\"/?button5off\"\">Rotate Right Direction</a>
");
client.println("
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button6off\"\">Turn off alarm</a>");
client.println("
");
client.println("
");
client.println("<big>Engg Technologist;</big>");
client.println(" <small>JALAL KHAN;</small>");
client.println(" <small>M.AQEEL;</small>");
client.println(" <small>M.MEHBOOB ANJUM;</small>");
client.println(" <small>EHSAN-E-ABDULLAH;</small>");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0)
{
digitalWrite(aled, HIGH);
}
if (readString.indexOf("?button1off") >0)
{
digitalWrite(aled, LOW);
}
if (readString.indexOf("?button2on") >0)
{
digitalWrite(bled, HIGH);
}
if (readString.indexOf("?button2off") >0)
{
digitalWrite(bled, LOW);
}
if (readString.indexOf("?button3on") >0)
{
digitalWrite(cled, HIGH);
}
if (readString.indexOf("?button3off") >0)
{
digitalWrite(cled, LOW);
}
if (readString.indexOf("?button4on") >0)
{
digitalWrite(dled, HIGH);
}
if (readString.indexOf("?button4off") >0)
{
digitalWrite(dled, LOW);
}
if (readString.indexOf("?button5on") >0)
{
for(pos = 0; pos < 180; pos += 3) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (readString.indexOf("?button5off") >0){
for(pos = 180; pos>=1; pos-=3) // goes from 180 degrees to 0 degrees
{
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (readString.indexOf("?button6off") >0)
{
digitalWrite(senseMotion, LOW);
}
//clearing string for next read
readString="";
}
}
}
}
}