CC3000 - No way to set the right DNS

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fab64
 
Posts: 24
Joined: Sat Jun 14, 2014 12:11 pm

CC3000 - No way to set the right DNS

Post by fab64 »

Hi all,

I am using the CC3000 breakout board and the board never gets the right DNS from my router which also acts as DHCP server (by the way, all my computers and other boards always get it).

So I have tried to set the static IP using the code published here:

viewtopic.php?f=22&t=54325&p=276677&hil ... ns#p276677

No way, the board gets the right DNS occasionally only. Most of the time it doesn't, getting 76.83.0.0.

Moreover if I power arduino and the board through my MAC's USB port, it hangs connecting to the network.

I have double checked solders and wiring. I have tested it with Apple Airport and a DLink router with the same results.

Is my board damaged? What else I can try?

Thank you in advance for your help.

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

Re: CC3000 - No way to set the right DNS

Post by tdicola »

Do you mind posting a sketch you use to set the static IP? Let's check how its being set so we can troubleshoot a little further. It's odd that you're getting an unexpected result when setting a static value--my suspicion is that the static IP set might be failing in some way and not actually being set.

User avatar
fab64
 
Posts: 24
Joined: Sat Jun 14, 2014 12:11 pm

Re: CC3000 - No way to set the right DNS

Post by fab64 »

Hi tdicola,

thank you for your answer.

I have attached my code below.

Code: Select all

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "utility/netapp.h"

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIVIDER); // you can change this clock speed but DI

#define WLAN_SSID       "wirelessnetwork"        // cannot be longer than 32 characters!
#define WLAN_PASS       "pwd"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2


bool setStaticIPAddress(uint32_t ip, uint32_t subnetMask, uint32_t defaultGateway, uint32_t dnsServer)
{
  // Update DHCP state with specified values.
  // This will be saved in non-volatile storage internally so it will persist across CC3000 reset.
  if (netapp_dhcp(&ip, &subnetMask, &defaultGateway, &dnsServer) != 0) {
    return false;
  }
  // Reset CC3000 to use modified setting.
  wlan_stop();
  delay(200);
  wlan_start(0);
  return true;
}

bool setDHCP() {
  return setStaticIPAddress(0, 0, 0, 0);
}


/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n")); 

  displayDriverMode();
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }
  
  uint16_t firmware = checkFirmwareVersion();
  if (firmware < 0x113) {
    Serial.println(F("Wrong firmware version!"));
    for(;;);
  } 
  
  displayMACAddress();
  
  /* Optional: Get the SSID list (not available in 'tiny' mode) */
#ifndef CC3000_TINY_DRIVER
  listSSIDResults();
#endif
  
  /* Delete any old connection data on the module */
  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while(1);
  }
  
  /* Set static IP address.
     Note this only needs to be called once and the CC3000 will remember the details in its non-volatile memory.
  */
  Serial.println(F("\nSetting static IP address."));
  if (!setStaticIPAddress(cc3000.IP2U32(10, 1, 168, 192),   // IP address, not that this and other values are
                                                            // sent in reverse order.  So an IP of 192.168.1.19 is
                                                            // actually sent as IP2U32(19, 1, 168, 192)
                          cc3000.IP2U32(0, 255, 255, 255),  // Subnet mask, for example 255.255.255.0.
                          cc3000.IP2U32(1, 1, 168, 192),    // Default gateway, usually router IP like 192.168.1.1.
                          cc3000.IP2U32(8, 8, 8, 8)))       // DNS server, can use Google's DNS at 8.8.8.8.
  {
    Serial.println(F("Failed to set static IP!"));
    while(1);
  }
  
  /* Set IP and network through DHCP
     Note this only needs to be called once and the CC3000 will remember the details in its non-volatile memory.
  */
  
//  Serial.println(F("\nSetting network details through DHCP."));
//  if (!setDHCP()) {
//    Serial.println(F("Failed to set DHCP!"));
//    while(1); 
//  }
  

  /* Attempt to connect to an access point */
  char *ssid = WLAN_SSID;             /* Max 32 chars */
  Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);
  
  /* NOTE: Secure connections are not available in 'Tiny' mode! */
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  

  /* Display the IP address DNS, Gateway, etc. */  
  while (! displayConnectionDetails()) {
    delay(1000);
  }
  
