Pages: [1]   Go Down
Author Topic: Webserver with dyn DNS  (Read 1076 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

to reach my Arduino webserver in the www without knowing my IP address, I used a dyndns service (no-ip in my case) and I know that my ISP will assign my a new IP regularly when I switch off and then on my router again (reset) because then I reconnect.
My question is: Does my ISP also assign me a new IP  if I always let my router on?
Then I would not need to update my IP with the so called DUC (dynamic update client) tool.

Thank you
Logged

using Arduino Uno Rev 3

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does my ISP also assign me a new IP  if I always let my router on?
Wouldn't this be better answered by your ISP?

Generally, though, the answer is yes. I never turn my router off, and it gets a new IP address about once a week.

Logged

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, thank you.
I will monitor the behaviour as from now.
Maybe I have some chanches making the arduino ethernet (as a client ) doing the request to update the new ip.
If someone is interested in this, too, there is an API http://www.noip.com/integrate/request

Can the Ethernet be Client and Server on the same time?
Will I first have to stop the server then start the client then do the update, then stop the client and restart the server (?)
« Last Edit: February 02, 2013, 11:01:25 am by karlok » Logged

using Arduino Uno Rev 3

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can the Ethernet be Client and Server on the same time?
Yes.

Quote
Will I first have to stop the server then start the client then do the update, then stop the client and restart the server (?)
No.
Logged

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, thanks.

Now I am trying to use the API described here http://www.noip.com/integrate/request

Code:
// NO-IP, Dynamic Update Client, 02.FEB.13

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "dynupdate.no-ip.com";

EthernetClient client;

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

  Serial.println("[NOIP-DUC]\n");
  Serial.println("Getting IP address from DHCP ...");

  if (Ethernet.begin(mac) == 0)
  {
    Serial.println("Failed to configure Ethernet using DHCP !");
    while (1)
      ;
  }

  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
  Serial.println();

  Serial.print("Connecting to ");
  Serial.print(server);
  Serial.println(" ...");
  client.connect(server, 80);
 
  // checking for answer?
 
  Serial.println("OK. Sending request...\n");
  client.println("GET /nic/update?hostname=mytest.testdomain.com&myip=1.2.3.4 HTTP/1.0");
  client.println("Host: dynupdate.no-ip.com");
  client.println("Authorization: Basic base64-encoded-auth-string");
  client.println("User-Agent: Bobs Update Client WindowsXP/1.2 bob@somedomain.com");
 
  Serial.println("ready?!");
 
}



void loop()
{
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  if (Serial.available())
  {
    char c = Serial.read();
    client.print(c);
  }

  if (!client.connected())
  {
    Serial.println();
    Serial.println("Disconnecting.");
    client.stop();
    while (1);
  }
}


Why don't I get any answer? It just disconnects after ~5 seconds.
Logged

using Arduino Uno Rev 3

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to show all your serial output.

Your domain isn't mytest.testdomain.com, is it?

Your current IP isn't 1.2.3.4, is it?

Your Base64 encoded authorization string isn't base64-encoded-auth-string, is it?

Logged

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After having done more debugging, I realized I cannot even connect to dynupdate.no-ip.com

I use this to check:
Quote
  if (client.connect(server, 80))
  {
    Serial.println("Connected.");
    
    while (client.connected())
    {
      while (client.available())
      {
        char c = client.read();
        Serial.print(c);
      }
    }
    client.stop();
  }
  else
    Serial.println("Error connecting!");


My code:
Code:
// NO-IP, Dynamic Update Client, 02.FEB.13

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

byte mac[] =
{
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
char server[] = "dynupdate.no-ip.com";

EthernetClient client;

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

  Serial.println("[NOIP-DUC]\n");
  Serial.println("Getting IP address from DHCP ...");

  if (Ethernet.begin(mac) == 0)
  {
    Serial.println("Failed to configure Ethernet using DHCP !");
    while (1)
      ;
  }

  //Give some time to initialize:
  delay(2000);

  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
  Serial.println();

  Serial.print("Connecting to ");
  Serial.print(server);
  Serial.println(" ...");

  if (client.connect(server, 80))
  {
    Serial.println("Connected.");
   
    while (client.connected())
    {
      while (client.available())
      {
        char c = client.read();
        Serial.print(c);
      }
    }
    client.stop();
  }
  else
    Serial.println("Error connecting!");
}

void loop()
{
  if (client.available()) // this cannot be reached by now
  {
    char c = client.read();
    Serial.print(c);
  }

  if (Serial.available())
  {
    char c = Serial.read();
    client.print(c);
  }

  if (!client.connected())
  {
    Serial.println();
    Serial.println("Disconnecting.");
    client.stop();
    while (1)
      ;
  }
}

Serial output
[NOIP-DUC]

Getting IP address from DHCP ...
My IP address: 192.168.2.124

Connecting to dynupdate.no-ip.com ...
Error connecting!

Disconnecting.

Logged

using Arduino Uno Rev 3

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you connect to other servers?
Logged

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, and I tried using http prefix
Code:
char server[] = "http://dynupdate.no-ip.com";
and then the output is

[NOIP-DUC]

Getting IP address from DHCP ...
My IP address: 192.168.2.124

Connecting to http://dynupdate.no-ip.com ...
Connected.

Disconnecting.

« Last Edit: February 02, 2013, 12:05:05 pm by karlok » Logged

using Arduino Uno Rev 3

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The prefix http:// should be omitted.

And I found on this forums, the issue has been already discussed and here is the solution
http://arduino.cc/forum/index.php/topic,95456.msg720162.html#msg720162

My problem was that I did not always use the same MAC address so that my router had too many ones to save and it is restricted to grant internet access to only the first 5 ones connected or kind of similiar, so I had to flush this and it worked again.
« Last Edit: February 02, 2013, 12:55:01 pm by karlok » Logged

using Arduino Uno Rev 3

0
Offline Offline
Tesla Member
***
Karma: 148
Posts: 9750
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Make sure you use your no-ip email address as the no-ip username and the domain you are using (yourhost.no-ip.org is in the example, but my account is .com instead of .org). I tested the code in the posted link with my changes and got the expected response for my no-ip account.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now it works!
( my account was .org )
Both using my email address and my user name worked (as the no-ip username)
The answer is "nochg <ipaddr>"
Logged

using Arduino Uno Rev 3

Germany
Offline Offline
Full Member
***
Karma: 1
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also implemented parsing the result, i.e. getting the Date and the Message:

Quote
    String  buf = "";
    String  msg = "";
    boolean tak = false;
    while (client.connected())
    {
      while (client.available())
      {
        char c = client.read();
        //Serial.print(c); // verbose?
        buf += c;
        if (tak)
          msg = buf;
        if (c == 10)
        {
          buf.trim();
          if (buf.indexOf("Date:") == 0)
            Serial.println("DATE = " + buf);
          if (buf == "") //empty line -> message
            tak = true;         
          buf = "";
        }
      }
    }
    client.stop();
    msg.trim();
    Serial.println("MESSAGE = " + msg);
    Serial.println("Disconnecting.");

Logged

using Arduino Uno Rev 3

Pages: [1]   Go Up
Jump to: