Ethernet shield + arduino as a CLIENT, please help!

I had disabled the dns services trying to do something to open the server's door...

Now it's ok, if u want u can visit and check it!

I see it now. That is a virtual hosting server, so you will need to send the Host parameter with the GET request. See reply #9.

edit: If you want to know how I can tell if it is a virtual server or not, here is how.

C:\Documents and Settings\user>nslookup www.valerioantonangeli.it
Server: ip68-105-28-16.at.at.cox.net
Address: 68.105.28.16

Non-authoritative answer:
Name: valerioantonangeli.it
Address: 46.4.96.70
Aliases: www.valerioantonangeli.it

Then go to your web browser and try to load http://46.4.96.70 . It will not be your web site. Instead it is normally your virtual hosting company's website.

ok, @surfer, i'm gonna understanding right now...
so u say that if i print (client.print) the parameters in the #9 reply i'll be able to send/recieve GET request?
if it is, please tell me which sketch should i use and where i hve to put those lines..

tomorrow i'll aks to my school if i can user their server to host my site, but i prefer your solution with MY website, if u think it's possible...

thx, man!

You should be able to use your website. Use the code in reply #9. Your web hosting company server requires the Host parameter, or it will load your web hosting company's page.

This is the code I use. You will need to modify the GET code to use the Host parameter.
http://playground.arduino.cc/Code/WebClient
It has all the bug fixes I know to prevent lockups. The good part about that code is if you have a question or problem, ask me.

could i marry u? i'll try and i'll update you soon! thx for help!

VALERiOSPQR:
could i marry u?

Not without dinner and several drinks first. :slight_smile:

edit: I changed the GET code to HTTP/1.1. Set the global char[] serverName to your domain name, and it will send the Host and Connection:close for you.

i modified this codewith my domain and ip but the part of the GET it's a little bit difficult, i don't know which parts i have to delete or replace (THE PART IS: "this part |||||||||...")
if you could add in the right method this part of the code u've sent me i'll promise, we go out for dinner! XD

client.println(F("GET / HTTP/1.1"));
client.println(F("Host: www.valerioantonangeli.it"));
client.println(F("Connection: close\r\n"));

you have reason, i know, i'm a little bit retarted but in the sketch there are something like: outBuf, sprintf, %s, and something like these and i don't wanna go wrong another one!

/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified June 17, 2013
*/

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

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,1,2);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(46,4,96,70); // Google

//Change to your domain name for virtual servers
char serverName[] = "www.valerioantonangeli.it";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[32];

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("provo a connettermi"));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above 
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("connesso"));
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));
//this part |||||||||||||||||||||||||||||||||||||||||||||
    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
//this part|||||||||||||||||||||||||||||||||||||||||||||||  
} 
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}

I changed the ethernet client GET code in the playground to send the Host and Connection parameters.

Feel free to change it any way that fits your requirements. That code fits mine, because I can use it to access multiple servers at different ports and different pages, or the same page with different parameters. You can hard code those values into your getPage() function if your code requires only one server and page.

It is a demo of how to contact a server with the client code using a basic trigger (30 seconds in my demo) and the ability to pass parameters to the server.

i've tried this one but it doesn't connect... now i'll try directly the sketche u've modified!

/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified June 17, 2013
*/

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

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,1,2);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(46,4,96,70); // Google

//Change to your domain name for virtual servers
char serverName[] = "www.valerioantonangeli.it";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[32];

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("provo a connettermi"));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above 
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("connesso"));
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));
//this part |||||||||||||||||||||||||||||||||||||||||||||
    sprintf(outBuf,"GET / HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: www.valerioantonangeli.it);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
//this part|||||||||||||||||||||||||||||||||||||||||||||||  
} 
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}

it couldn't be possible... the code above this post doesen't function and the code u've modified "for me" on the playgroundarduino doesn't funztion too...

i'm thinking to go in local, it couldn't be possible, i think ther's no solution but really thax for your help, @SurferTim, u're the best! 8)

I downloaded the sketch for the new GET client code from the playground link above. Those are my localnet settings, so I changed only these

char serverName[] = "www.valerioantonangeli.it";
IPAddress server(46,4,96,70);

I'm now on pass 10 and doing fine.

impossible, changing only the srrver name and ipadress and adjusting network settings it doesen't connect.... for me...

Not impossible. Are you required to use a proxy by your ISP? Sometimes that will interfere with the connect/send/receive unless you adjust your ethernet shield settings for a proxy.

edit: Insure you are not using an ip that is already being used by another device. That will cause connection problems.

no proxy and no doubled ip on my network, thx for the information...
sorry, but u've tried with my parameters and u're able to recieve something like "3=accendi"? from the administration page??

What page do you want me to check? I was downloading your home page. Indirectly this:

client.println("GET / HTTP/1.1");

edit: If you are using an Uno, try reducing the size of outBuf. Maybe you are getting close to running out of SRAM.

  char outBuf[64];

Thx surfertim, i have to "download", to listen to the amministratore.php orto the portiere.php depending by which account're logged in!
Ps: arduino mega 2560 r3 + eth shield r3

Then you have to login to access those pages? I cannot access either of those pages from here. If so, then you need to modify your code to login first. It appears you need to send this page these parameters in a POST format to login.

<FORM ACTION="verifica_credenziali.php" METHOD="POST">
 Username: <INPUT TYPE="text" NAME="username" SIZE=20>
 

 Password:  <INPUT TYPE="password" NAME="password" SIZE=20>
 


 <INPUT TYPE="submit" VALUE="Login">
 

 </form>

So, the home pages that u see at valerioantonangeli.it passes values to verifica_credenziali.php that loads one of the two control pages: amministratore.php (if u log with username: valeanto94 and password: ciao2013xx) or portiere.php (if u log with username: mariored88 and password: kappadue2).
These pages (amministratore and portiere) sends get request by clicking "button" in the html table on these... I hope i was clear...

The problem is also that trying ONLY TO MODIFY the network settings to tour webclient example (above) i was not able to recieve nothing from these pages when i clicked pn the button...

Try to let me know but don't become crazy! I also could do it in local with some webserver, i think...
Less wonderful but really less difficult and bore for u!
Thx surfer!

I tried accessing your login page (verifica_credenziali.php) with my Mega2560, and I can connect, but get an immediate disconnect from the server with no message at all when I send a POST request. No "file not found", no "access denied" , no "thanks for playing our game". Looks like this every 30 seconds

connecting...connected

disconnecting

Heey something like this appears to me!!
How the fuck it's possible that my fucking website doesen't send request to me!!
Should u suggest to try something like PC server- SWITCH -ARDUINO client - ...and XAMPP?