Googling for a ns lookup client for arduino, i couldn't find but one, the adafruit CC3000 MDNS. Can someone suggest other alternatives? My purpose is to be able to ping (Internet hosts in addition to local machines) using the icmp lib in the playground.
I use dns lookup with the ethernet shield. Is that the device you are using? I will presume it is by your prior posts.
Here is the code I use to resolve pool.ntp.org for my NTP client sketch. The include goes at the top of the sketch with the other ethernet includes, the timeServer variable goes in global variable declarations, and the rest goes in setup after the Ethernet.begin() call.
But this is a piece of cake I'll try it as soon as I'm back home. I was not aware of the existence of this DNSClient thing and it's strange I missed it. Where is it documented?
here is the whole code and it says dns failed. The Arduino ping test (to google) gives 100% OK (i resolve with wins ns lookup). What's wrong??
BTW, why did you want to resolve your time server?
NTP servers come and go. I want to use a current one, so I resolve pool.ntp.org to get a current active NTP server.
If your code fails the dns, then I suggest you use DHCP to get your network settings. Maybe your router isn't resolving the domains correctly, or isn't a dns server.
// put this in global variables
DNSClient dnClient;
// put this in setup
dnClient.begin(Ethernet.dnsServerIP());
// call this any time you want
if(dnClient.getHostByName("pool.ntp.org",timeServer) == 1)
Oops...
I was sure everything worked fine but today I am witnessing that I am getting Internet OK even when my router-modem link is removed, as if my router was caching name resolutions
here is my net
ISP - coax - modem - router - arduino
|
wifi
If I brake the router link to arduino link I am getting the Inet fail status
If I brake the router link to the modem I get Inet ok !!!
Below is the code
What would you recommend?
Thanks youTim
void manageRouter(){
/*How does this work
every 10 minutes resolve the server to confirm we have internet access
if we succeed, we log to phant the OK result and this serves as system health check
if we fail,
->we log the failure to the eeprom then we log no more till first subsequant success
->obviusely we log nothing to phant which will shaw holes in the given slot but as holes aren't
as noticeable,we;'ll log the epoch of the first failure once the failures are over
*/
static long failureStart;
static boolean slotChecked=false;
char server1[]= "www.google.com";
String timeString;
IPAddress ip;
if ((hmsLocal[1]%10)==0){ // round minute
if(!slotChecked){
slotChecked=true;
if(nsClient.getHostByName(server1,ip) == 1){// inet ok
if(inetFailed){
inetFailed=false;
logger(__LINE__,version,0);// stamp end of shortage
epoch2string(failureStart, timeString);
post2phant("!Inet_failure_since"+timeString);
// post2phant("!Inet_failure_since"+timeString);
}
epoch2string(epochLocal, timeString);
Serial.println("dns ok at "+timeString);
post2phant("Inet_ok_at_"+timeString);
return;
}
else {//inet failure
if (!inetFailed){//start of failure
inetFailed=true;
failureStart=epochLocal;
logger(__LINE__,version,0);
}
Serial.println("dns failed at "+timeString=+"-> cycling router");cycleRouter();
return;
}
}
else return; // slot checked
}
else{//not round minute
slotChecked=false;
return;
}
}
SurferTim:
I use dns lookup with the ethernet shield. Is that the device you are using? I will presume it is by your prior posts.
Here is the code I use to resolve pool.ntp.org for my NTP client sketch. The include goes at the top of the sketch with the other ethernet includes, the timeServer variable goes in global variable declarations, and the rest goes in setup after the Ethernet.begin() call.
Thanks for this. Worked for me, and confirmed why my UDP send was taking so long, it was the DNS Lookup. Interestingly, my informal timing seemed to indicate that the DNS lookup happening as part of
UdpNTP.beginPacket(address, 123);
was generally faster. I'm not really sure why, and given that there is variation it could be nothing. I expect, and haven't looked, that it should call the same code.
In attempting to estimate the round trip delay for my NTP reply, I am now starting my timer after the UdpNTP.beginPacket() statement.