Hello ,
I’m using sparkfun Pro Ethernet with a sensor
when a sensor detect he will show a massage “Problem!!!”
else he will show " all good"
my problem is in the html code (the cpp part is working good, I can see the sensor is working-I’m using 2 LED)
can someone please help me and\or tell me what I did wrong?
this is my code:
#include <SPI.h>
#include <Ethernet.h>
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,0,155); // ip in lan
EthernetServer server(80); //server is using port 80
int PIRChannel=4;
int GreenLED=9;
int RedLED=7;
int d;
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
pinMode(GreenLED,OUTPUT);
pinMode(RedLED,OUTPUT);
pinMode(PIRChannel,INPUT);
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// see if HTTP request has ended with blank line
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();
//meta-refresh page every 1 seconds
client.println(“”);
client.print(“”);
client.print(“<meta http-equiv="refresh" content="1">”);
client.print(“ Test”);
client.print(“”);
client.println(“”);
client.print("autorefresh test ");
client.println("
");
// printing the message
cheak();
if (d=0)
{
client.print(“All Good”);
client.print("
");
}
else
{
client.print(“Warning”);
client.print("
");
}
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();
}
}
void cheak()
{
if (digitalRead(PIRChannel) ==HIGH) // Green LED
{
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED,HIGH);
int d=0;
}
else
{
int d=12;
digitalWrite(GreenLED,LOW); //Red LED
digitalWrite(RedLED,HIGH);
delay(5000);
}
}