i am having a problem with my arduino when trying to connect to a apache web server.
I tried to use both public ip and local ip to connect but none works, i still get connection failed message..
Here is the arduino sketch:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192, 168, 1, 6 }; //assigned arduino LAN IP address
byte server[] = {
46,198,212,78 };
EthernetClient client; //apache web server running on port 80
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("starting simple arduino client test");
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 80 > 0)) {
Serial.println("connected");
client.println("GET /write.php?value0=99 HTTP/1.0"); //php page invoking my web service
client.println();
}
else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================================");
Serial.println("");
client.stop();
for(;;);
}
}
And here is the php script:
<?php
echo "connection receiving";
$value0=$_GET['value0'];
$opendb=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db('arduino',$opendb);
if ($opendb){
echo " database open.";
if (!$db) {
echo mysql_error();
}
$query = "INSERT INTO analoog0 VALUES(curdate(), curtime(), '$value0');";
/* Run the query */
$result= mysql_query($query)or die(mysql_error());
mysql_close($opendb);
echo "values written = $value0";
}
?>
Thanks in advance..!!