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 Internal server

Part Number: CC3220SF-LAUNCHXL

Tool/software: Code Composer Studio

Dear Sir,

I have an question about the Internal HTTP server of the CC3220 device. i am following the out box example for the my reference. as i see in example there have a post and get method to the device here also i need a post and get method for the getting information and configuring the device.

Here i am able to run the get method as expected with response but while POST method i am able to get the payload but i could not able to send response back to client with application/json.

Here i am using preparing metadata as per the outbox example and too send them am using @sl_NetAppSend API as per explain in the example.

I need a response when i do post method but i could not regenerate .

Please do needful .

Here my example to send a response


uint16_t prepareGetMetadata(int32_t parsingStatus, uint32_t contentLen, HttpContentTypeList contentTypeId)
{
char *contentType;
uint8_t *pMetadata;
uint16_t metadataLen;

contentType = g_ContentTypes[contentTypeId].contentTypeText;

memset((uint8_t*)&gMetadataBuffer, 0x00, sizeof(gMetadataBuffer));

pMetadata = gMetadataBuffer;

/* http status */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pMetadata++;
*(uint16_t*) pMetadata = (uint16_t) 2;
pMetadata += 2;

if (parsingStatus < 0)
{
*(uint16_t*) pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
}
else
{
*(uint16_t*) pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_200_OK;
}

pMetadata += 2;

/* Content type */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_TYPE;
pMetadata++;
(*(uint16_t*) pMetadata) = (uint16_t) strlen((const char*) contentType);
pMetadata += 2;
sl_Memcpy(pMetadata, contentType, strlen((const char* )contentType));
pMetadata += strlen((const char*) contentType);

/* Content len */
*pMetadata = SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_LEN;
pMetadata++;
*(uint16_t*) pMetadata = (uint16_t) 4;
pMetadata += 2;
*(uint32_t*) pMetadata = (uint32_t) contentLen;

metadataLen = 5 + 7 + strlen((const char*) contentType) + 3;

return (metadataLen);
}

uint16_t preparePostMetadata(int32_t parsingStatus)
{
uint8_t *pMetadata;

uint16_t metadataLen;

memset((uint8_t*)&gMetadataBuffer, 0x00, sizeof(gMetadataBuffer));

pMetadata = gMetadataBuffer;

/* http status */
*pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pMetadata++;
*(uint16_t *)pMetadata = (uint16_t) 2;
pMetadata += 2;

if(parsingStatus < 0)
{
*(uint16_t *)pMetadata = (uint16_t) SL_NETAPP_HTTP_RESPONSE_404_NOT_FOUND;
}
else
{
/* no need for content so browser stays on the same page */
*(uint16_t *)pMetadata = SL_NETAPP_HTTP_RESPONSE_200_OK; //(uint16_t) SL_NETAPP_HTTP_RESPONSE_204_OK_NO_CONTENT;
}

pMetadata += 2;

metadataLen = 5;

return(metadataLen);
}