#ifndef CC3000_TINY_DRIVER
  /* Try looking up www.adafruit.com */
  uint32_t ip = 0;
  Serial.print(F("www.adafruit.com -> "));
  while  (ip  ==  0)  {
    if  (!  cc3000.getHostByName("www.adafruit.com", &ip))  {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }  
  cc3000.printIPdotsRev(ip);
  
  /* Do a quick ping test on adafruit.com */  
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("...");  
  uint8_t replies = cc3000.ping(ip, 5);
  Serial.print(replies); Serial.println(F(" replies"));
  if (replies)
    Serial.println(F("Ping successful!"));
#endif

  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time you try to connect ... */
  Serial.println(F("\n\nClosing the connection"));
  cc3000.disconnect();
}

void loop(void)
{
  delay(1000);
}

/**************************************************************************/
/*!
    @brief  Displays the driver mode (tiny of normal), and the buffer
            size if tiny mode is not being used

    @note   The buffer size and driver mode are defined in cc3000_common.h
*/
/**************************************************************************/
void displayDriverMode(void)
{
  #ifdef CC3000_TINY_DRIVER
    Serial.println(F("CC3000 is configure in 'Tiny' mode"));
  #else
    Serial.print(F("RX Buffer : "));
    Serial.print(CC3000_RX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
    Serial.print(F("TX Buffer : "));
    Serial.print(CC3000_TX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
  #endif
}

/**************************************************************************/
/*!
    @brief  Tries to read the CC3000's internal firmware patch ID
*/
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;
  
#ifndef CC3000_TINY_DRIVER  
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); Serial.print(F(".")); Serial.println(minor);
    version = major; version <<= 8; version |= minor;
  }
#endif
  return version;
}

/**************************************************************************/
/*!
    @brief  Tries to read the 6-byte MAC address of the CC3000 module
*/
/**************************************************************************/
void displayMACAddress(void)
{
  uint8_t macAddress[6];
  
  if(!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}


/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

/**************************************************************************/
/*!
    @brief  Begins an SSID scan and prints out all the visible networks
*/
/**************************************************************************/

void listSSIDResults(void)
{
  uint8_t valid, rssi, sec, index;
  char ssidname[33]; 

  index = cc3000.startSSIDscan();

  Serial.print(F("Networks found: ")); Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
    
    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}

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

Re: CC3000 - No way to set the right DNS

Post by tdicola »

Thanks for posting the code--it looks good and I don't see any obvious issues. Do you mind grabbing the output of running the sketch? Just want to check the details returned like firmware version, IP, etc.

User avatar
fab64
 
Posts: 24
Joined: Sat Jun 14, 2014 12:11 pm

Re: CC3000 - No way to set the right DNS

Post by fab64 »

This is the console dump trying to connect to the Apple airport

Code: Select all

Hello, CC3000!

RX Buffer : 131 bytes
TX RAM: 1231

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x94 0x3C
Hello, CC3000!

RX Buffer : 131 bytes
TX Buffer : 131 bytes
Free RAM: 1231

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x94 0x3C
Networks found: 3
================================================
SSID Name    : homewirelessnetwork
RSSI         : 83
Security Mode: 3

SSID Name    : homewirelessnetwork2
RSSI         : 83
Security Mode: 3

SSID Name    : TNCAPAD75F9
RSSI         : 33
Security Mode: 3

================================================

Deleting old connection profiles

Setting static IP address.

Attempting to connect to homewirelessnetwork
Connected!
Request DHCP

IP Addr: 192.168.1.8
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 76.83.0.0
www.adafruit.com -> 
This is the dump connecting to DSLink router

Code: Select all

Hello, CC3000!

RX Buffer : 131 bytes
TX Buffer : 131 bytes
Free RAM: 1231

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x94 0x3C
Networks found: 4
================================================
SSID Name    : homewirelessnetwork
RSSI         : 83
Security Mode: 3

SSID Name    : homewirelessnetwork2
RSSI         : 83
Security Mode: 3

SSID Name    : dlink_pol
RSSI         : 43
Security Mode: 3

SSID Name    : TNCAPAD75F9
RSSI         : 33
Security Mode: 3

================================================

Deleting old connection profiles

Setting static IP address.

Attempting to connect to homewirelessnetwork2
Connected!
Request DHCP

IP Addr: 192.168.1.8
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 76.83.0.0
www.adafruit.com -> 
Please, note that I have to power the UNO with an external source otherwise it hangs here:

Attempting to connect to homewirelessnetwork

Thank you for your help.

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

Re: CC3000 - No way to set the right DNS

Post by tdicola »

Wow, odd that it's not even picking up the IP address that you set. Just to rule out any funky interaction between the set static ip function in the sketch, and a similar function that was added to the CC3k library recently, can you download the latest CC3k library from the github repo https://github.com/adafruit/Adafruit_CC3000_Library and open the buildtest sketch there. Inside you'll see a commented out call to set a static IP address:

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);
  }
  */
