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/CC3200-LAUNCHXL: Problems with HTTP Post with the http client example in cc3200 sdk v1.3.0

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

Tool/software: Code Composer Studio

Hello,

I am using cc3200 sdk 1.3.0 and ccs v7 with cc3200launchXL for prototyping. The example works out of the box, but now I am trying to create dynamic json data with the help of this library. I have unit tested json strings generated from this library and also did http post using curl and it works fine. The problem is when I use strings generated from its api (which are json validated), the http post does not work and on the terminal I see only HTTP Post begin and HTTP Post end. on the Http server no data is received, and I get absolutely no error logs on the terminal. Its making debugging the issue difficult. If anyone already knows the code flow, any pointers to the bug would be appreciated. Here is the code I use:

int main(){

...

size_t buff_size = build_packet((float) i);

lRetVal = HTTPPostMethod(&httpClient, g_cpOutputBuffer, buff_size);

...

}



static size_t build_packet(float value)
{

JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);
size_t bytes;
char *serialized_string = NULL;
json_object_set_string(root_object, "name", "abc");
json_object_set_number(root_object, "voltage", value);

bytes = json_serialization_size_pretty(root_value);
g_cpOutputBuffer = (char*) malloc(bytes); //g_cpOutputBuffer is a global static char pointer

serialized_string = json_serialize_to_string_pretty(root_value);
strcpy(g_cpOutputBuffer, serialized_string);

json_free_serialized_string(serialized_string);
json_value_free(root_value);
return bytes;
}

static int HTTPPostMethod(HTTPCli_Handle httpClient, char *data, size_t length){

...

sprintf((char *) tmpBuf, "%d", length);

... //rest of the code has no modifications

 lRetVal = HTTPCli_sendRequestBody(httpClient, data, length);

...

}

Here are the logs I get:

		 *************************************************
		      CC3200 HTTP Client Application       
		 *************************************************



Host Driver Version: 1.0.1.11
Build Version 2.9.0.0.31.1.4.0.1.1.0.3.37
Device is configured in default state 
Device started as STATION 
[WLAN EVENT] STA Connected to the AP: ------- , BSSID: --:--:--:--:--:--
[NETAPP EVENT] IP Acquired: IP=------, Gateway=--------
Connected to the AP: ---------
Connection to server created successfully
HTTP Post Begin:
HTTP Post End:

HTTP Get Begin:
HTTP Status 200
Content-Type : application/json
Successfully parsed 7 JSON tokens
HTTP Get End:

  • Hi Anjali,

    Without further details, it is hard to know what could be happening with your project that could be causing an issue.

    One thing you can check is whether you have included all of the headers you need with your post request. With curl, set it to verbose mode (-v) so that you can see which HTTP headers it sends to the server. You should see something like:
    "POST /myservice HTTP/1.1
    Host: <your host>
    User-Agent: curl/7.54.0"
    etc.
    If you see some flag that you think you need, you'll have to use the HTTPCli_sendField() API to send it to the server before you use HTTPCli_sendRequestBody(). Make sure you only set lastFlag = 1 on your final HTTP header field.

    Another thing that could be it is that you are getting some HTTP response back that is not HTTP 200 or HTTP 404. In the demo, the readResponse() function only handles HTTP responses with status 200 and status 404. Perhaps you are getting some other status from your server, in which case readResponse() invokes flushHTTPResponse() and throws away the data. Check your curl prints and see what status you get back from the server. You can also put a breakpoint in readResponse() to see what you get back. If you get back some status that is missing from the handler, than you need to add in a handler for that response code in readReponse().

    If those two steps don't solve the problem, then you'll have to step through readResponse() and see what you get back from the server and what readResponse() is doing with it. You don't seem to be getting any obvious error, as the demo has several print statements that would have printed out if an error occurs. Instead, you seem to be getting through to the end of HTTPPostMethod().

    Regards,
    Michael
  • Now that I can debug the project properly, I set a breakpoint in readResponse.

    Another thing that could be it is that you are getting some HTTP response back that is not HTTP 200 or HTTP 404. In the demo, the readResponse() function only handles HTTP responses with status 200 and status 404. Perhaps you are getting some other status from your server, in which case readResponse() invokes flushHTTPResponse() and throws away the data. Check your curl prints and see what status you get back from the server. You can also put a breakpoint in readResponse() to see what you get back. If you get back some status that is missing from the handler, than you need to add in a handler for that response code in readReponse().

    You are correct I am receiving status 400 in readResponse. How do I remove this error?

  • I solved this problem by removing the trailing NULL from my custom data, due to which I was getting response 400. I dont know how cURL handles trailing NULL from string, but apparently the http API's with this SDK do not omit nulls before sending data on wire.