//if payload created
if(status > 0)
{
//get the payload length
len = strlen((const char*)gPayloadBuffer);

if (netAppRequest->Type == SL_NETAPP_REQUEST_HTTP_GET)
{
metadataLen = prepareGetMetadata(0, len, HttpContentTypeList_ApplicationJson);
}
else
{
metadataLen = preparePostMetadata(status);
}

sl_NetAppSend(netAppRequest->Handle, metadataLen, gMetadataBuffer, (SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION | SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA));

/* mark as last segment */
sl_NetAppSend(netAppRequest->Handle, len, gPayloadBuffer, 0);

WMLogInfo(DEBUG_LOG, "Payload buffer sent with %d", len);
}

  • Have you used the RESPONSE_PENDING in the SimpleLinkNetAppRequestEventHandler?

    pNetAppResponse->Status = SL_NETAPP_RESPONSE_PENDING;

    it is mandatory if you are going to send the response in a different thread context.

    Did you change anything in the prepareGetMetadata or preparePostMetadata functions?

    Please use the reference example to compare  the flags and the buffer sent in the sl_NetAppSend.

    Please refer to chapter 9 of the programmers guide (https://www.ti.com/lit/ug/swru455l/swru455l.pdf) for more details on the HTTP Server.

    Br,

    Kobi

  • Dear Kobi,

    I haven't change anything in @SimpleLinkNetAppRequestEventHandler handler.

    No i did not changed any thing in prepare metadata function.

    Please have a look at the handler function 

    void SimpleLinkNetAppRequestEventHandler(SlNetAppRequest_t *pNetAppRequest, SlNetAppResponse_t *pNetAppResponse)
    {
    SlNetAppRequest_t *netAppRequest;
    int32_t msgqRetVal;

    if ((pNetAppRequest->Type == SL_NETAPP_REQUEST_HTTP_GET) || (pNetAppRequest->Type == SL_NETAPP_REQUEST_HTTP_DELETE) || (pNetAppRequest->Type == SL_NETAPP_REQUEST_HTTP_POST)
    || (pNetAppRequest->Type == SL_NETAPP_REQUEST_HTTP_PUT))
    {
    /* Prepare pending response */
    pNetAppResponse->Status = SL_NETAPP_RESPONSE_PENDING;
    pNetAppResponse->ResponseData.pMetadata = NULL;
    pNetAppResponse->ResponseData.MetadataLen = 0;
    pNetAppResponse->ResponseData.pPayload = NULL;
    pNetAppResponse->ResponseData.PayloadLen = 0;
    pNetAppResponse->ResponseData.Flags = 0;
    }
    else
    {
    NetAppRequestErrorResponse(pNetAppResponse);

    return;
    }

    netAppRequest = (SlNetAppRequest_t*) malloc(sizeof(SlNetAppRequest_t));
    if (NULL == netAppRequest)
    {
    NetAppRequestErrorResponse(pNetAppResponse);

    return;
    }

    memset(netAppRequest, 0, sizeof(SlNetAppRequest_t));
    netAppRequest->AppId = pNetAppRequest->AppId;
    netAppRequest->Type = pNetAppRequest->Type;
    netAppRequest->Handle = pNetAppRequest->Handle;
    netAppRequest->requestData.Flags = pNetAppRequest->requestData.Flags;

    /* Copy Metadata */
    if (pNetAppRequest->requestData.MetadataLen > 0)
    {
    netAppRequest->requestData.pMetadata = (uint8_t*) malloc(pNetAppRequest->requestData.MetadataLen);
    if (NULL == netAppRequest->requestData.pMetadata)
    {
    NetAppRequestErrorResponse(pNetAppResponse);
    free(netAppRequest);
    return;
    }
    sl_Memcpy(netAppRequest->requestData.pMetadata, pNetAppRequest->requestData.pMetadata, pNetAppRequest->requestData.MetadataLen);
    netAppRequest->requestData.MetadataLen = pNetAppRequest->requestData.MetadataLen;
    }
    else
    {
    netAppRequest->requestData.MetadataLen = 0;
    }

    /* Copy the payload */
    if (pNetAppRequest->requestData.PayloadLen > 0)
    {
    netAppRequest->requestData.pPayload = (uint8_t*) malloc(pNetAppRequest->requestData.PayloadLen);
    if (NULL == netAppRequest->requestData.pPayload)
    {
    NetAppRequestErrorResponse(pNetAppResponse);

    if (netAppRequest->requestData.pMetadata != NULL)
    {
    free(netAppRequest->requestData.pMetadata);
    }
    free(netAppRequest);
    return;
    }
    sl_Memcpy(netAppRequest->requestData.pPayload, pNetAppRequest->requestData.pPayload, pNetAppRequest->requestData.PayloadLen);
    netAppRequest->requestData.PayloadLen = pNetAppRequest->requestData.PayloadLen;
    }
    else
    {
    netAppRequest->requestData.PayloadLen = 0;
    }

    msgqRetVal = mq_send(linkLocalMQueue, (char*) &netAppRequest, 1, 0);

    if (msgqRetVal < 0)
    {
    ERROR_ON_FUNCTION(-1, "mq_send() failed");
    while (1)
    {
    ;
    }
    }
    }

  • It is hard for me to understand what you are doing and what you have changed in the oob example.

    The sequences of the OTA contains GET request (for reading device version for example). 

    My best advice is that you try to work with the original reference code and to understand it (e.g. put breakpoint or log messages in the callback) and then make small changes.

    br,

    Kobi

  • Dear,

    First of i am not using oob code but i used as a reference. here i have a some GE and POST request for the getting something and configuration. as i see, i am able get the response body when i do GET method , means that i got the application/json response but if i do POST method, i am able to received the POST method Request to handler and able extract the Payload but when i sent the application/json as a response back to client there only i am getting 200Ok instead off the application/json body response.

    There is nothing like rocket science kobi, just i have to get the POST generate the POST method response along with 200OK response if request payload is correct otherwise i have to send a error message like 404 not found as a application/json type response 

  • For the POST request, we are not supporting payload in  the response body (see chapter 9.7.3. in https://www.ti.com/lit/ug/swru455l/swru455l.pdf).

    You can use an HTTP Header as part of the metadata.

    Br,

    Kobi

     

  • Dear

    Thank you...

    You can close this thread.