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.

Processing response data after send HTTP POST request

Other Parts Discussed in Thread: CC3200, CC3200SDK, ENERGIA, UNIFLASH

Hi,

I have connected CC3200 to Google API and send HTTP POST and i have a few questions about response data

1/  when the request POST send successfully and Google is 100% confident in it's translation,

It will return the following object:

{
  "result":[
    {
      "alternative":[
        {
          "transcript":"this is a test",
          "confidence":0.97321892
        },
        {
          "transcript":"this is a test for"
        }
      ],
      "final":true
    }
  ],
  "result_index":0
}

So I have to use lRetVal = readResponse(httpClient); (at the end of function HTTPPostMethod)  to receive the return data

if i use readResponse, i have to change the ids field 

	const char *ids[5] = {
			HTTPCli_FIELD_NAME_CONTENT_LENGTH,
			HTTPCli_FIELD_NAME_CONNECTION,
			HTTPCli_FIELD_NAME_CONTENT_TYPE,
			"result",
			NULL
	};

Do you have any solution to get the value " transcript: this a test "  from return value

Would you mind helping me

2/ the result after i debugged the code. 

why after this line

if(!strncmp((const char *)g_buff, "application/json",
sizeof("application/json")))

the result is json = 0

In the second picture, the g_buff contains application/json; . Why json = 0

I tested with Postma and it is true that it is not json. Can only be read by XML type , HTML type , Text type . But i still wonder why json = 0

Thank you and Best regards,

