Pages: [1]   Go Down
Author Topic: Bug with EthernetShield and Dns library error  (Read 2984 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I have a problem with the following code:

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 Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My test worked. I used a modification of the DhcpAddressPrinter sketch.
Code:
#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
Online Online
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It showed
Something really secret, apparently.  smiley-cool
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

what is your SO? and Arduino libraries version?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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?

« Last Edit: October 01, 2012, 07:30:11 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 1
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: