This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3000 gethostbyname error

Hi,

I updated the cc3000 to 1.13 version.

I tried this chip in both mode DHCP and in static IP.

in DHCP I have the follow problem:

sometime I can't read the IP set by DHCP server.

in Static IP I have problem with gethostbyname.
The method came back always -95 errno code. So I tried to call the method gethostbyname after Wifi connection with "localhost", in this case When I call gethostbyname with hostname I receive errno -161.


How can I resolve my problem?

  • Hi,

    Can you share your code snippet?

    Regards,
    Gigi Joseph.
  • I use Arduini IDE and Adafruit library

    this is the initialize code

    #define STATIC_IP
    void WifiStart() {
      Serial.println(F("\Inizializzazione CC3000..."));
      if (!cc3000.begin())
      {
        Serial.println(F("Impossibile avviare il WiFi, verificare il cablaggio"));
        while(1);
      }
      //lettura versione CC3000
      uint8_t major = 0, minor = 0;
      cc3000.getFirmwareVersion(&major, &minor);
      Serial.print(F("\n Versione CC3000: ")); Serial.print(major, DEC); Serial.print("."); Serial.print(minor, DEC);Serial.print("\n\n");
    
      displayMACAddress();
    
      /* Delete any old connection data on the module */
      //Serial.println(F("\nDeleting old connection profiles"));
      if (!cc3000.deleteProfiles()) {
        Serial.println(F("Failed!"));
        while(1);
      }
    
    #ifdef STATIC_IP
      uint32_t ipAddress = cc3000.IP2U32(***, ***, ***, ***);
      uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0);
      uint32_t defaultGateway = cc3000.IP2U32(***, ***, ***, ***);
      uint32_t dns = cc3000.IP2U32(***, ***, ***, ***);
      //Serial.println(F("IP statico"));
      if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) {
        Serial.println(F("Failed to set static IP!"));
        while(1);
      }
    #else
      //Serial.println(F("IP dinamico DHCP"));
      if (!cc3000.setDHCP()) {
        Serial.println(F("Failed to set DHCP!"));
        while(1);
      }
    #endif
    
      //Serial.print(F("\nAttesa connessione SSID ")); Serial.println(WLAN_SSID);
      if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
        Serial.println(F("Connessione fallita!"));
        while(1);
      }
      //Serial.println(F("Connesso!"));
    
      //Serial.println(F("Richiesta DHCP"));
    #ifndef STATIC_IP
      Serial.println(F("Attesa per DHCP DHCP"));
      unsigned long timeout = millis() + 60000;
      while (!cc3000.checkDHCP() && millis() < timeout)
        delay(100);
        
      if (millis() >= timeout){
        Serial.println(F(" DHCP request timed out"));
        cc3000.disconnect();
        while(1);
      }
    #endif
      //Mostra i dati di connessione
      while (! displayConnectionDetails()) {
        delay(100);
      }
    #ifdef STATIC_IP
      Serial.println("test DNS");
      uint32_t output;
      gethostbyname("localhost", 9, &output);
    #endif
    }

    and this is code where I have the problem

    void UpdateDnsService() {
      //se la connessione avviene con successo
      //invio la richiesta http
      Adafruit_CC3000_Client client;
      unsigned long startTime = millis();
      unsigned long ip = 0;
      int err = cc3000.getHostByName(serverNoIp, &ip);
      
      Serial.println(F("errore getHostByName: "));
      Serial.println(err,DEC);
      
      if(ip == 0 || err != 0) {
        //Serial.println(F("UpdateDnsService: problemi nel server DNS"));
        //Serial.print(F("Errore = "));
        //Serial.print(errno);
        //Serial.print(" (");
        //Serial.print(errno, HEX);
        //Serial.println(")");
        return;
      }
      //Serial.println(F("Connessione..."));
      //Serial.println(ip);
       do {
        client = cc3000.connectTCP(ip , 80);
       }while((!client.connected()) && ((millis() - startTime) < connectTimeout));
      if(client.connected()) {
        //Serial.println(F("Connesso"));
        client.fastrprint(F("GET "));
        client.fastrprint(F("/nic/update?hostname=webmeteostation.no-ip.org "));
        client.fastrprint(F("HTTP/1.0\r\n"));
        client.fastrprint(F("Host: dynupdate.no-ip.com\r\n"));
        client.fastrprint(F("Authorization: "));
        client.fastrprint(F("Basic ***********************************************\r\n"));
        client.fastrprint(F("User-Agent: "));
        client.fastrprint(F("arduino_wifi/1.0"));
        client.fastrprint(F("***************************\r\n"));
        client.fastrprint(F("\r\n"));
        client.println();
        //attendo la risposta
        startTime = millis();
        unsigned long lastRead = millis();
        while (client.connected() && (millis() - lastRead < responseTimeout)) {
          while (client.available()) {
            char c = client.read();
            Serial.print(c);
            lastRead = millis();
          }
        }
        //disconnetto
        Serial.println("\n");
        //Serial.println(F("Disconessione"));
        client.close();
      }
      else
      {
        //Problemi nella connessione
        Serial.println(F("connessione fallita!"));
      }
    }