<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cJSON_print() issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60746/cjson_print-issue</link><description>I&amp;#39;m using nRF9160DK and in that cJSON formation give me some error because of that my device will restart again and again 
 as in code if I&amp;#39;m input cJSON_AddNumberToObject(Data,&amp;quot;Humidity&amp;quot;,22); that time its happening but I thing the problem with cJSON_print</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Oct 2021 09:26:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60746/cjson_print-issue" /><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/333681?ContentTypeID=1</link><pubDate>Tue, 12 Oct 2021 09:26:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c935dc27-2ffd-4af7-bf14-0f54b76bcf95</guid><dc:creator>code-magic</dc:creator><description>&lt;p&gt;I fixed this issue by altering my prj.conf file. The main culprit is shown below.&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_MAIN_STACK_SIZE=4096&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/333607?ContentTypeID=1</link><pubDate>Tue, 12 Oct 2021 00:54:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb870cdd-7c78-4f71-818d-e6f008684689</guid><dc:creator>code-magic</dc:creator><description>&lt;p&gt;So I am still getting crashes after calling cJSON_Init(). My prj.conf is below. I&amp;#39;m at a loss.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_CJSON_LIB=y

# newlibc
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_FPU=y
CONFIG_FPU_SHARING=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=32768
CONFIG_MAIN_STACK_SIZE=1280
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_HW_STACK_PROTECTION=y
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/302018?ContentTypeID=1</link><pubDate>Thu, 25 Mar 2021 20:42:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78f735b4-5e2c-4cc6-b81e-bf7aed459344</guid><dc:creator>Rafalino</dc:creator><description>&lt;p&gt;I had a similar issue and what I found out was that it was related to a wrong behavior in my code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In one case I allocated memory using &lt;strong&gt;k_malloc&lt;/strong&gt; but released it with &lt;strong&gt;free&lt;/strong&gt; instead of &lt;strong&gt;k_free.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Once I fixed&amp;nbsp;this wrong behavior the crashes disappeared.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247968?ContentTypeID=1</link><pubDate>Mon, 04 May 2020 15:24:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19aaf091-bef7-40a7-9371-2bf328736ed2</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Just would like to&amp;nbsp;let you know that I&amp;#39;ve figured out what was wrong with my code. I was having unexpected kernel panics / reboots because I had forgot to inicialize the cJSON library. I&amp;#39;ve managed to fix the reboots by adding this at the beginning of my code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;cJSON_Init();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hope this can fix your problem too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247650?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 19:56:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9ca51ec-e8e4-40cd-a86f-dd98fd82d80b</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;Thanks,&lt;/p&gt;
[quote userid="26000" url="~/f/nordic-q-a/60746/cjson_print-issue/247647"]cJSON in the asset_tracker example[/quote]
&lt;p&gt;&amp;gt;&amp;nbsp; That part is working because there are Numbers in String format not Not in INT, I checked already like {&amp;quot;temp&amp;quot; : &amp;quot;23&amp;quot; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; but i&amp;#39;m looking like that {&amp;quot;temp&amp;quot; : 23 }..&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;nbsp; I did get what you try to say by that&lt;/p&gt;
[quote userid="26000" url="~/f/nordic-q-a/60746/cjson_print-issue/247647"]I also needed to add&amp;nbsp;CONFIG_MODEM_INFO_ADD_DATE_TIME=n[/quote]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247647?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 19:47:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71c21e5c-5138-40cb-9fc9-4018a11a0de1</guid><dc:creator>Tiago Costa</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m having a similar issue. I can use cJSON in the asset_tracker example to retrieve modem information without problems, but if I try to run the same code in the&amp;nbsp;mqtt_simple sample, my board reboots&amp;nbsp;on&amp;nbsp;cJSON_PrintUnformatted() after calling&amp;nbsp;modem_info_json_string_encode(). Couldn&amp;#39;t yet figure out what&amp;#39;s causing this.&lt;/p&gt;
&lt;p&gt;Sample code:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	err = modem_info_init();
	if (err) {
		printk(&amp;quot;Modem info could not be established: %d&amp;quot;, err);
		return;
	}

	modem_info_params_init(&amp;amp;modem_param);

        cJSON *root_obj = cJSON_CreateObject();

	if (root_obj == NULL) {
		printk(&amp;quot;Unable to allocate JSON object&amp;quot;);
		return;
	}

	size_t item_cnt = 0;

        int ret = modem_info_params_get(&amp;amp;modem_param);
        char root_buf[MODEM_INFO_JSON_STRING_SIZE];

	if (ret &amp;lt; 0) {
		printk(&amp;quot;Unable to obtain modem parameters: %d&amp;quot;, ret);
	} else {
                printk(&amp;quot;Got modem parameters&amp;quot;);
		ret = modem_info_json_object_encode(&amp;amp;modem_param, root_obj);
		if (ret &amp;gt; 0) {
			item_cnt = (size_t)ret;
		}
                modem_info_json_string_encode(&amp;amp;modem_param, root_buf);
                data_print(&amp;quot;Modem info: &amp;quot;, root_buf, MODEM_INFO_JSON_STRING_SIZE);
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Error in console:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Got modem parameters[00:00:19.870,330] &amp;lt;err&amp;gt; os: ***** BUS FAULT *****
[00:00:19.875,854] &amp;lt;err&amp;gt; os:   Precise data bus error
[00:00:19.881,683] &amp;lt;err&amp;gt; os:   BFAR Address: 0x6eef9a63
[00:00:19.887,664] &amp;lt;err&amp;gt; os: r0/a1:  0x000fffff  r1/a2:  0x0000000f  r2/a3:  0x000fffff
[00:00:19.896,484] &amp;lt;err&amp;gt; os: r3/a4:  0x20029834 r12/ip:  0x8168b400 r14/lr:  0x0000f10b
[00:00:19.905,273] &amp;lt;err&amp;gt; os:  xpsr:  0xa100b800
[00:00:19.910,552] &amp;lt;err&amp;gt; os: s[ 0]:  0x00000005  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
[00:00:19.921,112] &amp;lt;err&amp;gt; os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
[00:00:19.931,671] &amp;lt;err&amp;gt; os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
[00:00:19.942,230] &amp;lt;err&amp;gt; os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
[00:00:19.952,728] &amp;lt;err&amp;gt; os: fpscr:  0x2002d4c0
[00:00:19.958,007] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00024162
[00:00:19.965,972] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00:00:19.973,846] &amp;lt;err&amp;gt; os: Current thread: 0x20021e3c (unknown)
[00:00:19.980,712] &amp;lt;err&amp;gt; fatal_error: Resetting system
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By the way, I also needed to add&amp;nbsp;CONFIG_MODEM_INFO_ADD_DATE_TIME=n in my prj.conf, otherwise retrieving modem information would fail. I have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CONFIG_HEAP_MEM_POOL_SIZE=16384&lt;/li&gt;
&lt;li&gt;CONFIG_MAIN_STACK_SIZE=8192&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247461?ContentTypeID=1</link><pubDate>Thu, 30 Apr 2020 07:40:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8dd88c7e-516c-4bd6-b462-a68203b47d3c</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;hello team,&lt;/p&gt;
&lt;p&gt;I waiting for your answer If you have anything to give me .... ??&lt;/p&gt;
&lt;p&gt;I tried with other json lib&amp;nbsp;&lt;a href="https://github.com/kgabis/parson"&gt;( this one)&lt;/a&gt;&amp;nbsp; too but the result is same as last time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247375?ContentTypeID=1</link><pubDate>Wed, 29 Apr 2020 13:58:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26cf9e73-c54b-47a9-bea5-2c261db3196c</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;Yes I did and I got point out like that&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/0728.Capture.PNG" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247364?ContentTypeID=1</link><pubDate>Wed, 29 Apr 2020 13:25:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7827861e-0b94-490f-85ce-386deb45327c</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Have you tried setting up a debug session to see where in the code it triggers the reset?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/247280?ContentTypeID=1</link><pubDate>Wed, 29 Apr 2020 10:05:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13caa5b6-68a1-4bf7-95db-3e84de735175</guid><dc:creator>Shekhar Suthar</dc:creator><description>[quote userid="66115" url="~/f/nordic-q-a/60746/cjson_print-issue/246829"]Please share the error output and more of your code.[/quote]
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
void main(void)
{
	
	if (!IS_ENABLED(CONFIG_AT_HOST_LIBRARY)) {
		/* Stop the UART RX for power consumption reasons */
		NRF_UARTE0_NS-&amp;gt;TASKS_STOPRX = 1;
		NRF_UARTE1_NS-&amp;gt;TASKS_STOPRX = 1;
	}


      cJSON *Attribute_json = NULL;
      cJSON *Device_data1 = NULL;
      cJSON *Device_data2 = NULL;
      cJSON *Data = NULL;
      cJSON *Sensor = NULL;
      char *out = NULL;

    Attribute_json = cJSON_CreateArray();
    cJSON_AddItemToArray(Attribute_json, Device_data1 = cJSON_CreateObject());
    cJSON_AddStringToObject(Device_data1, &amp;quot;uniqueId&amp;quot;,&amp;quot;uniqueId&amp;quot;);
    cJSON_AddStringToObject(Device_data1, &amp;quot;time&amp;quot;,&amp;quot;2020-04-01T06:23:23.000Z&amp;quot;);
    cJSON_AddItemToObject(Device_data1, &amp;quot;data&amp;quot;, Data = cJSON_CreateObject());
    cJSON_AddNumberToObject(Device_data1,&amp;quot;Humidity&amp;quot;, 45);
    //cJSON_AddStringToObject(Device_data1,&amp;quot;Humidity&amp;quot;, &amp;quot;45&amp;quot;);

    cJSON_AddNumberToObject(Data,&amp;quot;Temperature&amp;quot;,23);

   
    out = cJSON_PrintUnformatted(Attribute_json);
    //out = cJSON_Print(Attribute_json);

    while(1){
       printk(&amp;quot;\n &amp;gt;&amp;gt; %s \n&amp;quot;,out);
       // printk(&amp;quot;\n &amp;gt;&amp;gt; %s \n&amp;quot;,cJSON_PrintBuffered(Attribute_json, 2000,0));
       k_sleep(5000);
       }

}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I shared main function try to in that I just want to print that Json I tried two three way you can see in comments parts&lt;/p&gt;
&lt;p&gt;tried with making different function and pass there may be that will work but result is same&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;cJSON_AddNumberToObject(Device_data1,&amp;quot;Humidity&amp;quot;, 45);&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;if I use that way to add a Number in JSON that will restart again and again my device&lt;/p&gt;
&lt;p&gt;but if I used String on that case its working fine as below comment code&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; cJSON_AddStringToObject(Device_data1,&amp;quot;Humidity&amp;quot;, &amp;quot;45&amp;quot;);&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;even if add a single json number in object that isn&amp;#39;t working fine&amp;nbsp;&lt;strong&gt;&amp;nbsp; ????&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/246873?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 13:20:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5428b21-8751-4388-a13d-ea510f5ac481</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;I want publish my JSON data by MQTT to cloud &lt;/p&gt;
[quote userid="66115" url="~/f/nordic-q-a/60746/cjson_print-issue/246829"]Could you try to use this as a reference?[/quote]
&lt;p&gt;I tried that way too but when I return cJSON that send blank value in string &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/246829?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 12:28:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a6158a5-d94c-4f03-b6b6-15bc0b54f8a5</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Sekhar,&lt;br /&gt;Please share the error output and more of your code.&lt;br /&gt;&lt;br /&gt;Could you try to use this as a reference?&amp;nbsp;&lt;a href="https://github.com/civetweb/civetweb/blob/master/examples/rest/rest.c#L60"&gt;https://github.com/civetweb/civetweb/blob/master/examples/rest/rest.c#L60&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON_print() issue</title><link>https://devzone.nordicsemi.com/thread/246821?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 06:00:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3871aa8c-52aa-4876-9811-ee1a31605154</guid><dc:creator>Shekhar Suthar</dc:creator><description>&lt;p&gt;hello team its like 4th day today and I didn&amp;#39;t get nay update from your end&lt;/p&gt;
&lt;p&gt;please ..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>