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.

LAUNCHXL-CC3235SF: Unable to use HTTP Client

Part Number: LAUNCHXL-CC3235SF
Other Parts Discussed in Thread: CC3235SF, CC3200

Hi Simplelink experts,

Can we use httpcli.c and httpcli.h which was given for CC3200 to CC3235SF. Because we have been migrating our code from CC3200 to CC3235SF. Our each and every functionality worked recently I faced issues in HTTP Server but that also I have been able to solve now when I use this function it is giving as -102

long device_provision_http_API_request()
{
unsigned long HostIP;
HTTPCli_Struct cli;
int32_t lRet;
memcpy((uint8_t *)&stFirmware.url_path,(uint8_t *)&stMqttConfig.Provision_url,strlen(stMqttConfig.Provision_url));
parse_hostname();
//DBG_MSG("gethostbyname before\r\n");
lRetVal = sl_NetAppDnsGetHostByName((signed char *)stFirmware.host_name,strlen((const char *)stFirmware.host_name), &HostIP, SL_AF_INET);
//lRetVal = sl_NetAppDnsGetHostByName((signed char *)"www.google.com",strlen((const char *)"www.google.com"), &HostIP, SL_AF_INET);
if(lRetVal < 0)
{
DBG_MSG("Failed to resolve host address\r\n");


return -1;
}
size_t ulLength = sprintf(debug_data, "%d\r\n",
HostIP);
uart1_send_fifo((uint8_t *)debug_data, ulLength);
DBG_MSG("gethostbyname ip resolved\r\n");
SlSockAddrIn_t addr;
addr.sin_family = SL_AF_INET;
addr.sin_port = sl_Htons(HOST_PORT);
addr.sin_addr.s_addr = sl_Htons(HostIP);

HTTPCli_construct(&cli);

lRetVal = HTTPCli_connect(&cli, (SlSockAddr_t *)&addr,HTTPCli_TYPE_TLS, NULL);
if (lRetVal < 0)
{


HTTPCli_disconnect(&cli);
HTTPCli_destruct(&cli);


return -1;
}

lRet = HTTPPostMethod(&cli);
HTTPCli_disconnect(&cli);
HTTPCli_destruct(&cli);
if(lRet != 0)
{
//HTTPCli_disconnect(&cli);
//HTTPCli_destruct(&cli);
if(lRet == -2)
{
DBG_MSG("Failed to post\r\n");
}
return -1;
}
return 1;
}

Can anyone point out that can we use the older API for HTTP Client? Please it is very urgent.

Thanks and Regards

