Partial data formatted using sprintf


#1

Hi,
I need to send json data to Airvantage via mqtt. I am using sprintf to format data in json string.
Problem : Unable to get complete json string using sprintf though enough buffer allocated. In LE_INFO , I am able to see only partial string. Please let me know the solution.

Code snippet : (sprintf code is continuous in one line)

char *json_str=(char *)malloc(2048);
memset(json_str,0,2048);

sprintf(json_str,"{ “flowmeter.RId”: “1”,“flowmeter.Record_Written_Time”: “10/01/2018 11:21:32”,“flowmeter.Flow_Rate”: “404443901281042”,“flowmeter.Totalize”: “-57”,“flowmeter.DIStatus”: “17”,“flowmeter.DITimeStamp”:“13/06/2018 13:06:12” }");

Output :

{ “flowmeter.RId”: “1”,“flowmeter.Record_Written_Time”: “10/01/2018 11:21:32”,“flowmeter.Flow_Rate”: “404443901281042”,"flow

Request you to reply ASAP.
LE_INFO(“json_str”);


#2

I’ve seen LE_INFO truncate lines that are too long, so it may have a character limit per line. You should probably verify the contents of your string through some other means, like writing directly to stdout or a file.


#3

We observed the same with LE_INFO and we observed it has maximum size limit is 100 to 126 bytes.
If we try to print more than maximum size LE_INFO truncate the contents of strings.
We tried the same with “printf(“output json %s\n”,json_str);” It can able to display all the strings which used in sprintf.
below is the steps,
sprintf(json_str,"{ “flowmeter.RId”: “1”,“flowmeter.Record_Written_Time”: “10/01/2018 11:21:32”,“flowmeter.Flow_Rate”: “404443901281042”,“flowmeter.Totalize”: “-57”,“flowmeter.DIStatus”: “17”,“flowmeter.DITimeStamp”:“13/06/2018 13:06:12” }");
printf(“output json %s\n”,json_str);

We can suggest to use printf insted of LE_INFO(json_str).


#4

Thanks for your suggestions.