cc3000 cannot getHostByName

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
ekremney
 
Posts: 7
Joined: Wed Jul 09, 2014 4:42 am

cc3000 cannot getHostByName

Post by ekremney »

Earlier this week, I changed my modem; current one uses 192.168.2.x for local IPs, unlike the previous one which was using 192.168.1.x

I was working with my arduino and cc3000 breakout board without no problem until that day. It seems that there is a problem with 192.168.2.x local IP addresses.

For a debug, I run WebClient example from Adafruit CC3000 library. I, here, put serial output for reference.

What could be the problem? Thank you.

Code: Select all

Hello, CC3000!

Free RAM: 1191

Initializing...

Attempting to connect to TTNET_AirTies_Air5650_3DEQ
Connected!
Request DHCP

IP Addr: 192.168.2.180
Netmask: 255.255.255.0
Gateway: 192.168.2.1
DHCPsrv: 192.168.2.1
DNSserv: 192.168.1.1
www.adafruit.com -> Couldn't resolve!


ekremney
 
Posts: 7
Joined: Wed Jul 09, 2014 4:42 am

Re: cc3000 cannot getHostByName

Post by ekremney »

I changed local IP range on modem interface from 192.168.2.x to 192.168.1.x and now it is working.

Why wasn't it working with 192.168.2.x, Is it because Adafruit library or CC3000 hardware?

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: cc3000 cannot getHostByName

Post by Franklin97355 »

Code: Select all

IP Addr: 192.168.2.180
Netmask: 255.255.255.0
Gateway: 192.168.2.1
DHCPsrv: 192.168.2.1
DNSserv: 192.168.1.1
www.adafruit.com -> Couldn't resolve!
Your cc3000 got an IP in the correct range (192.168.2.180) but your DNS server for some reason has an address of 192.168.1.1 which was the old gateway and won't route. Find out where the DNS is being set and fix that and it should work. Make sure your code isn't setting it

ekremney
 
Posts: 7
Joined: Wed Jul 09, 2014 4:42 am

Re: cc3000 cannot getHostByName

Post by ekremney »

franklin97355 wrote: Find out where the DNS is being set
I thought it is in somewhere of adafruit library. I am not a network guru, but I believe modem informs cc3000 about DNS when cc3000 first connects. Since other of my devices work without any problem, I think there is a problem in where cc3000 interprets address of DNS. Again, I have no extensive knowledge on computer networks; all of my premises could be wrong.

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: cc3000 cannot getHostByName

Post by tdicola »

Yep by default the CC3000 sketches will ask your router for the DNS server using DHCP. If you can, check the router configuration to see if it has any DHCP or DNS server configuration which might need to be updated to send the 192.168.2.1 value.

One other thing to try, let's see if setting a static IP address and explicit DNS servers help get you connected to your network. Grab the latest library code from github and open the buildtest example. Scroll down to this section of code:

Code: Select all

 /* Optional: Set a static IP address instead of using DHCP.
     Note that the setStaticIPAddress function will save its state
     in the CC3000's internal non-volatile memory and the details
     will be used the next time the CC3000 connects to a network.
     This means you only need to call the function once and the
     CC3000 will remember the connection details.  To switch back
     to using DHCP, call the setDHCP() function (again only needs
     to be called once).
  */
  /*
  uint32_t ipAddress = cc3000.IP2U32(192, 168, 1, 19);
  uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0);
  uint32_t defaultGateway = cc3000.IP2U32(192, 168, 1, 1);
  uint32_t dns = cc3000.IP2U32(8, 8, 4, 4);
  if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) {
    Serial.println(F("Failed to set static IP!"));
    while(1);
  }
*/
Uncomment the block of code and fill in the details for setting a static IP. You probably want an IP in the 192.168.2.x range. If you know the explicit netmask and default gateway values for your router then drop those in, otherwise I think 255.255.255.0 and 192.168.2.1 are what you want. Finally for the DNS server try using the 8.8.4.4 value for Google's DNS servers to start with now since it's a known working server. Run the sketch with those changes and let's see if it can connect with the 8.8.4.4 DNS server.

ekremney
 
Posts: 7
Joined: Wed Jul 09, 2014 4:42 am

Re: cc3000 cannot getHostByName

Post by ekremney »

tdicola wrote:One other thing to try, let's see if setting a static IP address and explicit DNS servers help get you connected to your network.
tdicola wrote:... try using the 8.8.4.4 value for Google's DNS servers to start with now since it's a known working server.
Using Google's DNS servers with static IP is a possible workaround for this problem; yet for my country, in where Google's DNS servers were prohibited for a month, it is not a feasible solution. I would like to stick to ISP's default DNS servers.

Mr. Dicola, I'd like to ask you another question. Is there any way to establish a healthy connection between cc3000 hardware and a server running node.js and socket.io? I would like to push data to my arduino at arbitrary times from a remote server.

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: cc3000 cannot getHostByName

Post by tdicola »

Sorry was away a couple days and couldn't reply sooner. You can actually use any DNS server with a static IP, including those that your ISP provides. Just change the 8.8.4.4 IP to the IP of your ISP's DNS servers (might need to check your network configuration on a computer to see what the DNS server IPs are). Just to check though, when you use a static IP and explicitly set the DNS servers does the CC3000 buildtest sketch work for you?

Good question about socket.io. I don't know of any library off hand that implements socket.io's protocol for the Arduino & CC3000 unfortunately. I'm not super familiar with the protocol either but want to say it's based on websockets. If so, it's a little tricky to run a websocket server on an Arduino. Websockets have a somewhat complex handshake which is requires generating a hash and doing other string manipulation that's tricky with only 2k of memory on the Arduino.

I would look into using raw TCP sockets--for example python has a pretty simple socket API (and I bet node.js has something similar these days too). Check out the chat server and echo server examples in the library for a few simple examples of listening for TCP connections and reading data from clients. You could have a sketch listen on a port (like 5000 for example) and then have a node.js or python script on your computer open a TCP connection to the Arduino's IP and port 5000 and send some commands. The wifi candy bowl monitor project here actually does something similar but just uses telnet to send commands manually: https://learn.adafruit.com/wifi-candy-bowl/overview

ekremney
 
Posts: 7
Joined: Wed Jul 09, 2014 4:42 am

Re: cc3000 cannot getHostByName

Post by ekremney »

I solved my problem using this* MQTT library. Now I can access to my arduino from outside of my house.

* https://github.com/nathanchantrell/pubsubclient

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”