when I use the example of web server
it's only working when I connect to it ,
I want to make it work even when no one is connected to it.
now it will only show me data when I connect to it using the ethernet cable (my code is to count how many people move in front of my PIR)
I want it to always run ,and when I connect it will continue normally.
what do I need to change?
#include <SPI.h>
#include <Ethernet.h>
int david;
int directtion_switch=7;//????? ????? ?????
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//mac address of the device
IPAddress ip(10,0,0,25);// ip address of the device
EthernetServer server(80);
void setup()
{//start of setup
Serial.begin(9600);
delay (1000);
pinMode(9,INPUT);
pinMode(8,INPUT);
pinMode(directtion_switch,INPUT);
Ethernet.begin(mac, ip);
delay(1000);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Serial.println("please waite while run startup...");
for (int i=0;i<10;i++)
{
Serial.print("**");
delay (1000);
}
Serial.println("");
Serial.println("Thank you");
Serial.println("Sensor is now active");
}//end of setup
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Refresh: 1"); // refresh the page automatically every 1 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
//******************************************* the part of the code*******************//////////
david=work();
int Possition_switch=poss();
Serial.println(Possition_switch);
if (Possition_switch==1)
{
client.println("The entry is from left side ");
client.print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
client.println("
");
}
else if (Possition_switch==0)
{
client.println("The entry is from right side ");
client.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
client.println("
");
}
if (david==0)
{
client.print("NO MOVE ");
client.println("
");
}
else
{
if (david==1)
{
client.print("move right-->left ");
client.println("
");
}
else
{
if (david==2)
{
client.print("move left-->right ");
client.println("
");
}
}
}
//**************** end part of the code ***************
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
int work()// ???? ???? ????? ???? ????
{
int PIR;
int right=digitalRead(9);
int left=digitalRead(8);
if ((left==HIGH)&(right==HIGH))
{
Serial.println("no move ");
PIR=0;
}
else
{//start of move
if ((left==LOW)&(right==HIGH))
{//fist move 1
Serial.println("move1");
PIR=1;
}//end move1
else
{
if ((left==HIGH)&&(right==LOW))
{
Serial.println("move2");
PIR=2;
}
}
}//end of move
return PIR;
}//end work
int poss()// ????? ????? ??? ???
{
int poss_temp;
if (digitalRead(directtion_switch==HIGH))
{
poss_temp=0;
Serial.println("entry from right side -->>>> ");
}
else if (digitalRead(directtion_switch==LOW))
{
poss_temp=1;
Serial.println("entry from left side -----<<< ");
}
return poss_temp;
}//end of poss