This is very similar to the code you have, but the one big difference is it fixes the order of the IP address components so you don't need to reverse them. If you use the buildtest example from the latest library and uncomment that section, fill in your static IP, etc. and run it do you still see a dynamic address being assigned?

User avatar
fab64
 
Posts: 24
Joined: Sat Jun 14, 2014 12:11 pm

Re: CC3000 - No way to set the right DNS

Post by fab64 »

Hi tdicola,

I followed your directions I had not success setting static IP and DNS.

The console dump with the function uncommented:

Code: Select all

Hello, CC3000!

RX Buffer : 131 bytes
TX Buffer : 131 bytes
Free RAM: 1221

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x94 0x3C
Networks found: 6
================================================
SSID Name    : homewirelessnetwork2
RSSI         : 83
Security Mode: 3

SSID Name    : TNCAP88215F
RSSI         : 33
Security Mode: 3

SSID Name    : dlink_pol
RSSI         : 51
Security Mode: 3

SSID Name    : homewirelessnetwork
RSSI         : 83
Security Mode: 3

SSID Name    : D-Link_Cru
RSSI         : 32
Security Mode: 3

SSID Name    : Studio Medico
RSSI         : 32
Security Mode: 3

================================================

Deleting old connection profiles

Attempting to connect to homewirelessnetwork2
Connected!
Request DHCP

IP Addr: 192.168.1.11
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 76.83.0.0
www.adafruit.com -> 
The dump when the function is commented out.

Code: Select all


Hello, CC3000!

RX Buffer : 131 bytes
TX Buffer : 131 bytes
Free RAM: 1248

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x94 0x3C
Networks found: 5
================================================
SSID Name    : homewirelessnetwork2
RSSI         : 83
Security Mode: 3

SSID Name    : dlink_pol
RSSI         : 53
Security Mode: 3

SSID Name    : homewirelessnetwork
RSSI         : 83
Security Mode: 3

SSID Name    : HP-Print-F3-Photosmart 7520
RSSI         : 35
Security Mode: 3

SSID Name    : TNCAP88215F
RSSI         : 37
Security Mode: 3

================================================

Deleting old connection profiles

Attempting to connect to homewirelessnetwork2
Connected!
Request DHCP

IP Addr: 192.168.1.11
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 76.83.0.0
www.adafruit.com -> 
Now I think that my board is faulty.

Thank you.

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

Re: CC3000 - No way to set the right DNS

Post by tdicola »

Thanks for trying the sketch, I agree lets replace the board since it appears to not be saving the static IP state in its non-volatile storage. Send an email to [email protected] with a link to this thread and they should get you all set with a replacement.

User avatar
fab64
 
Posts: 24
Joined: Sat Jun 14, 2014 12:11 pm

Re: CC3000 - No way to set the right DNS

Post by fab64 »

Thank your for your support, I'll do that.

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

Return to “Other Arduino products from Adafruit”