I’ve seen other threads regarding this issue, but most are somewhat old, referring to older firmware versions, or not specifically the Photon. I’m able to make (http) tcp connections by IP address to remote hosts over the internet. However, when I use a hostname, the connection always fails.
WiFi.resolve("hostname");
WiFi.dnsServerIP();
both return 0.0.0.0. I tried to setStaticIP/useStaticIP, supplying my own DNS server, but it didn’t stick.
I moved closer to the router, and made sure it’s using a dynamicIP. I’ve gotten it to successfully resolve a single IP:
did not resolve google.com
resolved www.facebook.com: 31.13.65.36
did not resolve community.particle.io
did not resolve notavalidhost.example.com
did not resolve google.com
did not resolve www.facebook.com
did not resolve community.particle.io
did not resolve notavalidhost.example.com
But never more than once (and the same hostname it successfully resolves seems to be quite random).
Well, that’s good progress! Can I ask if your DNS setup is complex? Most people use their router/access-point as their DNS server, but other configurations are possible. There have been problems in the past with multilevel DNS server setups.
Just so we are clear: are you running the sample code I wrote in that thread that uses gethostbyname or are you running @Hootie81 's separate DNS client?
There was problem on the older Spark Core that the MAC address inside the WiFi chip would get messed up and that made DNS not work. I don’t think that can happen on a Photon with its different WiFi module. A lot of the voodoo about what fixed DNS problems was eventually traced back to the MAC issue and writing a new MAC address would fix it (until the next time it broke).
I’m using a version of your code that uses gethostbyname. I couldn’t get @Hootie81’s dns client working (there are a few issues, I can’t seem to resolve).
The timeout for WiFi.resolve() is quite short, 5 seconds, on the Photon. Since the call is blocking I can see why it wouldn’t want to be extremely long, but 5 seconds seems a little short to me. WiFi.resolve() calls inet_gethostbyname() in inet_hal, which calls right into the WICED DNS resolver on the Photon with a timeout of 5 seconds. Also, this means that the DNS resolver is entirely different between the Core, Photon and Electron.
I was looking at this just now and I agree with @rickkas7 assessment that 5 seconds could be a little short.
One other small point: in the test code are you calling gethostbyname() or inet_gethostbyname()?
It makes a big different since the one without the inet_ prefix only compiles for a Core and if you have a Core, we should check your MAC address! If you are compiling for a Photon, I don’t think gethostbyname should compile but I haven’t checked.
So I spoke a bit too soon, when I modified the test to output the IP for multiple domain names, it works for the first two, but then proceeds to output the second IP for all subsequent requests:
OK, none of those are right. I think your ISP is hijacking requests that do not land on host and supplying a “helpful” web address (CenturyLink in the first case) to help you find the host you are looking for.
Something seems wrong in your DNS server. Do other hosts on this router work OK? Can you run the nslookup utility to see what is really happening? In nslookup, use the command set debug and then type a hostname. Note that “facebook.com” is not a hostname but magic converts it to “www.facebook.com” in most cases.