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 (EtherCard/twitter.ino at main · njh/EtherCard · GitHub), I get this in the serial monitor in the Arduino IDE:
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.
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.
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.
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...)
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.
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 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...
make sure that the "Allow Remote Requests" flag is set (DNS server settings on the router)
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.