DNS issue with EtherCard library, ENC28J60 module, and Nano v3

I’m having an issue with the EtherCard library (https://github.com/jcw/ethercard) and an ENC28J60 module (like this one: http://www.hardcopyworld.com/ngine/aduino/wp-content/uploads/sites/3/2013/12/ENC28j60-Ethernet-Interface-Module1.jpg). I’m using the ethernet module with a Nano v3.

The ethernet module itself seems to be functioning correctly, since the backSoon example (https://github.com/jcw/ethercard/blob/master/examples/backSoon/backSoon.ino) works just fine.

However, without altering anything in the physical setup (e.g. I don’t change any of the wiring), when I try to run the Twitter example (https://github.com/jcw/ethercard/blob/master/examples/twitter/twitter.ino), I get this in the serial monitor in the Arduino IDE:

[Twitter Client]
IP:  192.168.2.117
GW:  192.168.2.1
DNS: 208.67.222.222
DNS failed
SRV: 0.0.0.0
Sending tweet...

After which nothing happens (a tweet is supposed to be posted).

The first time, the only modification I made was to the token (as I’m supposed to):

(lines 15-16)

//OAUTH key from http://arduino-tweet.appspot.com/
#define TOKEN   "<my token>"

The second time, I changed line 58 to this:

if (ether.begin(sizeof Ethernet::buffer, mymac, 8) == 0)

The results are the same each time (DNS failed, and nothing seems to happen).

I’ve searched all over for a solution to this, and I can’t seem to figure out what’s wrong with the code. I should note that I downloaded and used the most recent version of the EtherCard library.

I should also note that the end goal of my little exercise is to send an HTTP POST request to a server (e.g. mydomain.com:3011) - if getting this sketch working isn’t getting me closer to that goal, please feel free to point out an alternative.

Thanks for taking the time to read this.

Any help would be appreciated.

It is not possible to post to twitter just like that anymore. Either use a certain service, or do all the security things in the sketch.

Did you do everything that is written here ? http://arduino-tweet.appspot.com/ Did you get a token ? Do you know if that service is still running ?

Peter_n:
It is not possible to post to twitter just like that anymore.
Either use a certain service, or do all the security things in the sketch.

Did you do everything that is written here ? http://arduino-tweet.appspot.com/
Did you get a token ? Do you know if that service is still running ?

Hello,

Thank you for your reply.

Others have used the example successfully, so I figured it should work for me, too. I do indeed have a token for it.

I went and tested it with the Postman app (http://www.getpostman.com/), which sent this HTTP request:

POST /update?token=<mytoken>&status="test2" HTTP/1.1
Host: arduino-tweet.appspot.com
Cache-Control: no-cache

And everything worked correctly (i.e. a tweet was successfully posted). So, I don’t see why the example shouldn’t work (that is, from the Arduino, as opposed to an app on my computer). It seems to be a DNS error, but I don’t know how to resolve that.

Thanks again.

I downloaded the newest Ethercard, used the twitter example, changed "mymac", run it on Nano+ENC28J60, and got this:

[Twitter Client]
IP:  192.168.1.10
GW:  192.168.1.1
DNS: 192.168.1.1
SRV: 173.194.65.141
Sending tweet...
Got a response!
HTTP/1.0 403 Forbidden
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Date: Sun, 22 Mar 2015 02:51:45 GMT
Server: Google Frontend
Content-Length: 28
Alternate-Protocol: 80:quic,p=0.5

Error 403 - token is invalid

I suppose that is perfectly normal, without having a token. The printed DNS is the DNS server in my router. You use OpenDNS.

I had to change the "mymac" because the original one stopped the sketch. Perhaps that mac is still in my router en blocked somehow.

The "ether.dnsLookup()" takes about 5ms.

  unsigned long t1=micros();
  boolean r = ether.dnsLookup(website);
  unsigned long t2=micros();
  
  Serial.println(t2-t1);
  
  if (!r)
    Serial.println(F("DNS failed"));

This gives always a value of about 5000 to 5100.

The "ether.dnsLookup()" is here : https://github.com/jcw/ethercard/blob/master/dns.cpp It returns false, but it doesn't return an error code, so it is not known what the problem is. You could change that file to print extra messages. Or you could try to use the default DNS instead of OpenDNS.

Peter_n: I downloaded the newest Ethercard, used the twitter example, changed "mymac", run it on Nano+ENC28J60, and got this:

[Twitter Client]
IP:  192.168.1.10
GW:  192.168.1.1
DNS: 192.168.1.1
SRV: 173.194.65.141
Sending tweet...
Got a response!
HTTP/1.0 403 Forbidden
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Date: Sun, 22 Mar 2015 02:51:45 GMT
Server: Google Frontend
Content-Length: 28
Alternate-Protocol: 80:quic,p=0.5

Error 403 - token is invalid



I suppose that is perfectly normal, without having a token.
The printed DNS is the DNS server in my router. You use OpenDNS.

I had to change the "mymac" because the original one stopped the sketch. Perhaps that mac is still in my router en blocked somehow.

The "ether.dnsLookup()" takes about 5ms.



  unsigned long t1=micros();   boolean r = ether.dnsLookup(website);   unsigned long t2=micros();     Serial.println(t2-t1);     if (!r)     Serial.println(F("DNS failed")); ```

This gives always a value of about 5000 to 5100.

The "ether.dnsLookup()" is here : https://github.com/jcw/ethercard/blob/master/dns.cpp It returns false, but it doesn't return an error code, so it is not known what the problem is. You could change that file to print extra messages. Or you could try to use the default DNS instead of OpenDNS.

Thank you for the in-depth reply.

I've rotated through randomly selected MAC addresses, but without any luck.

As for the DNS server, how would I go about using a different one? (I haven't changed dns.cpp (it seems to point automatically to 8.8.8.8).) I added some extra print statements, but nothing seems to stand out. Oddly enough, returning to previous functioning code now results in errors. Out of curiosity, how would I go about checking my router for issues? (Perhaps it's the root of all my problems...)

Thank you again.

I don't know what is going on. I suppose your router has still the normal settings. Perhaps your computer has set the DNS to OpenDNS. So I changed the DNS on my computer from automatic to OpenDNS 208.67.222.222 But that didn't help, I still got : "DNS: 192.168.1.1". I don't know why. I did a restart, and I check my network information, and confirmed that the DNS was set to OpenDNS.

The EtherCard dns.cpp uses indeed 8.8.8.8 from Google for DNS loopup. But only if the DNS was still zero and not set to a DNS server.

I tried to force another DNS server. The four "ether.dnsip[ .." are added to set it to OpenDNS.

  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  // Force DNS to OpenDNS 208.67.222.222, 208.67.220.220
  // Let's choose the other one : 208.67.220.220
  ether.dnsip[0] = 208;
  ether.dnsip[1] = 67;
  ether.dnsip[2] = 220;
  ether.dnsip[3] = 220;

  ether.printIp("IP:  ", ether.myip);

That did work. The EtherCard lookup uses now OpenDNS. It takes 20ms to 30ms which is slower than the DNS of my internet provider. The response was the same, only the DNS was what I forced into it, the rest is the same.

You have a different DNS value, but that doesn't have to the be problem. Since your dnsLookup() failed, you could change the dns.cpp and add error messages to "EtherCard::dnsLookup", or return an error value instead of just "false".

Are you sure you have the newest EtherCard library ? A bug in dns.cpp was fixed in januari 2015.

P.S.: You don't have to quote my post, since my post is already there ;) You can use the "REPLY" button, or the "Quick Reply" input field.

Thank you again for a detailed reply.

I've hardcoded the DNS address to 8.8.8.8 (I took out the conditional statement, as well). It doesn't seem to fix the problem.

I deleted the EtherCard library that I had in the libraries folder and re-downloaded it from Github. For me, it's taken almost a minute for the "DNS failed" message to come up. I've used both USB power (through the Nano for the module), and I've externally-powered the Ethernet module (3v3 through a TI LP2950-33LPRE3) - trying 8 different combinations of solutions, and nothing seems to work. At the end of it, it wouldn't even print "DNS failed."

At this point I think the Ethernet module is probably faulty. I'm going to check the connections on the ENC28J60 chip itself (and probably re-solder them). After that, I'm not sure what to do.

Thanks again. Unfortunately, it seems like this problem is basically at a dead end.

Perhaps. You could check your computer that no other version of EtherCard is installed.
I don’t know what else to do. It is working here as it is supposed to do.

I tried it on a different computer, and the same thing happens. It's either my router or the module.

If I find the solution, I'll post it here.

Thank you again for your help.

Hi,

sorry if this topic is to old, but i have exactly the same issue with the same conclusion. Do you find a solution ?

For me it works with other library :UIPEthernet.h but I prefer to use Ethercard library Thank.

I am also facing the same problem, did any of you solve it? Please help me out here

I had the same problem when i called dnsLookup. I checked the logs on my router, it received a dns request from arduino of the wrong format. For two days I puzzled over the structure of DNS queries...

1) make sure that the "Allow Remote Requests" flag is set (DNS server settings on the router) 2) check second param fromRam=true in the ether.dnsLookup function so it knows that the string is in ram and not in PROGMEM.

In my case, the problem was that I made a PROGMEM in the body of the setup function ;( I was upset that the author did not describe his solution in this topic. Hope my solution helps someone.