Manish

  • Hi,

    Any update it has been two days since I raised my query. Please reply as soon as possible I need to have some clarifications.

    Thanks,

    Manish

  • Hi Manish,

    You should to use debugger and see what error code is returned from connect() call inside httpcli.c.

    Jan

  • HI ,

    I'm getting an error as -102 but the same code works in CC3200.

  • Hi,

    No. You need to check return code directly inside httpcli.c.

    Jan

  • Hello Jan 

    inside httpcli.c inside Sl_Connect it retruns the follows: 
    HTTPCli_EPROXYTUNNELFAIL   (-111)

    Can you please point it out how we can solve this?

  • Hi,

    At your case is meaning of error code -111 of "Connection refused ". Hard to say why is this error returned from sl_ API - that means what else you have wrong inside your code.

    Maybe you should consider to use http library from CC32xx SDK (\source\ti\net\http\) - see httpget example inside CC32xx SDK.

    Jan

  • Thanks Jan, will dig further to solve this issue, and anyway I'll move ahead as per your suggestion.

  • Hi ,

    Can you give some idea how can I reuse the GEN1 HTTP Client to GEN2 devices?

  • Hi,

    I am sorry, I am not able provide any resolution. Technically it should be relatively easy, unfortunately I am not able say why this is not working at your case. Please wait for answer from TI.

    Jan

  • Hi TI Experts,

    I ported HTTP Client code from our working application for CC3200 to CC3235SF. Code follows

    static int HTTPPostMethod(HTTPCli_Handle httpClient)
    {
    bool moreFlags = 1;
    bool lastFlag = 1;
    char tmpBuf[4];
    char mac[13]={0},Udid[13]={0};
    long lRetVal = 0,body_len=0;
    HTTPCli_Field fields[5] = {
    {HTTPCli_FIELD_NAME_HOST, HOST_NAME},
    {HTTPCli_FIELD_NAME_ACCEPT, "*/*"},
    {HTTPCli_FIELD_NAME_CONTENT_TYPE, "application/json"},
    {"x-api-key", TOKEN},
    {NULL, NULL}
    };

    /* Set request header fields to be send for HTTP request. */
    HTTPCli_setRequestFields(httpClient, fields);


    moreFlags = 1;
    lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_POST,HOSTNAME, moreFlags);
    if(lRetVal < 0)
    {
    UART_PRINT("Failed to send HTTP POST request header.\n\r");
    return lRetVal;
    }
    memset(stGateway.Json_Buffer,NULL,sizeof(stGateway.Json_Buffer));

    body_len = // Copy Buffer

    sprintf((char *)tmpBuf, "%d", body_len);
    Please refer HTTP Library API documentaion @ref HTTPCli_sendField for more information.
    */
    lastFlag = 1;
    lRetVal = HTTPCli_sendField(httpClient, HTTPCli_FIELD_NAME_CONTENT_LENGTH, (const char *)tmpBuf, lastFlag);
    if(lRetVal < 0)
    {
    UART_PRINT("Failed to send HTTP POST request header.\n\r");
    return lRetVal;
    }
    lRetVal = HTTPCli_sendRequestBody(httpClient,stGateway.Json_Buffer, body_len);
    if(lRetVal < 0)
    {
    UART_PRINT("Failed to send HTTP POST request body.\n\r");
    return lRetVal;
    }


    lRetVal = readResponse(httpClient);

    return lRetVal;
    }

    Same code is able to post the request for CC3200 but not be able to do in CC3235. It returns -111.

    Can anyone please point it out how we can achieve these functionalities for CC3235SF?

    Basically my ultimate aim is achieve the following setup for CC323SF

    HTTPCli_Field fields[5] = {
    {HTTPCli_FIELD_NAME_HOST, HOST_NAME},
    {HTTPCli_FIELD_NAME_ACCEPT, "*/*"},
    {HTTPCli_FIELD_NAME_CONTENT_TYPE, "application/json"},
    {"x-api-key", TOKEN},
    {NULL, NULL}
    };

    /* Set request header fields to be send for HTTP request. */
    HTTPCli_setRequestFields(httpClient, fields);


    moreFlags = 1;
    lRetVal = HTTPCli_sendRequest(httpClient, HTTPCli_METHOD_POST,HOSTNAME, moreFlags);

  • Hi Manish,

    Are you setting a proxy?

    If you can get a sniffer capture, that may help determine why the connection is being refused.

    Best regards,

    Sarah

  • Hi Manish,

    As Jan mentioned, I would double-check and ensure that the error you're getting is generated from the HTTP library and not from the underlying sl_connect() call.

    This is since error -111 from sl_connect is SL_ERROR_BSD_ECONNREFUSED, which is a fairly common error, more common than that of a proxy error.

    If you're getting -111 from sl_connect, then I suggest you check the data you pass into sl_connect, so your address and port + TLS certs. While your HTTP application code might be the same, perhaps the ported HTTP library doesn't quite call the APIs correctly anymore. You can run your application in debug mode to double-check that your sl_connect call looks correct.

    In the past, I had successfully gotten the Gen1 HTTP library working on Gen2+, in this project:https://www.ti.com/tool/TIDEP-0083

    Unfortunately, it is quite outdated as I worked on it years ago before the new and reworked Gen2/3 HTTP library was released. Then again, the porting layer I used worked back then, and it might serve as a guide for how to interface the Gen1 HTTP library to the newer SDK.

    The project code is in this SDK, in a folder called "voice_ui_demo"

    https://www.ti.com/tool/SPRC133

    Perhaps looking at my code after you perform the sl_connect check might be useful.

    Regards,

    Michael

  • f you're getting -111 from sl_connect, then I suggest you check the data you pass into sl_connect, so your address and port + TLS certs

    Hi

    Is HTTP client over TLS/SSL is supported in CC3235SF?

    Regards,

    Manish

  • Hi Manish,

    This is supported in the Network Services HTTP Client library provided in the CC32xx SDK. Since you ported your application and Gen 1 library, you may have missed something. You should check how you are handling your certificates.

    Best regards,

    Sarah

  • Hi ,

    I just wanted to know how we can perform HTTP Post because I'm able to do the get request. I need to set some header with name as "api-key" and value as some string " abcdefghijklmnopqrstuvwxyz"

    so for that, I'm using 

    HTTPClient_setHeaderByName(httpClientHandle, HTTPClient_REQUEST_HEADER_MASK, "api-key", "abcdefghijklmnopqrstuvwxyz", strlen("abcdefghijklmnopqrstuvwxyz"), HTTPClient_HFIELD_PERSISTENT);

    After that, I'm passing a body with a body length in send response as a post request. Here is an example shown below:

    body_len = sprintf(Json_Buffer, PROVISION_DATA,"abcdrfgh","xxxxxxxxxxxx","---------------","************","+++++++++++"); 

    (SYMBOLS IN DOUBLE-QUOTES ARE STRING. I just do not want to expose that)
    ret =
    HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_POST,HOSTNAME,
    (char const *)Json_Buffer,body_len,
    0);

    But every time I call the API it gives me either 400 or 403. If you can or ant TI Experts can point out how to set the header for the API key which I have shown above that would be extremely helpful. Actually, I have tried everything and now it is too late, I need to complete this work as soon as possible.

    Kindly please suggest me some answers, I need some clarifications about only POST requests using setting header and sendRequest.

  • I have solved my issue. Thanks, everyone for the support.

  • What did you do to solve your issue?
    I too am unable to connect using HTTPClient_Connect().

    When my function parses URI, I can see the string includes "Creation of http client handle failed."
    I am trying to connect create HTTP client (which I believe is failing despite no errors being returned), and eventually sending a POST request to an AWS API Gateway URL.

    Thank you.

  • Hi

    Make sure your headers are properly set up otherwise it is very difficult to fix the issue.