Pages: 1 [2]   Go Down
Author Topic: no-ip and Arduino Ethernet Shield  (Read 7151 times)
0 Members and 1 Guest are viewing this topic.
SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some of the stuff on the no-ip page just doesn't make scense, like the below statement.


An example update request string
http://username:password@dynupdate.no-ip.com/nic/update?
hostname=mytest.testdomain.com&myip=1.2.3.4


that means you enter that URL via a browser.

if you connect using your own program, then you need to break down that url to the components as per http protocol.
connect to host dynupdate.no-ip.com port 80
send the URI /nic/update?hostname=mytest...
send the rest of http protocol header, host, authorization, user-agent, etc.

the browser simply does all that in its program for you.
Logged

SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, I finally got a few minutes to do a quick test. 

This code works (you need to replace the hostname and the encoded username:password with your values of course)

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

// 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(9600);
  // 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:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // 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=yourhhost.no-ip.org 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 dXNlcm5hbWU6cGFzc3dvcmQ=");
    client.println("User-Agent: Arduino Sketch/1.0 user@host.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(;;)
      ;
  }
}


this is my serial monitor output (not my real ip address), result is nochg, meaning my ip address did not change
Code:
connecting...
connected
HTTP/1.1 200 OK
Date: Sat, 10 Mar 2012 01:37:40 GMT
Server: Apache/2
Content-Location: update.php
Vary: negotiate
TCN: choice
Content-Length: 20
Connection: close
Content-Type: text/plain; charset=UTF-8

nochg 50.131.456.123
disconnecting.


FWIW, un-encoded clear text password does not work.

Hope this helps.
Jerry
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8902
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
that means you enter that URL via a browser.

The example no-ip header code works, so I'll have to see what is different in what I tried that doesn't work. I'm still curous about the browser url method below. I can't get it to work with my data, as the "username:password@dynupdate" part seems to possibly cause a DNS lookup failure or confuses IE.

Code:
http://username:password@dynupdate.no-ip.com/nic/update?hostname=mytest.testdomain.com&myip=1.2.3.4
Logged

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

SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try this (I only tested on Chrome browser, I imagine this should work in firefox as well)

http://"username:password"@dynupdate.no-ip.com/nic/update?hostname=<your hostname>

that works for me, it returns
nochg

This is a fairly common URL format for ftp protocol, like when downloading files via ftp from a secured ftp server you can enter

Code:
ftp://username:password@<ftphost>/path to file

Actually, from the w3c spec, entering the username and password is part of ftp protocol url spec, but it is not mentioned for http protocol. So it may not work for all browsers.

http://www.w3.org/Addressing/URL/url-spec.txt

you can see that in page13-14 of the spec
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8902
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can get the url to work with an old version of firefox (it first gives a warning), But IE says it can't find the url somewhat like it is searching the hard drive or similar for the location. More head scratching.
Logged

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

SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.





Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8902
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

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

SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Pages: 1 [2]   Go Up
Jump to: