Go Down

Topic: Ethernet shield + arduino as a CLIENT, please help! (Read 11070 times) previous topic - next topic


hi guys, i've made my site (www.valerioantonangeli.it, hosted on a server in a webfarm) to control my arduino project, a model of an house, with sensors, servo, lights,...
the code that control all the project is perfect, i've finally adjusted it...
the website accesses to the database, log the users and sends the parameters (like: "?3=accendi") to the internet...

THE QUESTION IS... i've started this project making arduino server, but now all it's ready except the PART of the code that set ARDUINO AS A CLIENT which connects to my website and listen for incoming values...
i've tried the "WebClientRepeating" exapmle but i wasn't able to make it operate...
Could someone explain me how to do, or post me some code of what i need? (i've searched but i haven't found nothing...)

Thanks in advance, hope u will help me!  :%


This works for me. Sends a request and reads the server response every 30 seconds.


thank you server, here at home i use a dhcp assignation and then i NAT the ip to the internet but when i will make it at school i'll have a static ip...
netherless i'll try this code and i will update you about "his" work...

if someone has other suggest, please, tell me!


If the school does not have a dhcp server, then you can assign a static ip if the Ethernet.begin(mac) call fails. Something like this.
Code: [Select]
if(!Ethernet.begin(mac)) {
  Serial.println(F("DHCP failed. Setting static ip."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);


ok, thanks! i'll try to explain u the question...

the school gives me an ethernet cable with a static ip directly connected to the internet...

how can i do to try at home now?

the website page (html form) sends parameters using GET (if u wanna see enter with: username: "valeanto94" and psw:"ciao2013xx") and tell me which of the two codes u posted me i have to use cause i've tried the get method but it doesen't work...

the server (of the hosted website) is:
i really couldn't understand how to do!  :~

REALLY THANKS for your help and ur patience! :D


I am fortunate enough to have static public ips. If you have a static public ip available, then you can test it using your public ip. If not, you will probably be stuck with my code above. It should get you an ip address, etc.

Or you could set your router localnet ports "static" by disabling the dhcp server on that interface. It will be a private ip localnet, but the theory is the same. Once you have a working ip, all else is pretty much the same, with the exception that a static ip does not need to call Ethernet.maintain() to renew your ip.


thanks man, i've understand! i'm going to set my router (not static, only at school i will have it, so i couldn't understand how i will do) as a static ip for arduino and setting the nat parameters with the port 80.
i'll try to use the first sketch (GET METHOD) and i will update u!


ok, setted my router with static ip, i am modifying the GET sketch (the first one u had sent to me) but it isn't commentated too much and it's quite difficult to understand...
...i have two different pages in my website which should commmunicate with arduino, should i put the directory of theme in some part of the code??

which parameters i have to change?



the server of my website returns a big html page and says that it couldn't understand...


should i use a pc with my website loaded on it and attached to a static public ip AS A SERVER, and connect arduino to it??

PLEASE, could someone help me? i'm really confused!!


If it is a virtual hosting server, then it requires a more complex request. Try loading your website home page. I couldn't load that url in your first post (the Host below).
Code: [Select]
client.println(F("GET / HTTP/1.1"));
client.println(F("Host: www.valerioantonangeli.it"));
client.println(F("Connection: close\r\n"));


should i use a pc with my website loaded on it and attached to a static public ip AS A SERVER, and connect arduino to it??

PLEASE, could someone help me? i'm really confused!!

Below is some arduino client test code that connects to a server and prints the returned info to the serial monitor. If it works for you, then you might try it with your server. also, when you get to school, get a wireless router and connect it to your school internet connection. Then you can have numerous internet devices.

Code: [Select]

//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:

  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
    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

  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

  client.stop(); //stop client


Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Wtf? I don't know ehat's happened to my website! The file are all puloaded! :0

I'll try your method but it seems how if the server is protected and i couldn't access to it, it shows parallel desktop information about the server, i think that my get answer couldn't reach my server! -.-

I'll try the sketches you posted me, i hope one  of the two will work!
Thks for supporting my project, guys!
@zoomkat @surfertim


I don't think it has anything to do with your files uploaded. I can't reach your site with a web browser. I used nslookup to determine the status of your domain name, and I get no dns resolution for your domain.


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!


Jun 15, 2013, 07:29 pm Last Edit: Jun 15, 2013, 07:39 pm by SurferTim Reason: 1
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

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

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

Go Up