Arduino to web host connection failed

Hello I need help with my project as I have come to a frustrating end. Any help will be much appreciated.

I am trying to get my arduino to connect to my web page which is held on a host server at www.godaddy.com. The reason is for it to update a php script that will insert data into a mysql database.

The problem i have is the arduino will not connect to the site.
below is my script for the arduino

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip (192, 168, 1, 74);
IPAddress server (184,168,138,128);//ip address for my web server
//char server [] = "www.duffahome.com";

EthernetClient client;

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)){
    Serial.println ("connected");
    client.println("GET/update_db.php?panel=15 HTTP/1.1");
    client.println("Host: www.duffahome.com");
    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(;;);
  }
}

the serial response as follows
starting simple arduino client test
connecting…
connection failed
disconnecting

So my connection is failing. I have tried using my web page as char server but this also fails.

I’ve also set my BT hub to port forwarding for this mac address.

When running the Ethernet Google example script the arduino works fine and gives the web servers reply to the serial port.

does any one have any tips on what i should try next as I’ve run out of ideas.

thanks

Simple http client test code

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println("Host: web.comporium.net");
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

You need a Host: statement after the get request. Your domain is NOT godaddy.com.

You need a space after the GET statement.

Hello Zoomkat thanks for the reply. I have seen and used a some of your topics on this subject to get this far so thanks again for your contribution. I have tried your sketch and it works as expected. The google sketch with the arduino examples works as well. I will go over your sketch and see what similarity's there are with mine. to see if i can get mine to work.

Hello PaulS

thanks for the reply.

I understand my domain is not godaddy.com. this is my host site, my domain is duffahome.com.

I have put a place after GET but this did not work.

I have already got a Host request after the GET request as follows

client.println("Host: www.duffahome.com");

but this is my domain address, should this be the host address.

the IP address for the server at the beginning of the sketch is form my domain address.

when i run the sketch the serial is saying connecting.... then connection failed. so i have no connection to get to the clientprint part of the sketch.

I think there may be a problem with the set up at the beginning but i don't know what.

any help will be appreciated. thanks

Zoomkat I have modified your sketch and its working XD

I now have the arduino updating the MySQL data base on my server.

from your sketch i changed the char server to my home page and the host to my home page and paster in my GET request to update my data base and it is working wonderfully.

I can't thank you enough i have spent a long time very frustrated with this.

I can now move on to adapting this to hopefully have temperature readings automatically sending data to my database.

thanks :D :D

zoomkat:   Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded

You might consider changing that to:

Serial.println(FILE " " DATE " " TIME); // so I can keep track of what is loaded

Unless you live in "Perfect World", this will lock up in this while loop eventually. I've tested it. It may be a couple hours or maybe a couple days, but eventually...

  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

It needs a timeout to abort that loop in the event of a connection fail, like a hardware failure enroute.

Thanks for the tips, the original script was to test if i could get this to work and update the MySQL data base.

I have removed the serial.print part in the set up and changed the script to now update a temperature reading on a count loop so as to not over fill my database to quickly.

Below is my first version 1 script. I hope to develop this further.

#include <SPI.h>
#include <Ethernet.h>
#include<OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//IPAddress ip (192, 168, 1, 74);
//IPAddress server (184,168,138,128);//ip address for my web server
char serverName[] = "www.duffahome.com";

OneWire oneWire(ONE_WIRE_BUS);
EthernetClient client;
DallasTemperature sensors(&oneWire);

DeviceAddress outsideTemp = {0x28, 0x45, 0xCA, 0x9C, 0x04, 0x00, 0x00, 0x72};
int temp1;


void setup(){
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 

}
  

void loop (){
  
  for (int x=0; x<100; x++)
  {
  temp1 = sensors.getTempC(outsideTemp);
  sensors.requestTemperatures ();
  Serial.print (temp1);
  delay (5000);
  }
  sendGET();
}

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.print("GET /update_db.php?panel=");
    //client.println("panel");
    //client.println("=");
    client.print(temp1);
    Serial.println(temp1);
    client.println(" HTTP/1.0");
    client.println("Host: www.duffahome.com");
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client
}

My goal is for this to run my water solar system. At present I have an arduino reading 4 temp readings. 1 from my solar panel 2 from the hot water cylinder and 1 out side temperature. The arduino calculates when to turn the water pump on and circulate the water through the solar panel to the cylinder.
This is working very well and has been running for over a month with no real issues.

Now i want to get it on-line so the version 1 script will have to grow to incorporate this. I will update as i get more written and tested.

Here is the thread that had the lockup fail in it. Another user found the fail, I just fixed it. http://forum.arduino.cc/index.php?topic=102879.0

thanks surfertim i will have a read over this tonight