Offline
Newbie
Karma: 1
Posts: 13
|
 |
« on: October 01, 2012, 03:15:02 am » |
Hi, I have a problem with the following code: #include <SPI.h> #include <Ethernet.h> #include <Dns.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
char server[] = "www.arduino.cc"; int serverport = 80;
void setup() { // start serial port: Serial.begin(115200); // give the ethernet module time to boot up: delay(1000); // start the Ethernet connection using a fixed IP address and DNS server: //Ethernet.begin(mac, ip, ipdns, ipgw, mask); Ethernet.begin(mac); // print the Ethernet board/shield's IP address: Serial.print("My IP address: "); Serial.println(Ethernet.localIP()); }
void loop() { DNSClient dns; // OPENDNS IPAddress dns_ip(208, 67, 222, 222); IPAddress out_ip; dns.begin(dns_ip); dns.getHostByName(server, out_ip); Serial.println(out_ip); delay(5000);
} I use Debian Sid and Arduino 1.0.1 with an Arduino Uno board. Instead of showing the IP address of the hostname www.arduino.cc it shows me 0.0.0.0. I found a problem in the dns library but I want to know if someone of you have my same problem. I reported it also on the Arduino bug tracker on google code http://code.google.com/p/arduino/issues/detail?id=1056. thank you very much.
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #1 on: October 01, 2012, 07:14:44 am » |
My test worked. I used a modification of the DhcpAddressPrinter sketch. #include <SPI.h> #include <Ethernet.h> #include <Dns.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[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// 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);
pinMode(4,OUTPUT); digitalWrite(4,HIGH);
// 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(;;) ; } // print your local IP address: Serial.print("My IP address: "); for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println();
DNSClient dns; IPAddress remote_addr; Serial.print("Google is "); dns.begin(Ethernet.dnsServerIP()); dns.getHostByName("www.google.com",remote_addr); Serial.println(remote_addr); }
void loop() {
}
It showed
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35483
Seattle, WA USA
|
 |
« Reply #2 on: October 01, 2012, 07:18:53 am » |
It showed Something really secret, apparently. 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 13
|
 |
« Reply #3 on: October 01, 2012, 07:20:01 am » |
I tried your code and it doesn't work for me.
what is your SO? and Arduino libraries version?
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #4 on: October 01, 2012, 07:21:46 am » |
@PaulS: VERY SECRET! So secret it failed to display! LOL Google is 74.125.227.82
I'm using IDE v1.0.1 downloaded from the Arduino site and installed in a local directory. edit: I used Ubuntu v11.10 for this test. What does your serial monitor display? Does it still show 0.0.0.0?
|
|
|
|
« Last Edit: October 01, 2012, 07:30:11 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 13
|
 |
« Reply #5 on: October 01, 2012, 09:57:58 am » |
Yes my serial display still shows 0.0.0.0.
I guess that at this point is a problem with my SO or with some libraries in it.
are there any other who want to try the previous code (one of the two or both)?
|
|
|
|
« Last Edit: October 01, 2012, 10:06:29 am by k_apo »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #6 on: October 01, 2012, 10:08:29 am » |
Which version of the IDE are you using? What operating system? Windows?
IDE v1.0.1 is the only version that works reliably for me.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 13
|
 |
« Reply #7 on: October 01, 2012, 10:09:32 am » |
Which version of the IDE are you using? What operating system? Windows?
IDE v1.0.1 is the only version that works reliably for me.
I'm using Debian Sid with Arduino IDE v 1.0.1.
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #8 on: October 01, 2012, 10:11:50 am » |
Are you using the IDE downloaded from the Arduino site? My Ubuntu repository version had some problems.
edit: Insure if you download the Arduino site version to run it using the arduino shell script in the directory in which it was unpacked.
|
|
|
|
« Last Edit: October 01, 2012, 10:17:11 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 13
|
 |
« Reply #9 on: October 01, 2012, 10:22:40 am » |
Are you using the IDE downloaded from the Arduino site? My Ubuntu repository version had some problems.
Ok, I was using the packaged version of the software and it simply doesn't work. I tried to download the IDE from the arduino web site and it works. The problem is not the Network library but something wrong in debian (and ubuntu) configuration. Thank you all for helping me to understand where is the problem.
|
|
|
|
« Last Edit: October 01, 2012, 10:35:58 am by k_apo »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #10 on: October 01, 2012, 10:46:12 am » |
Good news on that! Insure you go back to the arduino code page and let them know it was not the arduino IDE code malfunction.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 13
|
 |
« Reply #11 on: October 01, 2012, 10:47:20 am » |
Good news on that! Insure you go back to the arduino code page and let them know it was not the arduino IDE code malfunction.
Yes sure, I've already done it. Thank you again.
|
|
|
|
|
Logged
|
|
|
|
|
Dallas, TX
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #12 on: October 19, 2012, 08:09:42 am » |
I also had to build the Arduino software from the github source to get the DNS functions to work. Both the Windows and linux-64bit downloads would return 0.0.0.0. Once I built the software from source the same code worked.
Thank you for sharing this!
|
|
|
|
|
Logged
|
|
|
|
|
|