Hi Guys!
I use an IR sensor to count people and i want to show the value counted from eeprom on the web.
But it does not appear on the web.
Please help me!
This is my code:
#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 76); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
boolean LED_status = 0; // state of LED, off by default
int button = 2;
int pirPin1 = 28;
int counter;
int laststate1 = HIGH;
int address =1 ;
int f;
//float f = 0.00f;
String readString;
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.begin(9600); // for diagnostics
pinMode(6, OUTPUT); // LED on pin 2
pinMode(button, INPUT_PULLUP);
pinMode(pirPin1, INPUT);
delay(1000);
}
char linebuf[80];
int charcount=0;
boolean authentificated=false;
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
memset(linebuf,0,sizeof(linebuf));
charcount=0;
authentificated=false;
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
linebuf[charcount]=c;
if (charcount<sizeof(linebuf)-1) charcount++;
Serial.write(c);
// HTTP_req += c; // save the HTTP request 1 char at a time
// last line of client request is blank and ends with \n
// respond to client only after last line received
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("Connection: close");
client.println();
// send web page
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Arduino Control</title>");
client.println("</head>");
client.println("<body>");
client.println("<a href=\"/?relay1on\"\">Click here </a>");
if(readString.indexOf("?relay1on") >0)//checks for on
{
int buttonStatus = digitalRead(button);
if (buttonStatus == HIGH) { // Nếu mà button bị nhấn
int state1 = digitalRead(pirPin1);
if ( laststate1 == LOW && state1 == HIGH)
{
counter++;
EEPROM.write(address, EEPROM.read(address)+1);
f = EEPROM.read(address)+1;
// Serial.println(EEPROM.read(address));
// client.println(EEPROM.get(address,f));
}
laststate1 = state1;
} else {
counter =0;
EEPROM.write(address, 0);
Serial.println(EEPROM.read(address));
delay(200);
}
client.print("<p>");
client.print("Numbers people=");
client.println(EEPROM.get((address),f));
client.print("</p>");
}
readString="";
client.println("</body>");
client.println("</html>");
// Serial.print(HTTP_req);
// HTTP_req = ""; // finished with request, empty string
delay(1);
//stopping client
client.stop();
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}