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.

CCS/CC3220SF-LAUNCHXL: HTTP CONNECTION FAILED WITH -2006

Part Number: CC3220SF-LAUNCHXL

Tool/software: Code Composer Studio

Dear sir,

i'm working on the HTTP client code and i have to connect with the third party cloud device to get password token using HTTP. here i'm using TI CC3220 SDK V3_40_00_5 but i getting error with the -2006 

please do needfull.

  • Hi,

    What HTTP site are you trying to connect to? If you try google.com, or another common site with a simple GET request, do you get the correct output from the HTTP library?

    Regards,

    Michael

  • Dear Sir,

    I tried third party URL for the POST method but i could not connected with that but when i tried with the localhost i been connected but while POST URL there been added some junk character 

    please check my code

    int get_token_from_http_server(MQTTPassword_ts *MQTTPassword)
    {
    int RetVal = -1;

    bool moreDataFlag = false;

    char httpBody[200] = { 0 };

    //http handler
    HTTPClient_Handle httpClientHandle;

    int16_t statusCode;

    httpClientHandle = HTTPClient_create(&statusCode, NULL);

    if (httpClientHandle < 0)
    {
    ASSERT_ON_ERROR(statusCode, "HTTPClient_create() failed");
    }

    uint32_t len = 0;


    char httpHeader[100] = { 0 };

    memset((char*) &httpHeader, 0x00, sizeof(httpHeader));

    strcpy(httpHeader, " application/json");

    len = strlen((const char*)httpHeader);

    RetVal = HTTPClient_setHeader(httpClientHandle,
    HTTPClient_HFIELD_REQ_CONTENT_TYPE, httpHeader, len,
    HTTPClient_HFIELD_PERSISTENT);

    memset((char*) &httpHeader, 0x00, sizeof(httpHeader));

    strcpy(httpHeader, "HTTPClient (ARM; TI-RTOS)");

    len = strlen((const char*) httpHeader);

    RetVal |= HTTPClient_setHeader(httpClientHandle,
    HTTPClient_HFIELD_REQ_USER_AGENT, httpHeader, len,
    HTTPClient_HFIELD_PERSISTENT);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_setHeader() failed");
    }

    char localHostName[40] = { 0 };

    strcpy(localHostName, HOSTNAME);


    WMLogInfo(INFO_LOG, "host name %s", localHostName);

    RetVal = HTTPClient_connect(httpClientHandle, localHostName, 0, 0);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_connect() failed");
    }
    else
    {
    WMLogInfo(INFO_LOG, "HTTP connected with %s", localHostName);
    }

    strcpy(httpBody, "{\n \"gatewayPassword\": \"w$YKuSRX\",\n \"gatewayUserName\": 205\n}\r\n");

    len = strlen((const char *)httpBody);

    WMLogInfo(INFO_LOG, "http body %s with len %d" , httpBody, len);

    RetVal = HTTPClient_sendRequest(httpClientHandle, HTTP_METHOD_POST, POST_REQUEST_URI, httpBody,
    len, 0);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_sendRequest() failed");
    }
    if (RetVal != HTTP_SC_OK)
    {
    ASSERT_ON_ERROR(statusCode, "HTTP_SC_OK failed");
    }

    //clear the buffer

    memset((char*)&httpData, 0x00, sizeof(httpData));

    len = 0;

    do
    {
    RetVal = HTTPClient_readResponseBody(httpClientHandle, httpData, sizeof(httpData),
    &moreDataFlag);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_readResponseBody() failed");
    }

    len += RetVal;

    }while (moreDataFlag);

    RetVal = HTTPClient_disconnect(httpClientHandle);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_disconnect() failed");
    }

    RetVal = HTTPClient_destroy(httpClientHandle);

    if (RetVal < 0)
    {
    ASSERT_ON_ERROR(RetVal, "HTTPClient_destroy() failed");
    }

    memset((char*)&finalString, 0x00, sizeof(finalString));

    strcpy(finalString, "{\"""");

    strcat(finalString, (char*)&httpData[2]);

    return gatewayLoginparser(MQTTPassword, (const char*)finalString);
    }

  • Hi,

    Looking at another thread you posted, it appears that the issue was due to an inadequate HTTP buffer size:

    https://e2e.ti.com/support/wireless-connectivity/wifi/f/968/t/935408

    Please let me know if that wasn't the resolution to your issue, or if you have further questions on the use of the HTTP library.

    Regards,

    Michael

  • Dear Sir,

    I changed the library now able to connect with any URL.

  • Dear Sir,

    I made some changed in HTTP library function, with latest SDK i was not able to connect but the SDKV2_40 i was able to connect so here was a problem with latest SDK.

    Here with latest SDK HTTP library i added +1 with Len as per the explanation of the @SlNetSock_secAttribSet in header file.

    if (domain != NULL)
    {
    ret = SlNetSock_secAttribSet(secAttribHdl, SLNETSOCK_SEC_ATTRIB_DOMAIN_NAME,(char *)domain, strlen(domain) + 1);
    if (ret < 0)
    {
    SHOW_ERROR(ret, "SlNetSock_secAttribSet() failed");
    goto error;
    }
    }

    After the above changed in the @startSecureMode function , device start connecting with URL but there is another bug was in @HTTPClient_setHeader function.here i had a two different URL for the connection so vice versa it was connecting means that if am processing the first URL flow it will connect properly and it will read the response but after the first flow second URL will connect but while setting header some Junk character was appending so this process was vice-versa, So i made some changed in the @HTTPClient_setHeader function. have a look once,

    /* Allocating request header node */
    node = (Req_HField *)malloc(sizeof(Req_HField));
    if (node != NULL)
    {
    node->CustomName = NULL;
    node->Value = (char *)malloc(len);
    if (node->Value == NULL)
    {
    free(node);
    return(HTTPClient_EREQUESTHEADERALLOCFAILED);
    }
    /* Fill the request name and value */
    node->Name = option;
    // memcpy((char*)node->Value, (const char*)value,len);
    sprintf(node->Value, "%s", (const char*)value);

    }

    Here library used memcpy for the copy the user Header but it was appending junk, so i changed to sprinf and it fine now.

    Thanks