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.

CC3200 HTTP client connect fail

Other Parts Discussed in Thread: CC3200

Hi all, 

I used the CC3200 example "http_client_demo"  to to do file downloading with FreeRTOS.

The chip cannot connect to the file  server,it returns -102 error,always. I'm sure the file server is OK.

I use the code like this below:

void HttpClientTask(void* param)
{
  long lRetVal;
  
  static HTTPCli_Struct httpClient;
  
  HTTPCli_construct(&httpClient);  
  
  UART_PRINT("\r\nserver:%s\r\n",ossServerName);
  UART_PRINT("ossServerPort:%d\r\n",ossServerPort);
  UART_PRINT("res:%s\r\n\r\n",urlResource);
  
  lRetVal = ConnectToHTTPServer(&httpClient,ossServerName,ossServerPort);
  if(lRetVal<0)
  {
    f_close(&saveFileMusicHd);
    DeleteMusicFile(saveFileMusicCatID,saveFileMusicFID);
    UART_PRINT("****Download File Fail!****\r\n");
  }
  else
  {
    lRetVal = HTTPGetMethod(&httpClient,ossServerName,urlResource);
    if(lRetVal<0)
    {
        f_close(&saveFileMusicHd);
        DeleteMusicFile(saveFileMusicCatID,saveFileMusicFID);
        UART_PRINT("****Download File Fail!****\r\n");
    }
  }
  
  HTTPCli_disconnect(&httpClient);
  
  //HTTPCli_destruct (&httpClient);  

}

-

the ConnectToHTTPServer is:

static int ConnectToHTTPServer(HTTPCli_Handle httpClient,const char* ossServer,uint16_t ossPort)
{
    long lRetVal = -1;
    //struct sockaddr_in addr;
    
    SlSockAddrIn_t addr;
    
    uint32_t ossIP;

#ifdef USE_PROXY
    struct sockaddr_in paddr;
    paddr.sin_family = AF_INET;
    paddr.sin_port = htons(PROXY_PORT);
    paddr.sin_addr.s_addr = sl_Htonl(PROXY_IP);
    HTTPCli_setProxy((struct sockaddr *)&paddr);
#endif
    
    /* Resolve HOST NAME/IP */
  
    
    lRetVal = sl_NetAppDnsGetHostByName((signed char *)ossServer,
                                          strlen((const char *)ossServer),
                                          &ossIP,SL_AF_INET);
    if(lRetVal < 0)
    {
        //ASSERT_ON_ERROR(GET_HOST_IP_FAILED);
      UART_PRINT("Get Host ip failed %d\r\n",lRetVal);
      return -1;
    }
    
    UART_PRINT("ip is :%x\r\n",ossIP);

    /* Set up the input parameters for HTTP Connection */
    addr.sin_family = AF_INET;
    addr.sin_port = htons(ossPort);
    addr.sin_addr.s_addr = sl_Htonl(ossIP);

    /* Testing HTTPCli open call: handle, address params only */
    //HTTPCli_construct(httpClient);
    
    lRetVal = HTTPCli_connect(httpClient, (SlSockAddr_t*)&addr, 0, NULL);
    if (lRetVal < 0)
    {
        UART_PRINT("Connection to server failed. error(%d)\r\n", lRetVal);
        return -2;
    }    
    else
    {
        UART_PRINT("Connection to server created successfully\r\n");
    }

    return 0;
}

---------------------------------------------------------

I keep calling the function in one of  OS task,i can always get the connect fail error code.

If it is necessary to call " HTTPCli_destruct (&httpClient); "  when I have called "HTTPCli_disconnect(&httpClient)",

cause In the API,i can see "HTTPCli_disconnect"  is "Disconnect from the HTTP server and destroy the HTTP client instance".

and "HTTPCli_destruct"  is  just "Destory the HTTP client instance."

And if it is OK that  I keep calling this function in the os task.

Regards,

  • Hi,

    Can you please let me know where you are printing this error code -102 from? Is it HTTPCli_connect?

    Regards,
    Raghavendra

  • Hi, Raghavendra

    it occurs here:

    lRetVal = HTTPCli_connect(httpClient, (SlSockAddr_t*)&addr, 0, NULL);
        if (lRetVal < 0)
        {
            //the -102 error code.returned here.
            UART_PRINT("Connection to server failed. error(%d)\r\n", lRetVal);
            return -2;
        }

    And I want to know, if it is necessary to call "HTTPCli_destruct" when "HTTPCli_disconnect" is already called .

    Regards,

  • Hi user4271140,

    Error code -102 means it is not able to connect to server. There may be following reason:

    1. No internet connection

    2. server ip or ports are incorrect.

    3. Server refusing the connection.

    user4271140 said:
    And I want to know, if it is necessary to call "HTTPCli_destruct" when "HTTPCli_disconnect" is already called .

    HTTPCli_disconnect() API close the connection with server and release memory that held by http client instance where as HTTPCli_destruct() API release resources without closing connection. If you connecting to server again and again the please use HTTPCli_disconnect() API in place of HTTPCli_destruct().

    Regards,

    Aashish

  • Hi Aashish,

    Thanks very much.

    And there is some other little question.
    Dose the http client api to do so some OSI memory allocation ?
    Do I need to set the osi task stack size much more bigger according to some policy?
    When I run my program,sometimes, it stucks in the http-client-connection stage forever, and then the system crashes.

    Regards,
  • Hi HeKaifeng,

    user4271140 said:
    Dose the http client api to do so some OSI memory allocation ?

    No. HTTP Client library uses static memory. There is no dynamic memory allocation in library.

    user4271140 said:
    Do I need to set the osi task stack size much more bigger according to some policy?

    Take stack size as per you task/thread design

    Regards,

    Aashish

  • Hi,

    I have the same error -102 when i run the http_client_demo example

    Would you mind sending me your http_client project.

    or comment in my post 

    Regards,

    Khoa