Go Down

Topic: Bug with EthernetShield and Dns library error (Read 3 times) previous topic - next topic

k_apo

Hi,
I have a problem with the following code:

Code: [Select]
#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.

SurferTim

My test worked. I used a modification of the DhcpAddressPrinter sketch.
Code: [Select]
#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

PaulS

Quote
It showed

Something really secret, apparently.  8)

k_apo

I tried your code and it doesn't work for me.

what is your SO? and Arduino libraries version?

SurferTim

#4
Oct 01, 2012, 02:21 pm Last Edit: Oct 01, 2012, 02:30 pm by SurferTim Reason: 1
@PaulS: VERY SECRET! So secret it failed to display! LOL
Quote
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?


k_apo

#5
Oct 01, 2012, 04:57 pm Last Edit: Oct 01, 2012, 05:06 pm by k_apo Reason: 1
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)?

SurferTim

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.

k_apo


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.

SurferTim

#8
Oct 01, 2012, 05:11 pm Last Edit: Oct 01, 2012, 05:17 pm by SurferTim Reason: 1
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.

k_apo

#9
Oct 01, 2012, 05:22 pm Last Edit: Oct 01, 2012, 05:35 pm by k_apo Reason: 1

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.

SurferTim

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.

k_apo


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.

chrylarson

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!

Go Up