user23642: There are lots of examples around how to connect with an NTP server, but I do not see how to find such an IP-address. From the examples I conclude I need to find it on for example pool.ntp.org, but I do not even see how to get IP-addresses out of there myself, let alone to let my Arduino do it. Of course I looked at the How do I use pool.ntp.org page, but it doesn't seem to say anything about finding IP-addresses.
Questions


Is it possible to let my Arduino find a working NTP server (using the EtherCard library), and if so, how?
All the examples I saw have an NTP server IP address hard coded, isn't that a bad practice and also a bad idea for a longer running project?


The code I currently find the easiest to understand is from the Arduino forum, and has an IP address hard coded.
I have an Arduino Nano ATmega328 with a ENC28j60 ethernet shield, and therefore use the EtherCard libray. I do know of existence of RTC devices but I would prefer NTP.

user22924: The EtherCard library offers a method called ether.dnsLookup(host) where you ask it to look up the IP address for you.
etherCard.dnsLookup("pool.ntp.org");

...only that might fail, so it returns a false:
if (!etherCard.dnsLookup("pool.ntp.org")) {
    // Error! Do something!
    return;
} // if

But if it works...
if (!etherCard.dnsLookup("pool.ntp.org")) {
    // Error! Do something!
    return;
} // if
// At this stage, dnsLookup() worked...

// Can now connect to IP adress in etherCard.hispip

Now: please note that ntp.org would prefer you to use a more precise locale than pool.ntp.org. If you're going to distribute your application worldwide, then that's fine. But I always use au.pool.ntp.org because I'm in the Australian region. There are others that you can/should use instead.

23642: <p>There are lots of examples around how to connect with an NTP server, but I do not see how to find such an IP-address. From the examples I conclude I need to find it on for example <a href="http://www.pool.ntp.org/zone/nl" rel="nofollow">pool.ntp.org</a>, but I do not even see how to get IP-addresses out of there myself, let alone to let my Arduino do it. Of course I looked at the <code>How do I use pool.ntp.org</code> page, but it doesn't seem to say anything about finding IP-addresses.</p>

<p><strong>Questions</strong></p>

<blockquote>
  <ol>
  <li>Is it possible to let my Arduino find a working NTP server (using the EtherCard library), and if so, how?</li>
  <li>All the examples I saw have an NTP server IP address hard coded, isn't that a bad practice and also a bad idea for a longer running project?</li>
  </ol>
</blockquote>

<p>The code I currently find the easiest to understand is from the <a href="http://forum.arduino.cc/index.php?topic=171941.0" rel="nofollow">Arduino forum</a>, and has an IP address hard coded.</p>

<p>I have an Arduino Nano ATmega328 with a ENC28j60 ethernet shield, and therefore use the <code>EtherCard</code> libray. I do know of existence of RTC devices but I would prefer NTP.</p>
 22924: <p>The <code>EtherCard</code> library offers a method called <code>ether.dnsLookup(host)</code> where you ask it to look up the IP address for you.</p>

<pre><code>etherCard.dnsLookup("pool.ntp.org");
</code></pre>

<p>...only that might fail, so it returns a <code>false</code>:</p>

<pre><code>if (!etherCard.dnsLookup("pool.ntp.org")) {
    // Error! Do something!
    return;
} // if
</code></pre>

<p>But if it works...</p>

<pre><code>if (!etherCard.dnsLookup("pool.ntp.org")) {
    // Error! Do something!
    return;
} // if
// At this stage, dnsLookup() worked...

// Can now connect to IP adress in etherCard.hispip
</code></pre>

<p>Now: please note that <code>ntp.org</code> would prefer you to use a more precise locale than <code>pool.ntp.org</code>. If you're going to distribute your application worldwide, then that's fine. But I always use <code>au.pool.ntp.org</code> because I'm in the Australian region. There are <a href="http://www.pool.ntp.org/zone/@" rel="nofollow">others</a> that you can/should use instead.</p>
