no-ip and Arduino Ethernet Shield

Strictly speaking, the URL format should not work for any browser, as it is not in the W3C spec for http protocol URL. I'd say Microsoft IE browser is spec compliant. There is nothing wrong if that URL does not work with IE, as it is NOT supposed to work. The spec is pretty clear cut and straightforward and that is all you need to go by.

On the other hand, on IE if you just enter

http://dynupdate.noip.com/nic/update?hostname=

then you will be prompted for basic authentication login.

This works as per W3C http protocol spec (in both URL format and basic authentication handling). i.e. initial GET command returns a 401 error and browser prompts for login.

then you will be prompted for basic authentication login.

Yes, I get that. I'm just chasing what is posted on the no-ip info page. Not sure the page ever got a technical proof read.

that's probably the case so I would not get too hung up on it too much.

same with the part where they say un-encoded username and password will work. Clear text does not work. which is fine, because the w3c spec says it should always be encoded. The the world wide web consortium (w3c) specs must be implemented by all internet applications. the implementor is free to add additional features that is not part of the spec, and that is what causes incompatibility and confusion like this. Always go with the spec.

I have follow the codes posted by doughboy but doesn't works.


Result:

Connecting ...

Connected

Disconnecting

Hufthh ... anyone may can help?

My Code ...