Khoa

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    {
      "result":[
        {
          "alternative":[
            {
              "transcript":"this is a test",
              "confidence":0.97321892
            },
            {
              "transcript":"this is a test for"
            }
          ],
          "final":true
        }
      ],
      "result_index":0
    }

    So I have to use lRetVal = readResponse(httpClient); (at the end of function HTTPPostMethod)  to receive the return data

    if i use readResponse, i have to change the ids field 

    	const char *ids[5] = {
    			HTTPCli_FIELD_NAME_CONTENT_LENGTH,
    			HTTPCli_FIELD_NAME_CONNECTION,
    			HTTPCli_FIELD_NAME_CONTENT_TYPE,
    			"result",
    			NULL
    	};

    No. result is HTTP body not HTTP header so dont add "result" in ids. Read HTTP body part using HTTPCli_readResponseBody() API. Refer readResponse().

     

    Tuan Khoa Nguyen said:
    Do you have any solution to get the value " transcript: this a test "  from return value

    There is 2 way either use JSON parser or use standard string API e.g. strcmp(), strtok()  to extract required string.

    There is JSMN JSON parser already integrated with SDK. In latest SDK(1.2.0) we have written a wrapper layer on the top of the JSMN JSON parser for better user experience. Please look into that.

    below is pseudo code to use SDK JSMN JSON library to parse JSON data:

    jsonParser	jParser;
    jsonObj 	jRootObj;
    jsonObj 	jObjResult;
    jsonObj 	jResultArrayObj1;
    jsonObj 	jAlternativeArrayObj2;
    
    jsonArray	jResultArray;
    jsonArray	jAlternativeArray;
    
    char		tempStr[32];
    
    
    
    // Get root JSON node
    jRootObj = json_parser_init(&jParser, httpBody);
    
    // Get "result" array
    jResultArray = json_object_get_array(&jParser, jRootObj, "result");
    
    // Get object at index 0 in "result" array
    jResultArrayObj1 = json_array_get_object(&jParser, jResultArray, 0);
    
    // Get "alternative" array from index 0 of "result" array 
    jAlternativeArray = json_object_get_array(&jParser, jResultArrayObj1, "alternative");
    
    // Get object at index 1 in "alternative" array
    jAlternativeArrayObj2 = json_array_get_object(&jParser, jAlternativeArray, 1);
    
    // Get value of "transcript" from object at index 1 in "alternative" array
    json_object_get_string(&jParser, jAlternativeArrayObj1, "transcript", tempStr);
    

    Tuan Khoa Nguyen said:

    why after this line

    if(!strncmp((const char *)g_buff, "application/json",
    sizeof("application/json")))

    the result is json = 0

    In the second picture, the g_buff contains application/json; . Why json = 0

    Above code is application/server specific. It depend upon what type of content server support. In SDK example we are expecting server always will send JSON data, if it's it other than JSON we setting flag "json=0" to ignore the HTTP body. Please modify above code as per your need.

    Tuan Khoa Nguyen said:
    I tested with Postma and it is true that it is not json. Can only be read by XML type , HTML type , Text type . But i still wonder why json = 0

    As above we mentioned it's just a flag to ignore data other JSON in our case. It's depend upon your server. If your server send XML data then use XML parser. To determine what type of content is there, check HTTPCli_FIELD_NAME_CONTENT_TYPE header as shown in example code. 

    For example:

    case 2: /* HTTPCli_FIELD_NAME_CONTENT_TYPE */
    {
    	if(!strncmp((const char *)g_buff, "application/json", sizeof("application/json")))
    	{
    		// It's json data
    		json = 1;
    	}
    	else if(!strncmp((const char *)g_buff, "application/text", sizeof("application/json")))
    	{
    		// It's text data
    		text = 1;
    	}
    	else if(!strncmp((const char *)g_buff, "application/xml", sizeof("application/json")))
    	{
    		// It's xml data
    		xml = 1;
    	}
    	.
    	.
    	.
    }
    break;

    Regards,
    Aashish

  • Hi Aashish,

    Thank you for your help

    i'm still confused about reponse data . 

     


    Would you mind helping me , please

    1/ if i use JSMN JSON parser i will do like this

    jsonParser	jParser;
    jsonObj 	jRootObj;
    jsonObj 	jObjResult;
    jsonObj 	jResultArrayObj1;
    jsonObj 	jAlternativeArrayObj2;
    
    jsonArray	jResultArray;
    jsonArray	jAlternativeArray;
    
    char		tempStr[32];
    
    httpBody = (char *)g_buff ;     // (g_buff store the response data )
    bytesRead = HTTPCli_readRawResponseBody(httpClient, (char *)httpBody, len); 
    
    // Get root JSON node
    
     jRootObj = json_parser_init(&jParser, httpBody); 
    
    
    // Get "result" array 
    
    jResultArray = json_object_get_array(&jParser, jRootObj, "result"); 
    
    
    // Get object at index 0 in "result" array 
    
    jResultArrayObj1 = json_array_get_object(&jParser, jResultArray, 0);
    
    
     // Get "alternative" array from index 0 of "result" array 
    
    jAlternativeArray = json_object_get_array(&jParser, jResultArrayObj1, "alternative"); 
    
    
    // Get object at index 1 in "alternative" array
    
     jAlternativeArrayObj2 = json_array_get_object(&jParser, jAlternativeArray, 1); 
    
    
    // Get value of "transcript" from object at index 1 in "alternative" array 
    
    json_object_get_string(&jParser, jAlternativeArrayObj1, "transcript", tempStr);

    right ?

    2/ after i tested with postman, the content type is truly application/json 

    the truly reponse is like this 

    {"result":[]}
    {"result":[{"alternative":[{"transcript":"chào","confidence":0.70181781},{"transcript":"Cha"},{"transcript":"dạ"},{"transcript":"trẻ"}],"final":true}],"result_index":0}

    It has 2 result. It means 2 json data in reponse data

    So that why the postman cannot show it in json type

    I think that also is the reason for ccs  determines wrong content-type and can't find the reponse body. Or CC3200 can't read utf-8 type ?

    The g_buff  always contains " application/json "

    after that g_buff  = " chunked.ncoding..21:46:29.GMT8".   I don't know where g_buff have that data. And moreflag = NULL

    Even i use HTTPCli_readRawResponseBody ,I can't find where the reponse body was stored . 

    So that i can't separate 2 json reuslt

    3/ Are there any ways for me to send data package > 16kb 

    Split data and send each small data ?

    Thank you and best regards

    Khoa

  • Hi Khoa,

    For question 1: Yes, but please ensure that you read HTTP body completely before calling JSON paser 

    Tuan Khoa Nguyen said:

    the truly reponse is like this 

    {"result":[]}
    {"result":[{"alternative":[{"transcript":"chào","confidence":0.70181781},{"transcript":"Cha"},{"transcript":"dạ"},{"transcript":"trẻ"}],"final":true}],"result_index":0}

    It has 2 result. It means 2 json data in reponse data

    So that why the postman cannot show it in json type

    Can not comment on  this as we don't know how postman work. It will be better if you post this query in postman forum.

    Tuan Khoa Nguyen said:
    I think that also is the reason for ccs  determines wrong content-type and can't find the reponse body. Or CC3200 can't read utf-8 type ?

    No, CC3200 can read utf-8 as all data in binary format. So it doesn't matter what character encoding is. It all depend upon how your implementation interpret it.

    Tuan Khoa Nguyen said:
    3/ Are there any ways for me to send data package > 16kb 

     

    Yes, you can send >16 kb by repedaly calling HTTPCli_sendRequestBody(). Below is pseudo code send data 100KB data

    // Set content length HTTP header value as 100KB

    sprintf((char *)tmpBuf, "%d", 100*1024);

    lRetVal = HTTPCli_sendField(httpClient, HTTPCli_FIELD_NAME_CONTENT_LENGTH, (const char *)tmpBuf, lastFlag);

    dataSend = 0;

    while(dataSend < (100*1024))

    {

           lRetVal = HTTPCli_sendRequestBody(httpClient, buf,  10*1024);

          dataSend  += (10*1024);

    }

    Regards,

    Aashish

  • Hi Aashish,

    thank you for your help.

    Now i have a problem with Json 

    I copy json.c and json.h from CC3200SDK_1.2.0 to my current SDK:  CC3200SDK_1.1.0

     


    and write new function

    int JSMN_JSON_parser(char *ptr)
    {
    	long lRetVal = 0;
    
    	jsonParser  jParser;
    	jsonObj     jRootObj;
    	jsonObj     jResultArrayObj0;
    	jsonObj     jAlternativeArrayObj0;
    
    	jsonArray   jResultArray;
    	jsonArray   jAlternativeArray;
    	/*
    {
      "result":[
        {
          "alternative":[
            {
              "transcript":"this is a test",  // i need this
              "confidence":0.97321892
            },
            {
              "transcript":"this is a test for"
            }
          ],
          "final":true
        }
      ],
      "result_index":0
    }
    	 */
    	char        tempStr[32];
    
    	// Get root JSON node
    	 jRootObj = json_parser_init(&jParser, ptr);
    
    	// Get "result" array
    	jResultArray = json_object_get_array(&jParser, jRootObj, "result"); 
    
    	// Get object at index 0 in "result" array
    	jResultArrayObj0 = json_array_get_object(&jParser, jResultArray, 0); 
    
    	 // Get "alternative" array from index 0 of "result" array // lay' array cua? alternative
    	jAlternativeArray = json_object_get_array(&jParser, jResultArrayObj0, "alternative");
    
    	// Get object at index 0 in "alternative" array // array alternative [ objet0 , objet1]
    	 jAlternativeArrayObj0 = json_array_get_object(&jParser, jAlternativeArray, 0); 
    
    	// Get value of "transcript" from object at index 0 in "alternative" array 
    	json_object_get_string(&jParser, jAlternativeArrayObj0, "transcript", tempStr);
    
    	return lRetVal;
    }


    then i add  #include "json. and build the project. These errors appear 

    If i copy all folder netapps from  CC3200SDK_1.2.0 to my current SDK:  CC3200SDK_1.1.0 , these errors appear 

    If i use all new CCS , SDK, Servicepack , my cc3200 cannot connect to my AP 

    If i change CC3200_SDK_ROOT  CC3200SDK_1.1.0 to CC3200SDK_1.2.0,  There is an error cannot open source file "provisioning_api.h" just like thist post 

    what should i do. 

    Would you mind helping me.

    Thank you and best regards,

    Khoa

     

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    If i copy all folder netapps from  CC3200SDK_1.2.0 to my current SDK:  CC3200SDK_1.1.0 , these errors appear 

    Did you recompiled HTTP client and json libraries again. If not, then you need to do it. Best way to add JSON wrapper layer is copy json.c and json.h to json folder.

    export the project in CCS and add json.c. To add json.c to json library project follow below steps:

    1. Go to properties.

    2. Select Add files.

    3. Browser to file location

    4. Select json.c and click on OK

    5. No re-compile the library and application

    Tuan Khoa Nguyen said:

    If i change CC3200_SDK_ROOT  CC3200SDK_1.1.0 to CC3200SDK_1.2.0,  There is an error cannot open source file "provisioning_api.h" just like thist post 

    what should i do. 

    To port you application to SDK1.2.0, follow below steps:

    1. Add  simplelink_extlib/provisioninling to include path("${CC3200_SDK_ROOT}/simplelink_extlib/provisioninglib")

    2. Add network_common.c to your project

    3. Add SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)  to your main.c 

    SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent) 

    {

    // Do noting

    }

    4. Default simplelink binary that come with SDK is in production mode and will not work with CCS in debug mode. To use debug mode with CCS, recompile simplelink with debug configuration and update simplelink library path in application project properties. For more detail please refer "section 3.1.3 -Switch Between OS, NON-OS, and Debug Configurations" of "docs\CC3200-Programmers_Guide.pdf"

    Regards,

    Aashish

  • Hi Aashish, 

    Thank you for your help

    I choose the first choice and it can debug again.

    In second choice, the 4th step makes me confused. My Set active only have Release and have more errors when i include network_common.c.

    So decided to keep use cc3200SDK_1.1

    I have a few question about processing google response. Would you mind helping me, please

    1/ This is the response from google. I have it from many tool help send HTTP post. 

    {"result":[]}
    {"result":[{"alternative":[{"transcript":"Xin chào","confidence":0.79667556},{"transcript":"chim chào"},{"transcript":"xinh chào"},{"transcript":"xinh đẹp"},{"transcript":"trứng gà"}],"final":true}],"result_index":0}

    I have it from many tool help send HTTP post. 

    Google doesn't send Content-Length header so i have to set   len = 1024

    I use 

    bytesRead = HTTPCli_readResponseBody(httpClient, (char *)dataBuffer, len, &moreFlags);

    and dataBuffer only contains 

    {"result":[]}

    I have tried calling the HTTPCli_readResponseBody function twice or HTTPCli_readRawResponseBody function 

    but the dataBuffer still the same.

    It means Goolge send the response with duplicate result of recognition.

    I found a same problem in stackoverflow but they use PHP

    What should i do to deal with it  ,even i have tried calling those APIs twice and it still not work.

    2/ this is my code to send more data > 16KB

    	/* Send POST data/body */
    
    	unsigned char i = 0;
    	unsigned int counts = (sizeof(POST_DATA)-1)/(10*1024); // surplus + counts*(10*1024) = (sizeof(POST_DATA)-1)
    	while(i < counts)
    	{
    		lRetVal = HTTPCli_sendRequestBody(httpClient, POST_DATA, 10*1024 ); // send 10KB data
    		i++;
    	}
    	lRetVal = HTTPCli_sendRequestBody(httpClient, POST_DATA,(sizeof(POST_DATA)-1)-counts*(10*1024));  // send the surplus data
    	if(lRetVal < 0)
    	{
    		UART_PRINT("Failed to send HTTP POST request body.\n\r");
    		return lRetVal;
    	}
    
    	lRetVal = readResponse(httpClient);

    is it right ?

    The status code is 200 means successfully but i'm not sure Google received successfully all the data or just receiced the surplus data.  if it just sent the surplus data,that will be the reason the dataBuffer always the same

    Thank you and best regards,

    Khoa

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    In second choice, the 4th step makes me confused. My Set active only have Release and have more errors when i include network_common.c.

    That is applicable for simplelink library not for application. If you want to debug application in CCS from SDk1.2.0 onward you need to link your application with debug version of simplelink library(simplelink/ccs/nonos_debug/simplelink.a or simplelink/ccs/os_debug/simplelink.a). 

    Tuan Khoa Nguyen said:
    Google doesn't send Content-Length header so i have to set   len = 1024

    Is it chunked data? In case of chunked data server will not send "Content-Length" but will  "Transfer-Encoding:chunked" HTTP header. Check whether "ransfer-Encoding" header is there. Refer file_download example for reading chunked data.

    Tuan Khoa Nguyen said:
    	unsigned char i = 0;
    	unsigned int counts = (sizeof(POST_DATA)-1)/(10*1024); // surplus + counts*(10*1024) = (sizeof(POST_DATA)-1)
    	while(i < counts)
    	{
    		lRetVal = HTTPCli_sendRequestBody(httpClient, POST_DATA, 10*1024 ); // send 10KB data
    		i++;
    	}
    	lRetVal = HTTPCli_sendRequestBody(httpClient, POST_DATA,(sizeof(POST_DATA)-1)-counts*(10*1024));  // send the surplus data
    	if(lRetVal < 0)
    	{
    		UART_PRINT("Failed to send HTTP POST request body.\n\r");
    		return lRetVal;
    	}
    
    	lRetVal = readResponse(httpClient);

    is it right ?

    No. You are not updating buffer(POST_BUFFER) pointer. Refer below pseudo code: 

    while(i < counts)
    {
    		lRetVal = HTTPCli_sendRequestBody(httpClient, tmpBuf, 10*1024 ); // send 10KB data
    		i++;
    tmpBuf = tmpBuf+(10*1024); // Increment buffer pointer to 10KB to send next 10 KB data }


    Tuan Khoa Nguyen said:
    The status code is 200 means successfully but i'm not sure Google received successfully all the data or just receiced the surplus data.  if it just sent the surplus data,that will be the reason the dataBuffer always the same

    If you received 200 means it received data successfully.

    Regards,

    Aashish 

    Regards,

    Aashish

  • Hi Aashish,

    Thank you for your help

    this is the response header i have from Postman

    alt-svc →quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"
    alternate-protocol →443:quic
    cache-control →no-transform
    content-disposition →attachment
    content-encoding →gzip
    content-type →application/json; charset=utf-8
    date →Wed, 20 Apr 2016 17:29:58 GMT
    pragma →no-cache
    server →S3 v1.0
    status →200
    x-content-type-options →nosniff
    x-frame-options →SAMEORIGIN
    x-xss-protection →1; mode=block

    In the previous picture, in CCS debug you can see the yellow highlight:  Chucked encode


     


    So i don't know it was a gzip encode type or a Chucked encode type .

    But in stackoverflow, he said the response was :

    HTTP/1.1 200 OK
    Content-Type: application/json; charset=utf-8
    Content-Disposition: attachment
    Cache-Control: no-transform
    X-Content-Type-Options: nosniff
    Pragma: no-cache
    Date: Thu, 15 May 2014 12:41:09 GMT
    Server: S3 v1.0
    X-XSS-Protection: 1; mode=block
    X-Frame-Options: SAMEORIGIN
    Alternate-Protocol: 80:quic
    Transfer-Encoding: chunked
    e
    {"result":[]}    <--- first one
    f8
    {"result":[{"alternative":[{"transcript":"............","confidence":0.73531097},{"transcript":"................"},{"transcript":".............."},{"transcript":"................"},{"transcript":"............ .."}],"final":true}],"result_index":0}   <--- second one
    0

    So i think it's a chucked encode

    If it's a chucked encode , that is the reason why i cannot  receive the second result,  right ?

    I will check  file_download example and update to you soon.

    Best regards,

    Khoa

     

     

     

  • Hi Khoa,

    Tuan Khoa Nguyen said:

    In the previous picture, in CCS debug you can see the yellow highlight:  Chucked encode


     


    So i don't know it was a gzip encode type or a Chucked encode type .

    We asked about "Transfer-Encoding" not about "Content-Encoding". From image seems like you are receiving chunked data.

    Tuan Khoa Nguyen said:
    If it's a chucked encode , that is the reason why i cannot  receive the second result,  right ?

    No, you will able to read second result. For that you need to change current logic. Please refer file-download example to read chunked encoded body.

    Regards,

    Aashish 

  • Hi Aashish,

    1/ I still can't receive the second result even i chaged current logic

    This is my code

    	const char *ids[4] = {
    			HTTPCli_FIELD_NAME_CONTENT_LENGTH,
    			HTTPCli_FIELD_NAME_TRANSFER_ENCODING,
    			HTTPCli_FIELD_NAME_CONNECTION,
    			NULL
    	};
    
    			HTTPCli_setResponseFields(httpClient, ids);
    
    			// Read response headers
    			while ((id = HTTPCli_getResponseField(httpClient, (char *)g_buff, sizeof(g_buff), &moreFlags))
    					!= HTTPCli_FIELD_ID_END)
    			{
    
    				if(id == 0)
    				{
    					UART_PRINT("Content length: %s\n\r", g_buff);
    				}
    				else if(id == 1)
    				{
    					if(!strncmp((const char *)g_buff, "chunked", sizeof("chunked")))
    					{
    						UART_PRINT("Chunked transfer encoding\n\r");
    					}
    				}
    				else if(id == 2)
    				{
    					if(!strncmp((const char *)g_buff, "close", sizeof("close")))
    					{
    						ASSERT_ON_ERROR(FORMAT_NOT_SUPPORTED);
    					}
    				}
    
    			}
    
    			while(1)
    			{
    				bytesRead = HTTPCli_readResponseBody(httpClient, (char *)g_buff, sizeof(g_buff) - 1, &moreFlags);
    				if(bytesRead < 0)
    				{
    					UART_PRINT("Failed to received response body\n\r");
    					lRetVal = bytesRead;
    					goto end;
    				}
    // start action
    				UART_PRINT("%s \n\r",g_buff);
    // check end point
    				if ((bytesRead - 2) >= 0 && g_buff[bytesRead - 2] == '\r' && g_buff [bytesRead - 1] == '\n'){
    					break;
    				}
    
    				if(!moreFlags)
    				{
    					break;
    				}
    			}

    It prints this while in loop

    {"result":[]}
    g 
    a 

    I do the same as file_download example 

    Do you have any ideas 

    2/ And this is my code send HTTP POST

    	/* Send POST data/body */
    
    	unsigned char i = 0;
    	char *tmpBuf2 = POST_DATA;
    
    	unsigned int counts = (sizeof(POST_DATA)-1)/(10*1024); // // surplus + counts*(10*1024) = (sizeof(POST_DATA)-1)
    	while(i < counts)
    	{
    		lRetVal = HTTPCli_sendRequestBody(httpClient,tmpBuf2, 10*1024 ); //send 10KB data
    		i++;
    		tmpBuf2 = tmpBuf2+(10*1024);
    	}
    	lRetVal = HTTPCli_sendRequestBody(httpClient, tmpBuf2,(sizeof(POST_DATA)-1)-counts*(10*1024)); // send the surplus data
    

    Is this code able to send HTTP Post Binary data (base64)  ( Content- type: audio/l16;rate=16000; ) ? or i have to config something so that cc3200 able to send binary data

    Thank you and regards,

    Khoa

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    1/ I still can't receive the second result even i chaged current logic

    Please share all server related information or bare minimum project to tried at my end.

    Tuan Khoa Nguyen said:
    Is this code able to send HTTP Post Binary data (base64)  ( Content- type: audio/l16;rate=16000; ) ? or i have to config something so that cc3200 able to send binary data

    Yes there is no restriction. But you need to convert data to base64.

    Regards,

    Aashish

  • Hi Aashish,

    This is my project Copy of http_client_demo.rar

    The project send HTTP POST request,which containts  POST_DATA (Binary data , base64 ) of the voice to google speech api. 


    I use this page to encode base64 the wav file. Then copy it to POST_DATA

    After send to Google completely ( Use the certificate in Copy of http_client_demo\Release\certificate\Google 2.cer )

    If you use english, you have to change  POST_REQUEST_URI from "lang=vi-VN"   to  "lang=en-US"

    Google will return a result. 

    The result of this POST_DATA should be : ( i use vietnamese)

    {"result":[]}
    {"result":[{"alternative":[{"transcript":"Xin chào","confidence":0.84101135},{"transcript":"chim chào"},{"transcript":"xinh đẹp"},{"transcript":"trứng gà"},{"transcript":"sinh nhật"}],"final":true}],"result_index":0}

    But i only receive the first result. even chaged the logic.

    This is the return header:

    alt-svc →quic=":443"; ma=2592000; v="33,32,31,30,29,28,27,26,25"
    alternate-protocol →443:quic
    cache-control →no-transform
    content-disposition →attachment
    content-encoding →gzip
    content-type →application/json; charset=utf-8
    date →Fri, 29 Apr 2016 19:15:53 GMT
    pragma →no-cache
    server →S3 v1.0
    status →200
    x-content-type-options →nosniff
    x-frame-options →SAMEORIGIN
    x-xss-protection →1; mode=block

    Would you mind testing it at your place. 

    I use CCS 6.1.0 and CC3200SDK_1.1.0 in my project

    Thank you for your help and regards,

    Khoa

  • Hi Khoa,


    We tried to send request (same as what you are sending through http client demo) using different windows tool and we never received "{"result":[{"alternative":[{"transcript":"Xin chào","confidence":0.84101135},{"transcript":"chim chào"},{"transcript":"xinh đẹp"},{"tr" from server. Server always sending "{"result": []}" only.

    Below is request that we send using different windows tools:
    Accept: */*
    Accept-Encoding: gzip, deflate
    Content-Length: 23344
    Content-Type: audio/l16;rate=16000;
    Host: www.google.com
    key: AIzaSyB7BXVILFrNgDpdbDoctPqZQ5x4uI7BjNQ
    lang: en-US
    output: json
    <base64 data>

    And we got following response from server:
    Alt-Svc: quic=":443"; ma=2592000; v="33,32,31,30,29,28,27,26,25"
    Alternate-Protocol: 443:quic
    Cache-Control: no-transform
    Content-Disposition: attachment
    Content-Encoding: gzip
    Content-Type: application/json; charset=utf-8
    Date: Mon, 02 May 2016 07:29:56 GMT
    Pragma: no-cache
    Server: S3 v1.0
    Transfer-Encoding: chunked
    X-Content-Type-Options: nosniff
    X-Frame-Options: SAMEORIGIN
    X-Xss-Protection: 1; mode=block
    {
    "result": []
    }

    So it's seems something wrong with the way request is sent. Please share exact request you are sending using your python script.


    Also there is issue in your code. You are trying to half the chunked data type and half the logic of where you receive content-length header. That's the reason you are getting "Mismatch in content length and received data length" error. The "len" value you are passing as 0 in HTTPCli_readResponseBody() API that's the reason return value is -ve. You need to pass len as buffer size as below

    HTTPCli_readRawResponseBody(httpClient, (char *)dataBuffer, sizeof(g_buff));



    Regards,
    Aashish
  • Hi Aashish,

    Thank you for your help.

    1/ I tested google speech api with python base on Temboo SDK so you have to download temboo python sdk here .

    This is my python script speech1.rar

    and 2 voice files  

    2 voices file and temboo python SDK should be in the same directory as this speech1.py file

    if you use English,replace "vi-VN" with "en-US"  in parameters

    2/ I also tested with energia too.  I send the same the POST_DATA which i send in http_demo and receive the result correctly 

    The POST_DATA was based on "xin chao 2.wav", which was encoded base64 from this web 

    This is my project test_GG.rar

    Remember to chage the WIFI_SSID and WPA_PASSWORD in TembooAccount.h 

    3/ After i used Temboo SDK , i don't want to rely on it

    I realized how to send request HTTP POST to google speech:

    + The voice file have to be in mono and f_rate = 16000 Hz

    + Content-Type: audio/l16;rate=16000;

    + output : json

    + lang : vi-VN or en-US

    + key : google_api Key

    This is the Post_url:  www.google.com/.../recognize

    With those infomations, I use Postman send POST request which contains binary data in the body

    This is all that I know for now. 

    p/s: Temboo create Encode data text box  for posting only binary data so i think that why we have to change something in the way we send the POST_DATA.

    Maybe missing some Parameter or Header so Google didn't realize binary data from CC3200

    Thank you and regards,

    Khoa

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    I tested google speech api with python base on Temboo SDK so you have to download temboo python sdk here .

    This script send data to temboo server and then temboo server forward it to google server. So cant able to find what exact header temboo add for base64 encoded data.

    Tuan Khoa Nguyen said:
    I also tested with energia too.  I send the same the POST_DATA which i send in http_demo and receive the result correctly 

    Shared energia example also send request to temboo server and then temboo server modify the request and forward to google speech server.

    Tuan Khoa Nguyen said:
    With those infomations, I use Postman send POST request which contains binary data in the body

    With Postman also we are getting only one JSON data "{result":[]}", even with binary data

    Tuan Khoa Nguyen said:

    p/s: Temboo create Encode data text box  for posting only binary data so i think that why we have to change something in the way we send the POST_DATA.

    Maybe missing some Parameter or Header so Google didn't realize binary data from CC3200

    To know exactly what header/info temboo server send for base64, please contact temboo server team or contact to google to know what header you need to add for base64 encoded data.

    We are able to get valid response from google speech server. We are sending binary raw data as it is(means read the wav file and send it) rather than sending base64 encoded data. Please below console log and attached project (http_client_demo_504757.zip)for your reference.

    HTTP Post Begin:
    HTTP Status 200
    Content-Type : application/json; charset=utf-8
    Chunked transfer encoding
    {"result":[]}

    {"result":[{"alternative":[{"transcript":"taobao","confidence":0.24557085},{"transcript":"How do you do"},{"transcript":"How Google"},{"transcript":"hamburger"},{"transcript":"Hello Google"}],"final":true}],"result_index":0}

    value at index 0 is taobao
    value at index 1 is How do you do
    value at index 2 is How Google

    value at index 3 is hamburger
    value at index 4 is Hello Google

    HTTP Post End:

    Note: Attached project is based on SDK1.2.0


    Regards,
    Aashish

  • Hi Aashish,

    thank you for your help,

    Yes, I know the data will be sent to temboo sever and it took so much time to receive result., that is the reason i don't want to rely on them. 



    I already asked them about that but they haven't replied yet.  

    1/  It's weird. My Postman still works fine.  

    Did you choose binary tab in body and open "xin chao 2.wav" ? or ?

    2/  I will research your project and update later


    Thank you and regards,

    Khoa

  • Hi, Aashish

    I really appreciate your help in resolving the problem. 

    Now I know that it's a problem with a missing code

    But I'm still wondering something.

    1/ which tool you use to convert wav to raw data source just like postData in the project 

    2/ If i use CC3200 audio boosterpack and i want to send the voice data to google which was recorded by Mic in, I just need to get the data from which variables ?

    g_pRecordBuffer or something else ?  

    Is It the same "binary raw data" type  with postData in http_demo example ?

    Thank you again for everything you’ve done

    Regards,

    Khoa

       

  • Hi Khoa,

    Tuan Khoa Nguyen said:
    1/ which tool you use to convert wav to raw data source just like postData in the project 

    We didn't use any tool to covert data. We open wav file in hex editor and copied to array. You dont need to use any tool to concert in raw. Flash the file using uniflash and in application read the file and dens the data to server. 

    Tuan Khoa Nguyen said:

    2/ If i use CC3200 audio boosterpack and i want to send the voice data to google which was recorded by Mic in, I just need to get the data from which variables ?

    g_pRecordBuffer or something else ?  

    Is It the same "binary raw data" type  with postData in http_demo example ?

    Yes, use g_pRecordBuffer to get mic data. And it is the raw data, you dont need to convert it Simply send it to server. But I am not sure whether you need to add WAV header or not.

    Regards,

    Aashish

  • Hi,Aashish

    thank you for replying

    1/ Is it right if i write 

    #define postData (unsigned char*)(pRecordBuffer->pucReadPtr)

    2/ I combined project http_demo and wifi_ audio_app

    I have already included "json.h"  but it stil gets errors :

    unresolved symbol json_array_get_object, first referenced in ./main.obj

    unresolved symbol json_array_get_object, first referenced in ./main.obj

    unresolved symbol json_object_get_string, first referenced in ./main.obj

    If i copy Json.c and json.h into my project. it gets errors :

    unresolved symbol jsmn_init, first referenced in ./json.obj
    unresolved symbol jsmn_init, first referenced in ./json.obj

    combine.rar

    Would you mind helping me.

    Thank you and regards,

    Khoa

  • Hi Khoa,

    Tuan Khoa Nguyen said:

    1/ Is it right if i write 

    #define postData (unsigned char*)(pRecordBuffer->pucReadPtr)

    Why defining as macro, you can directly use it. Also keep in mind to update pucReadPtr value once you read the data.

    Tuan Khoa Nguyen said:

    If i copy Json.c and json.h into my project. it gets errors :

    unresolved symbol jsmn_init, first referenced in ./json.obj
    unresolved symbol jsmn_init, first referenced in ./json.obj

    You need to add jsmn.c and jsmn.h also.

    Regards,

    Aashish

  • Hi Aashish,

    Thank you for your help

    I copy all the code in http_demo into network_project.c ( I renamed network.c and network.h to network_project.c)

    In network_project.h I included 

    // HTTP Client lib
    #include <http/client/httpcli.h>
    #include <http/client/common.h>

    In  network_project.c i created  

    HTTPCli_Struct httpClient;

    I want httpClient is a global variable, so in  network_project.h i created 

    extern HTTPCli_Struct httpClient;

    I added   _SL_   in predefined project

    But I still get the error 

    unresolved symbol HTTPCli_connect, first referenced in ./network_project.obj
    unresolved symbol HTTPCli_construct, first referenced in ./network_project.obj

    Would you mind giving me some advice


    Regards,

    Khoa

  • Hi Aashish,

    1/  What is the maximum number of PACKET_SIZE that I can have in a pack 

                int iBufferFilled = 0;
                iBufferFilled = GetBufferSize(pRecordBuffer);
                if(iBufferFilled >= (2*PACKET_SIZE))
                { 
                    if(g_loopback)
                    {
                        lRetVal = FillBuffer(pPlayBuffer,\
                                              (unsigned char*)(pRecordBuffer->pucReadPtr), \
                                              PACKET_SIZE);
                        if(lRetVal < 0)
                        {
                            UART_PRINT("Unable to fill buffer\n\r");
                        }
                        g_iReceiveCount++;
                    }
                    UpdateReadPtr(pRecordBuffer, PACKET_SIZE);
                    g_iSentCount++;
                }

    I mean if i record my voice by the Mic.

    What is the maximum amount of  minutes/ seconds/ KBs that can be stored on pucReadPtr ?



    Because i want to send pucReadPtr as a HTTP Post body after the record is finished 

    2/ The PACKET_SIZE is the size of  each small pucReadPtr pack in the loop ?

                if(iBufferFilled >= (2*PACKET_SIZE))
                { 
                    if(g_loopback)
                    {
                        lRetVal = FillBuffer(pPlayBuffer,\
                                              (unsigned char*)(pRecordBuffer->pucReadPtr), \
                                              PACKET_SIZE);

    why Fillbuffer only use  one PACKET_SIZE .

     we have if(iBufferFilled >= (2*PACKET_SIZE)) , so it should be two PACKET_SIZE  .

    I'm confused



    3/ or I should add each pucReadPtr value intro an array after used FillBuffer ?

                        lRetVal = FillBuffer(pPlayBuffer,\
                                              (unsigned char*)(pRecordBuffer->pucReadPtr), \
                                              PACKET_SIZE);
                        postdata[g_iSentCount] = pucReadPtr;

    4/ What does g_iSentCount and g_iReceiveCount do in project ?

    I can't find what does it do in project so i think i can use it like this

    postdata[ g_iReceiveCount]  = pucReadPtr;
    g_iReceiveCount++ ;

     

    Thank you and regards,

    Khoa

  • Hi,

    I try config only in loopback mode without  Osi.h but it didn't work wifi_audio_app_doan2.rar

    Would you mind helping me

    Thanks and regards,

    Khoa

  • HI Khoa,


    Is it default SDK wifi example without any modification in loopback working or not?


    Regards,
    Aashish
  • Hi Aashish.

    Thank you for your reply

    The default SDK wifi example without any modification in loopback working perfectly

    I copy code from wifi_audio_app project into http_client_demo project . I only use Microphone()

    Did i config in loop mode correctly .
    Is it right to put Microphone() in while loop

    Regards,
    Khoa
  • Hi Aashish,
    We have used your code http_client_demo_504757 to upload the audio data to google server and get the text back,
    can you please tell how to do the same thing over HTTP secure network and what changes has to be done in the code.
    Thank you
    Regards
    Deepak
  • Hi Deepak,


    Please refer secure connection section on processors.wiki.ti.com/.../CC32xx_HTTP_Client_Demo


    Regards,
    Aashish
  • Hi Aashish,

    Thanks a lot for your reply,

    We are try to connect to a HOST:"dictation.nuancemobility.net" and PORT NUMBER:"443",

    we are not able to connect to the server in secure method,

    Please can you give a try to that and share the results,

    Also we have to send a audio file using HTTP post  to the server of 256KB can it be done in MIN library mode or we have to use FULL library mode,

    Please can you try connection to above server in HTTP clinet mode,

    Thanks 

  • Do you have ever see the error before ? the error will show just when i add http get file function to
    the email demo,the erro below:
    "D:/TI/CC3200SDK_1.2.0/cc3200-sdk/netapps/http/client/network.h", line 74: fatal error #35: #error directive: No or unrecognized network configuration specified
  • "D:/TI/CC3200SDK_1.2.0/cc3200-sdk/netapps/http/client/network.h", line 74: fatal error #35: #error directive: No or unrecognized network configuration specified
  • Hi user4756937,

    For support on a new issue, please post a new thread in the forum. You can reference another thread link in your post if you think it is relevant.

    Best regards,
    Sarah