I've made changes in two places following the sample Ethernet Client code:
- obtaining an IP address from dhcp if available
- printing out any return information from the web/php server.
I can't test it, however.
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte ip[] = { 192, 168, 0, 127 };
byte server[] = { 192, 168, 0, 121 };
//Initialize the Ethernet server library
EthernetClient client;
int LED = 13; // Use the onboard Uno LED
int isSensePin = 7; // This is our input pin
int isSensePin2 = 8;
int isSensePin3 = 9;
int sensor1 = HIGH; // HIGH MEANS NO OBSTACLE
int sensor2 = HIGH;
int sensor3 = HIGH;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(isSensePin, INPUT);
pinMode(isSensePin2, INPUT);
pinMode(isSensePin3, INPUT);
Serial.begin(9600);
// =====================
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// =====================
}
void loop()
{
sensor1 = digitalRead(isSensePin);
sensor2 = digitalRead(isSensePin2);
sensor3 = digitalRead(isSensePin3);
if (client.connect(server, 80))
{
Serial.println("---connection ok---");
client.print("GET /arduino/getdata.php?");
client.print("sensor1=");
client.print(sensor1);
client.print("&sensor2=");
client.print(sensor2);
client.print("&sensor3=");
client.print(sensor3);
client.print(" HTTP/1.1");
client.println("Host: 192.168.0.121");
client.println("Connection: close");
client.println();
Serial.print("sensor1=");
Serial.println(sensor1);
Serial.print("sensor2=");
Serial.println(sensor2);
Serial.print("sensor3=");
Serial.println(sensor3);
// ============
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
// ============
}
else
{
Serial.println("---connection failed---\n");
client.stop();
}
delay (500);
if (sensor1 == LOW)
{
Serial.println("Occupied1");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("Available1");
digitalWrite(LED, LOW);
}
delay(1000);
if (sensor2 == LOW)
{
Serial.println("Occupied2");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("Available2");
digitalWrite(LED, LOW);
}
delay(1000);
if (sensor3 == LOW)
{
Serial.println("Occupied3");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("Available3");
digitalWrite(LED, LOW);
}
delay(1000);
}
If that doesn't work, but prints something, then post the results.
Is the web browser that you manually entered the following command on
http://192.168.0.121/arduino/getdata.php?sensor1=91&sensor2=92&sensor3=93
running on an normal PC in your network or is it running on the web server itself ?
Can you access the web server log files ?