/*
  Web client

This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. 

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13

created 18 Dec 2009
by David A. Mellis

modified for no-ip client example
by Jerry Sy aka doughboy
*/

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 82);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 1);
IPAddress dnServer(192, 168, 1, 1);
// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(115200);  

    Ethernet.begin(mac, ip);  // initialize Ethernet device
  
  // if you get a connection, report back via serial:
  if (client.connect("dynupdate.no-ip.com", 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    //replace yourhost.no-ip.org with your no-ip hostname
    client.println("GET /nic/update?hostname=www.myhostname.com HTTP/1.0");
    client.println("Host: dynupdate.no-ip.com");
    //encode your username:password (make sure colon is between username and password) 
    //to base64 at http://www.opinionatedgeek.com/dotnet/tools/base64encode/
    //and replace the string below after Basic with your encoded string
    //clear text username:password is not accepted
    client.println("Authorization: Basic YmFkYW5rLW1iYXM6QmVuOUJlbjk="); 
    client.println("User-Agent: Arduino Sketch/1.0 myemail@xxx.com");

    client.println();
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{


  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (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();

    // do nothing forevermore:
    for(;;)
      ;
  }
 
  
}

The return value of client.connect has changed. Use this instead.

if(client.connect(server,port) == 1)

edit: Only a return value of 1 indicates connection success. The client.connect function can return a negative value if something went wrong with the domain name resolution, and that also evaluates to 'true'.

Even tho the reference page doesn't mention it, if it returns -5, that indicates "domain name not found".

Hey, are you guys having any luck with no-ip?
I got connected to their server but got this in response

HTTP/1.0 401 Unauthorized
Date: Wed, 25 Feb 2015 01:11:55 GMT
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
WWW-Authenticate: Basic realm="dynupdate.no-ip.com"
Content-Length: 47
Connection: close
Content-Type: text/html; charset=UTF-8

This service requires basic http authentication

Here's their API

This is my code like above

 if (client.connect("dynupdate.no-ip.com", 80))
    {
        Serial.println(F("ddns connected"));
        client.print(F("GET /nic/update?hostname="));
        client.print(ddnsHostName);
        client.print(F("&myip=60.60.60.200"));
        client.println(F(" HTTP/1.0"));
        client.print(F("HOST: "));
        client.println(ddnsHost);
        client.print(F("Authorization: Basic "));
        client.println(userpass);
        client.print(F("User-Agent: Arduino Green Controller/1.0 "));
        client.println(toEmail);
        client.println();
    } else {
        Serial.println(F("connection failed"));
        client.stop();
        
    }

hmm. For some reason I got it to update the IP today once but get failed connection on subsequence tries. I wonder if you can only call 'update' a few times a day.

I don't think that would cause a failed connection. It might prevent you from updating your IP. What does the server response show on the successful connection?

Maybe if you posted your entire sketch, someone may be able to help you.

I entered in the wrong user/pass before. That's why I got the 401.
When that was corrected, it went through with something like

HTTP/1.1 200 OK
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
Content-Length: 20
Connection: close
Content-Type: text/plain; charset=UTF-8

chg 60.60.60.200

But on subsequent connections, nothing but failed, 0.
My code is part of a class. I'll pull it out into a sketch for testing and sharing.

That's funny, I just got another successful update but when I try again, I got a failed connection. Seems like 1-2 hour limit. Will try again in a few hours.

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);


EthernetClient client;
unsigned long waitTime;

void setup() {
  // start the serial library:
  Serial.begin(115200);  

  Ethernet.begin(mac, ip);  // initialize Ethernet device
  // give me time to launch serial monitor and ethershield to get ready.
  delay(7000);
  
  Serial.println("begin");
  if (client.connect("dynupdate.no-ip.com", 80)) {
    Serial.println("connected");
    client.println("GET /nic/update?hostname=hostname HTTP/1.0");
    client.println("Host: dynupdate.no-ip.com");
    client.println("Authorization: Basic userpassbase64"); 
    client.println("User-Agent: Arduino Sketch/1.0 email");

    client.println();
  } 
  else 
  {
    Serial.println(client.connect("dynupdate.no-ip.com", 80));
    Serial.println("failed");
  }
  Serial.println("waiting");
  waitForResponse(client);
}

void loop()
{
  
}

void waitForResponse(EthernetClient client)
{
    waitTime = millis();
    while (!client.available())
    {

        if((millis() - waitTime) > 10000) {
            client.stop();
            Serial.println(F("\r\nTimeout"));
            break;
        }
    }
    
    while (client.available())
    {
        char c = client.read();
        Serial.print(c);
    }//end while
  
    
}

yup, that confirms it. You can update only within x time span.
I waited 2 hours

HTTP/1.1 200 OK
Date: Wed, 25 Feb 2015 18:05:55 GMT
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
Content-Length: 19
Connection: close
Content-Type: text/plain; charset=UTF-8

nochg 1.2.3.4

btw, Your IP is automatically looked up by noip update.php and updated. You don't need to find you ip via something like checkip.dyndns.com to update.

yup, that confirms it. You can update only within x time span.

I got the below from my arduino no-ip update code. Three update replies with in ~8 seconds, so your conclusion may not be correct. The no-ip application updates about every 5 min.

connected
HTTP/1.1 200 OK
Date: Fri, 27 Feb 2015 18:09:52 GMT
Server: Apache
Content-Location: update.php
Vary: negotiate,Accept-Encoding
TCN: choice
Content-Length: 20
Connection: close
Content-Type: text/plain

nochg 67.197.101.195
disconnecting.
==================

connected
HTTP/1.1 200 OK
Date: Fri, 27 Feb 2015 18:09:55 GMT
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
Content-Length: 5
Connection: close
Content-Type: text/plain; charset=UTF-8

nochg
disconnecting.
==================

connected
HTTP/1.1 200 OK
Date: Fri, 27 Feb 2015 18:09:59 GMT
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
Content-Length: 5
Connection: close
Content-Type: text/plain; charset=UTF-8

nochg
disconnecting.
==================

hmm, you're right. I'm able to update every 5 minutes today. I wonder if their server can get overloaded and slow down a bit. I usually give a 10 seconds and call timed out.

mistergreen:
hmm, you're right. I'm able to update every 5 minutes today. I wonder if their server can get overloaded and slow down a bit. I usually give a 10 seconds and call timed out.

If you look at the return messages, the first includes the current wan IP address. The subsequent return messages don't contain the IP address, but do contain the nochg message, which I assume indicates there has been no change in the wan IP address sense the last check. There is probably no practical need for frequent updates beyond 5 min.

i made this i checked it and its working great :smiley:

/*
Hope you like this little sketch! I love this sketch so much that i decided 
to post it online :D (i never did before :|). Part of the code comes from 
Ethernet WebClient sketch i just modified it a little bit to update my ip 
to no-ip server without the use of a computer or other software. If you want to 
access any Device from the internet you will need a PORT FORWARDING and FIREWALL
settings on your router. This sketch only updates your external to your no-ip
account and therefore you can access your network or device using your no-ip address.
There are few issues with this sketch, one is that when you execute it for the
first time you will need to press the RESET button on your arduino then you will
receive the proper values. Im new to this so some mistakes are there :|.
Author: Deepesh Buckus
*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x80, 0xA5, 0xDX, 0x0F, 0xFA, 0xMD }; // MAC ADD OF ETHERNET SHEILD
byte ip[] = { 192, 168, 1, 17 };                     // SET AN IP 
char server[] = "checkip.dyndns.org";                // THIS WOULD GIVE US THE EXTERNAL IP ITS NEEDED SO WE CAN UPDATE THE EXTERNAL IP ONLY IF THERE IS A CHANGE IN IP
char server2[] = "dynupdate.no-ip.com";              // NO-IP SERVER 
String rawip = "\0";
int i = 0;
int j = 0;
String ipnew;
String ipold = "111.255.155.27";                     //THIS IS JUST FOR COMPARISON PURPOSE (WITH IPNEW AND IPOLD) YOU CAN LEAVE IT AS IT IS
EthernetClient client ,client2;                      

void setup() {
 Serial.begin(9600);
  while (!Serial) {
   ; 
 }

 // start the Ethernet connection:
 if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");
   // no point in carrying on, so do nothing forevermore:
   // try to congifure using IP address instead of DHCP:
   Ethernet.begin(mac, ip);
 }
 // give the Ethernet shield a second to initialize:
 delay(1000);
 Serial.println("connecting...");
 getip();                                          // THIS FUNCTION GET THE HTML FROM THE CHECKIP.DYNDNS.ORG

}

void loop()
{
 rawip="\0";               
 
 j = 0;

 getip();
 delay(3000);
while (client.available()) {                   //THIS WHILE LOOP REMOVES THE UNNECESSARY CHARACTERS FROM THE CHAR C

   char c = client.read();
   if ( c =='<')
   {
     j++; 
   }
   if ( j >= 1) {
     rawip = rawip + c;                       //GETTING ONLY THE <HTML> TAGS AND IP
   }
   Serial.print(c);                           // PRINTS THE WHOLE THING FROM THE LIKE SERVER AND STUFF
 }
 Serial.println("html:");
  Serial.println(rawip); 
 ipnew ="\0";                                 
ipnew =dec_rawip(rawip);                      // dec_rawip() function removes all other texts and tags and gets only the ip address from rawip

Serial.println(" New ip");
Serial.println(ipnew);
Serial.println("Old ip:");                  
 Serial.println(ipold);
 if ( ipold != ipnew)                         //IF THE OLD IP IS NOT SAME AS THE NEW IP THE NEW IP HAS TO BE UPDATED TO NO-IP SERVER..
 {
   ipold = "\0";
   ipold = ipnew;
   Serial.println(" Changing old IP to:");
   Serial.println(ipold);
  update_ddns();                              // THIS FUNCTION UPDATES THE NO-IP SERVER TO YOUR ACTUAL IP
  while (client2.available()) {               // THIS IS NOT WORKING I DONT KNOW WHYYYYYYYYYYYYYY >< BUT IT IS UPDATING THE IP..
   char c = client.read();
   Serial.print(c);
  }
    delay(5000);                              
   
 } else {
   Serial.println("Nothing to be changed");   // IF IP HASNT CHANGED THE NO-IP SERVER DOESNT NEED TO BE UPDATED
 }
  
 
 // if the server's disconnected, stop the client:
 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");    
   client.stop();
    
   delay(10000);                               //WAIT FOR SOME TIME
 }
}

void getip()                                     // GETIP FUNCTION 
{ 
 
 // if you get a connection, report back via serial:
 if (client.connect(server, 80)) {
   Serial.println("connected");
   // Make a HTTP request:
    client.println("GET / HTTP/1.0");
   client.println("Host: www.checkip.dyndns.org");
   client.println("Connection: close");
   client.println();
} 
}

String dec_rawip( String ip)       // GETTING THE IP FROM THE HTML STRING
{
 int y = ip.length();
char myStr[y];
int i;
char c[20];
String str;
i = ip.length();
 ip.toCharArray(myStr, i -1);
 
 str ="\0";
for (i=0;i < sizeof(myStr) - 1; i++)
 {
  if (myStr[i] == '1' || myStr[i] == '2' ||myStr[i] == '3' ||myStr[i] == '4' ||myStr[i] == '5' ||myStr[i] == '6'||myStr[i] == '7'||myStr[i] == '8'||myStr[i] == '9'||myStr[i] == '0' || myStr[i] =='.' )
   {
 c[i] = myStr[i];
 str = str + c[i];
   }
}
return(str); 
}  
void update_ddns()                                   // UPDATES YOUR IP TO NO-IP
{
   if (client2.connect(server2, 80)) {
   Serial.println("connected to no-ip");
   client2.println("GET /nic/update?hostname=your_user_address.no-ip.org HTTP/1.0");     // replace 'your_user_address.no-ip.org' by your hostname e.g jimmyhendricks.no-ip.org 
       client2.println("Host: dynupdate.no-ip.com");
        client2.println("Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");      // HERE U NEED TO PUT YOUR USERNAME AND PASSWORD BY ENCODING IT FIRST TO BASE64. GO TO https://www.base64encode.org/ AND TYPE YOUR USERNAME AND PASSWORD IN THE FORMAT username:password AND REPLACE 'dXNlcm5hbWU6cGFzc3dvcmQNCg==' BY THE ENCODED STRING
        client2.println("User-Agent: Arduino_update_client/1.0 YOUREMAILADDRESS@gmail.com");  // REPLACE YOUREMAILADDRESS BY YOUR EMAIL ADDRESS :|
   client2.println();
  
 } else {
   Serial.println("connection failed");                                         
 }
 client2.stop();
}

i made this i checked it and its working great :smiley:

But people can't easily read it or use it unless you put it in [code][/code] tags.

You're also using buckets of precious RAM

Yess im really sorry.. this is my first post actually.. and it would be great if you guys helped me out for the RAM issue :slight_smile:

here is the code

/*
Hope you like this little sketch! I love this sketch so much that i decided 
to post it online :D (i never did before :|). Part of the code comes from 
Ethernet WebClient sketch i just modified it a little bit to update my ip 
to no-ip server without the use of a computer or other software. If you want to 
access any Device from the internet you will need a PORT FORWARDING and FIREWALL
settings on your router. This sketch only updates your external to your no-ip
account and therefore you can access your network or device using your no-ip address.
There are few issues with this sketch, one is that when you execute it for the
first time you will need to press the RESET button on your arduino then you will
receive the proper values. Im new to this so some mistakes are there :|.
Author: Deepesh Buckus
*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x80, 0xA5, 0xDX, 0x0F, 0xFA, 0xMD }; // MAC ADD OF ETHERNET SHEILD
byte ip[] = { 192, 168, 1, 17 };                     // SET AN IP 
char server[] = "checkip.dyndns.org";                // THIS WOULD GIVE US THE EXTERNAL IP ITS NEEDED SO WE CAN UPDATE THE EXTERNAL IP ONLY IF THERE IS A CHANGE IN IP
char server2[] = "dynupdate.no-ip.com";              // NO-IP SERVER 
String rawip = "\0";
int i = 0;
int j = 0;
String ipnew;
String ipold = "111.255.155.27";                     //THIS IS JUST FOR COMPARISON PURPOSE (WITH IPNEW AND IPOLD) YOU CAN LEAVE IT AS IT IS
EthernetClient client ,client2;                      

void setup() {
 Serial.begin(9600);
  while (!Serial) {
   ; 
 }

 // start the Ethernet connection:
 if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");
   // no point in carrying on, so do nothing forevermore:
   // try to congifure using IP address instead of DHCP:
   Ethernet.begin(mac, ip);
 }
 // give the Ethernet shield a second to initialize:
 delay(1000);
 Serial.println("connecting...");
 getip();                                          // THIS FUNCTION GET THE HTML FROM THE CHECKIP.DYNDNS.ORG

}

void loop()
{
 rawip="\0";               
 
 j = 0;

 getip();
 delay(3000);
while (client.available()) {                   //THIS WHILE LOOP REMOVES THE UNNECESSARY CHARACTERS FROM THE CHAR C

   char c = client.read();
   if ( c =='<')
   {
     j++; 
   }
   if ( j >= 1) {
     rawip = rawip + c;                       //GETTING ONLY THE <HTML> TAGS AND IP
   }
   Serial.print(c);                           // PRINTS THE WHOLE THING FROM THE LIKE SERVER AND STUFF
 }
 Serial.println("html:");
  Serial.println(rawip); 
 ipnew ="\0";                                 
ipnew =dec_rawip(rawip);                      // dec_rawip() function removes all other texts and tags and gets only the ip address from rawip

Serial.println(" New ip");
Serial.println(ipnew);
Serial.println("Old ip:");                  
 Serial.println(ipold);
 if ( ipold != ipnew)                         //IF THE OLD IP IS NOT SAME AS THE NEW IP THE NEW IP HAS TO BE UPDATED TO NO-IP SERVER..
 {
   ipold = "\0";
   ipold = ipnew;
   Serial.println(" Changing old IP to:");
   Serial.println(ipold);
  update_ddns();                              // THIS FUNCTION UPDATES THE NO-IP SERVER TO YOUR ACTUAL IP
  while (client2.available()) {               // THIS IS NOT WORKING I DONT KNOW WHYYYYYYYYYYYYYY >< BUT IT IS UPDATING THE IP..
   char c = client.read();
   Serial.print(c);
  }
    delay(5000);                              
   
 } else {
   Serial.println("Nothing to be changed");   // IF IP HASNT CHANGED THE NO-IP SERVER DOESNT NEED TO BE UPDATED
 }
  
 
 // if the server's disconnected, stop the client:
 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");    
   client.stop();
    
   delay(10000);                               //WAIT FOR SOME TIME
 }
}

void getip()                                     // GETIP FUNCTION 
{ 
 
 // if you get a connection, report back via serial:
 if (client.connect(server, 80)) {
   Serial.println("connected");
   // Make a HTTP request:
    client.println("GET / HTTP/1.0");
   client.println("Host: www.checkip.dyndns.org");
   client.println("Connection: close");
   client.println();
} 
}

String dec_rawip( String ip)       // GETTING THE IP FROM THE HTML STRING
{
 int y = ip.length();
char myStr[y];
int i;
char c[20];
String str;
i = ip.length();
 ip.toCharArray(myStr, i -1);
 
 str ="\0";
for (i=0;i < sizeof(myStr) - 1; i++)
 {
  if (myStr == '1' || myStr == '2' ||myStr == '3' ||myStr == '4' ||myStr == '5' ||myStr == '6'||myStr == '7'||myStr == '8'||myStr == '9'||myStr == '0' || myStr =='.' )
   {
 c = myStr;
 str = str + c;
   }
}
return(str); 
}  
void update_ddns()                                   // UPDATES YOUR IP TO NO-IP
{
   if (client2.connect(server2, 80)) {
   Serial.println("connected to no-ip");
   client2.println("GET /nic/update?hostname=your_user_address.no-ip.org HTTP/1.0");     // replace 'your_user_address.no-ip.org' by your hostname e.g jimmyhendricks.no-ip.org 
       client2.println("Host: dynupdate.no-ip.com");
        client2.println("Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");      // HERE U NEED TO PUT YOUR USERNAME AND PASSWORD BY ENCODING IT FIRST TO BASE64. GO TO https://www.base64encode.org/ AND TYPE YOUR USERNAME AND PASSWORD IN THE FORMAT username:password AND REPLACE 'dXNlcm5hbWU6cGFzc3dvcmQNCg==' BY THE ENCODED STRING
        client2.println("User-Agent: Arduino_update_client/1.0 YOUREMAILADDRESS@gmail.com");  // REPLACE YOUREMAILADDRESS BY YOUR EMAIL ADDRESS :|
   client2.println();
  
 } else {
   Serial.println("connection failed");                                         
 }
 client2.stop();
}

my English is bad, I'm using google translator.

But after reading enough, this is what we get done, basing on 3 things:

  • Arduino example WebClienteRepeating
  • One of the example presented here
  • A web server, created by someone else (can not remember the name)

does the following, ClienteWeb a No-ip automatically updated every 5 minutes + web server

Now I have a problem, how to do that when physically Ethernet cable is disconnected and reconnected ..... Arduino lift both the web server and the web client and automatically reconnect.

had thought about doing externally:

use a transistor as electronic switch such that put the RESET pin to GND (resetting arduino) ....

but not how to do the function

//----------------------------------
// Servidor web + cliente No-Ip
//----------------------------------

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

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192, 168, 1, 50);

// fill in your Domain Name Server address here:
IPAddress myDns(192, 168, 1, 1);

// initialize the library instance:
EthernetClient client;
EthernetServer servidor(888);
//----------------------------------------------------------Servidor
int PIN_LED = 12;
String readString = String(30); //lee los caracteres de una secuencia en una cadena. ***no entiendo***
//Los strings se representan como arrays de caracteres (tipo char)
String state = String(3); //****tampoco entiendo****
//-----------------------------------------------------------//
unsigned long lastConnectionTime = 0;             // última vez que se conecta al servidor, en milisegundos
const unsigned long postingInterval = 300L * 1000L; // Tiempo entre actualizacion, en  milisegundos
// La "L" es necesaria para usar numeros de tipo Long
//----------------------------------------------------------------------------
void setup() {
  // iniciar puerto serial:
  Serial.begin(9600);
  // dar al modulo ethernet tiempo para arrancar:
  delay(3000);
  // iniciar la conexion ethernet usando ip y dns del DHCP:
  Ethernet.begin(mac, ip, myDns);
  // print the Ethernet board/shield's IP address:
  Serial.print("direccion IP Arduino: ");
  Serial.println(Ethernet.localIP());
  if (Ethernet.begin(mac) == 0) {
    Serial.println("fallo conexion Ethernet usando DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  pinMode(PIN_LED, OUTPUT);
  digitalWrite(PIN_LED, LOW);
  state = "OFF";
}
//---------------------------------------------------------------------------
void loop() {
  // si hay datos entrantes de la conexión a la red.
  // enviarlo por el puerto serie. Esto es para la depuración
  // solo para ese proposito:
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
  // si han transcurrido diez segundos desde su última conexión,
  // Luego conecte de nuevo y enviar datos:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }
//----------------------------------------------------------------------------
//---------------------Servidor-----------------------------------------------
//----------------------------------------------------------------------------
//EthernetClient Crea un cliente que se puede conectar a 
    //una dirección específica de Internet IP
  EthernetClient cliente= servidor.available(); 
  if(cliente) {
      boolean lineaenblanco=true; //****no entiendo*****
      while(cliente.connected()) {
              if(cliente.available()) {
              char c=cliente.read(); 
                if(readString.length()<30) {
                  readString.concat(c);
                  //Cliente conectado
                  //Leemos petición HTTP caracter a caracter
                  //Almacenar los caracteres en la variable readString
                  } 
              if(c=='\n' && lineaenblanco) //Si la petición HTTP ha finalizado 
                  {
                  int LED = readString.indexOf("LED="); 
                    if(readString.substring(LED,LED+5)=="LED=T") {
                      digitalWrite(PIN_LED,LOW);
                      state="ON"; } 
                    else if (readString.substring(LED,LED+5)=="LED=F") {
                      digitalWrite(PIN_LED,HIGH); 
                      state="OFF";
                      }
                  //Cabecera HTTP estándar
                  cliente.println("HTTP/1.1 200 OK"); 
                  cliente.println("Content-Type: text/html"); 
                  cliente.println(); //Página Web en HTML 
                  cliente.println("<html>"); 
                  cliente.println("<head>"); 
                  cliente.println("<title>LAMPARA ON/OFF</title>"); 
                  cliente.println("</head>");
                  cliente.println("<body width=100% height=100%>"); 
                  cliente.println("<center>"); 
                  cliente.println("<h1>LAMPARA ON/OFF</h1>");
                  cliente.print("

"); 
                  cliente.print("Estado de la lampara: "); 
                  cliente.print(state); 
                  cliente.print("



"); 
                  cliente.println("<input type=submit value=ON style=width:200px;height:75px onClick=location.href='./?LED=T\'>"); 
                  cliente.println("<input type=submit value=OFF style=width:200px;height:75px onClick=location.href='./?LED=F\'>"); 
                  cliente.println("</center>"); 
                  cliente.println("</body>"); 
                  cliente.println("</html>"); 
                  cliente.stop();
                  //Cierro conexión con el cliente 
                  readString="";
                  }
              }
          }
      }
  }
//----------------------------------------------------------------------------
//--------este método hace una conexión HTTP con el servidor:-----------------
//----------------------------------------------------------------------------
void httpRequest() {
  // cerrar cualquier conexión antes de enviar una nueva solicitud.
  // Esto liberará la toma del escudo WiFi
  client.stop();

  // si hay una conexión con éxito:
  if (client.connect("dynupdate.no-ip.com", 80)) {
    Serial.println();
    Serial.println();
    Serial.println(">>>>>connectado a no-ip<<<<<");
    // Make a HTTP request:
    //replace yourhost.no-ip.org with your no-ip hostname
    client.println("GET /nic/update?hostname=Tu Dominio de no-ip HTTP/1.0");
    client.println("Host: dynupdate.no-ip.com");
    //encode your username:password (make sure colon is between username and password) 
    //to base64 at http://www.opinionatedgeek.com/dotnet/tools/base64encode/
    //and replace the string below after Basic with your encoded string
    //clear text username:password is not accepted
    //reemplazar Usuario@email.com:contraseña encriptados
    //la pagina de mas arriva sirve para tal caso
    client.println("Authorization: Basic Usuario@email.com:contraseña"); 
    client.println("User-Agent: Arduino Sketch/1.0 user@host.com");
    client.println();
    // tenga en cuenta el momento en que se realizó la conexión:
    lastConnectionTime = millis();
  }
  else {
    // Si no se Logra hacer Una Conexión::
    Serial.println("++++++++conneccion fallida a no-ip+++++++++");
  }
 
}

in the code there things you do not understand

Hello, I have a problem with this sketch.

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

byte mac[] = {0x98,0x4F,0xEE,0x01,0x8C,0xCA};


//IPAddress server(192,168,1,75);
IPAddress server(193,110,128,199);
IPAddress gateway(192,168,1,5);
IPAddress ip(192,168,1,100);
IPAddress subnet(255,255,255,0);
IPAddress dns(8,8,8,8);


EthernetClient client;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac,ip,dns,gateway,subnet);
  delay(1000);
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());
  
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    for(;;)
      ;
  }
    delay(1000);
  Serial.println("connecting...");
  

  if (client.connect(server, 80)) {
    
    Serial.println("connected");

    client.println("GET");
    client.println();
    
  } 
  else {
    Serial.println("connection failed");
  }
  
}

void loop()
{
  char c;
  if (client.available()) {
    c += client.read();
    Serial.print(c);
  }
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    
    for(;;)
      ;
  }
}

The problem: client.connect(server, 80)=0, therefore the result is the next:

IP = 192.168.  1.100
connecting...
connection failed

disconnecting.

Someone what my problem?

Thank you very much!

Does your code resemble the code above?