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,