This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

cJSON_print() issue

I'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'm input cJSON_AddNumberToObject(Data,"Humidity",22); that time its happening but I thing the problem with cJSON_print()

cJSON_AddItemToObject(Device_data1, "data", Data = cJSON_CreateObject());
cJSON_AddStringToObject(Data,"Temperature","67");
cJSON_AddStringToObject(Data,"Humidity","44");
//cJSON_AddNumberToObject(Data,"Humidity",22);

Attribute_json_Data = cJSON_Print(Attribute_json);

????

Parents
  • Hi,

    I'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 mqtt_simple sample, my board reboots on cJSON_PrintUnformatted() after calling modem_info_json_string_encode(). Couldn't yet figure out what's causing this.

    Sample code:

    	err = modem_info_init();
    	if (err) {
    		printk("Modem info could not be established: %d", err);
    		return;
    	}
    
    	modem_info_params_init(&modem_param);
    
            cJSON *root_obj = cJSON_CreateObject();
    
    	if (root_obj == NULL) {
    		printk("Unable to allocate JSON object");
    		return;
    	}
    
    	size_t item_cnt = 0;
    
            int ret = modem_info_params_get(&modem_param);
            char root_buf[MODEM_INFO_JSON_STRING_SIZE];
    
    	if (ret < 0) {
    		printk("Unable to obtain modem parameters: %d", ret);
    	} else {
                    printk("Got modem parameters");
    		ret = modem_info_json_object_encode(&modem_param, root_obj);
    		if (ret > 0) {
    			item_cnt = (size_t)ret;
    		}
                    modem_info_json_string_encode(&modem_param, root_buf);
                    data_print("Modem info: ", root_buf, MODEM_INFO_JSON_STRING_SIZE);
    	}

    Error in console:

    Got modem parameters[00:00:19.870,330] <err> os: ***** BUS FAULT *****
    [00:00:19.875,854] <err> os:   Precise data bus error
    [00:00:19.881,683] <err> os:   BFAR Address: 0x6eef9a63
    [00:00:19.887,664] <err> os: r0/a1:  0x000fffff  r1/a2:  0x0000000f  r2/a3:  0x000fffff
    [00:00:19.896,484] <err> os: r3/a4:  0x20029834 r12/ip:  0x8168b400 r14/lr:  0x0000f10b
    [00:00:19.905,273] <err> os:  xpsr:  0xa100b800
    [00:00:19.910,552] <err> os: s[ 0]:  0x00000005  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
    [00:00:19.921,112] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
    [00:00:19.931,671] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
    [00:00:19.942,230] <err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
    [00:00:19.952,728] <err> os: fpscr:  0x2002d4c0
    [00:00:19.958,007] <err> os: Faulting instruction address (r15/pc): 0x00024162
    [00:00:19.965,972] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00:00:19.973,846] <err> os: Current thread: 0x20021e3c (unknown)
    [00:00:19.980,712] <err> fatal_error: Resetting system
    

    By the way, I also needed to add CONFIG_MODEM_INFO_ADD_DATE_TIME=n in my prj.conf, otherwise retrieving modem information would fail. I have:

    • CONFIG_HEAP_MEM_POOL_SIZE=16384
    • CONFIG_MAIN_STACK_SIZE=8192
  • Thanks,

    cJSON in the asset_tracker example

    >  That part is working because there are Numbers in String format not Not in INT, I checked already like {"temp" : "23" }

         but i'm looking like that {"temp" : 23 }..

    >  I did get what you try to say by that

    I also needed to add CONFIG_MODEM_INFO_ADD_DATE_TIME=n
Reply Children
No Data
Related