Hi, Thank you for taking time and reading my post
I have already made the code although its poor since I am new to arduino
I have and Ethernet Shield and Uno Rev3
my problem is when I use the Yaler server the code does not loop and stuck in this line:
EthernetClient client = server.available(); (until I refresh the page it loops and stuck again)
However, when I use the local network the code works perfect without any problem
Thanx in addvance
the code is as follows
#include <SPI.h>
#include <Ethernet.h>
#include <YalerEthernetServer.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,101);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
//YalerEthernetServer server("try.yaler.net", 80, "gsiot-r7q0-9bm5");
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
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
//Ethernet.begin(mac);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
long x=0,y=0,z=0;
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration1, cm1, duration2, cm2;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(3, OUTPUT);// attach pin 3 to Trig of HC-SR04 #1
digitalWrite(3, LOW);
delayMicroseconds(2);
digitalWrite(3, HIGH);
delayMicroseconds(5);
digitalWrite(3, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode (4, INPUT);//attach pin 4 to Echo of HC-SR04 #1
duration1 = pulseIn(4, HIGH);
pinMode(5, OUTPUT);// attach pin 5 to Trig of HC-SR04 #2
digitalWrite(5, LOW);
delayMicroseconds(2);
digitalWrite(5, HIGH);
delayMicroseconds(5);
digitalWrite(5, LOW);
pinMode (6, INPUT);//attach pin 6 to Echo of HC-SR04 #2
duration2 = pulseIn(6, HIGH);
// convert the time into a distance
cm1 = microsecondsToCentimeters(duration1);
cm2 = microsecondsToCentimeters(duration2);
Serial.print(cm1);
Serial.print("cm, ");
Serial.print(cm2);
Serial.print("cm");
Serial.println();
if((cm1 < 70) || (cm2<70))
{
if(cm1 < cm2)
{
++x;
++y;
}
else if(cm2 < cm1)
{
--x;
++z;
}
Serial.print( "The number of people inside is " );
Serial.print(x);
Serial.println();
Serial.print( "The number of people got in is ");
Serial.print(y);
Serial.println();
Serial.print( "The number of people got out is ");
Serial.print(z);
Serial.println();
while ((cm1 < 70) || (cm2<70))
{
digitalWrite(3, LOW);
delayMicroseconds(2);
digitalWrite(3, HIGH);
delayMicroseconds(5);
digitalWrite(3, LOW);
duration1 = pulseIn(4, HIGH);
digitalWrite(5, LOW);
delayMicroseconds(2);
digitalWrite(5, HIGH);
delayMicroseconds(5);
digitalWrite(5, LOW);
duration2 = pulseIn(6, HIGH);
// convert the time into a distance
cm1 = microsecondsToCentimeters(duration1);
cm2 = microsecondsToCentimeters(duration2);
}
delay(2000);
}
////////////////////////////
listenForEthernetClients();
////////////////////////////
delay(10);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
void listenForEthernetClients() {
EthernetClient client = server.available();
if (client) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
/////////////////////////////
client.print( "The number of people inside is " );
client.print(x);
client.println("
");
client.print( "The number of people got in is ");
client.print(y);
client.println("
");
client.print( "The number of people got out is ");
client.print(z);
client.println("
");
client.println("</html>");
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
,