<?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>Issues with running FOTA and cJSON</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/120773/issues-with-running-fota-and-cjson</link><description>Hi, 
 I recently added FOTA support on my project which runs on nRF5340 + nRF7002. I am currently working on a devboard, nRF7002DK. 
 Previously, I was running the project on NCS 2.7.0 and I was using the cJSON library to generate the payloads for my</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 24 Apr 2025 10:37:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/120773/issues-with-running-fota-and-cjson" /><item><title>RE: Issues with running FOTA and cJSON</title><link>https://devzone.nordicsemi.com/thread/532782?ContentTypeID=1</link><pubDate>Thu, 24 Apr 2025 10:37:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e896469-1b29-4fae-98f7-172bf1a6650a</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi again&lt;/p&gt;
&lt;p&gt;So, the fact that converting the number to strings makes it work it seems to be because a function somewhere expects string(s) and not numbers, and I think it might be this one from the &lt;strong&gt;download_client&lt;/strong&gt;()&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/nrf-apis-latest/page/group_fota_download_ga613aa199d71f84a9531ea42c56776a1b.html#ga613aa199d71f84a9531ea42c56776a1b"&gt;https://docs.nordicsemi.com/bundle/nrf-apis-latest/page/group_fota_download_ga613aa199d71f84a9531ea42c56776a1b.html#ga613aa199d71f84a9531ea42c56776a1b&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I&amp;#39;m guessing the download_client tried pulling one or more of your number values when a string was expected causing this issue.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with running FOTA and cJSON</title><link>https://devzone.nordicsemi.com/thread/532363?ContentTypeID=1</link><pubDate>Tue, 22 Apr 2025 13:08:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1e9060d-4995-4e54-8d18-187849ff6cdc</guid><dc:creator>simon belanger</dc:creator><description>&lt;p&gt;Thanks for the migration guides, I will make sure I did not forget important steps.&lt;/p&gt;
[quote userid="75734" url="~/f/nordic-q-a/120773/issues-with-running-fota-and-cjson/532308"]How exactly are you linking this to the cJSON being the issue? Does the error only occur if you&amp;#39;ve done cJSON operations, or could it be something else like the Wi-Fi being active and thus you&amp;#39;re not able to do a new connection?[/quote]
&lt;p&gt;I am not entirely sure that cJSON is the cause, but I observed that the fota error only occurs when I use the method&amp;nbsp;&lt;strong&gt;cJSON_AddNumberToObject()&lt;/strong&gt; from the cJSON library, as mentionned in my last post. This led me to think that I was doing something wrong with that library. If I do not use this function from cJSON, I get no issues with FOTA. As a workaround, I formatted all my number values to strings so I could use cJSON_AddStringToObject and the FOTA works fine.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with running FOTA and cJSON</title><link>https://devzone.nordicsemi.com/thread/532308?ContentTypeID=1</link><pubDate>Tue, 22 Apr 2025 10:14:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d412a81-3f72-4936-914f-faa34ee5a9d1</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t find anything specific related to JSON when moving from NCS v2.7.0 to 2.9.0, but there are a few migration steps you should be wary of when moving over. First off, the steps in &amp;quot;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/releases_and_maturity/migration/migration_guide_2.8.html"&gt;migration guide for NCS v2.8.0&lt;/a&gt;&amp;quot; has a lot of steps on how to move from 2.7.0 to 2.8.0. You should also go through the &amp;quot;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/releases_and_maturity/migration/migration_sysbuild.html"&gt;Migrating from multi-image builds to sysbuild&lt;/a&gt;&amp;quot; to make sure you&amp;#39;ve included all necessary steps. Additionally, the error that seems to return is a &amp;quot;No such file or directory&amp;quot; error from what I assume is the &lt;strong&gt;fota_dl_handler&lt;/strong&gt;() function apparently due to not being able to connect to the client. How exactly are you linking this to the cJSON being the issue? Does the error only occur if you&amp;#39;ve done cJSON operations, or could it be something else like the Wi-Fi being active and thus you&amp;#39;re not able to do a new connection?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with running FOTA and cJSON</title><link>https://devzone.nordicsemi.com/thread/532142?ContentTypeID=1</link><pubDate>Thu, 17 Apr 2025 20:38:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:342ba5d7-8786-4419-a393-e972c9d94805</guid><dc:creator>simon belanger</dc:creator><description>&lt;p&gt;As a supplement, here are my latest findings.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It seems like the issue can be traced back to cJSON numbers. I can reproduce the issue by creating a cJSON object and adding a single numeral field using cJSON_AddNumberToObject(), then printing this cJSON as a string using cJSON_Print and then freeing everything. If I were to create a string field using cJSON_AddStringToObject(), the bug would not occur.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void device_publish_status(void) {
	char *json_payload = NULL;
	cJSON *response = NULL;

	if ((response = cJSON_CreateObject()) == NULL) {
		goto end;
	}
	if (cJSON_AddNumberToObject(response, &amp;quot;battery_voltage_mv&amp;quot;, 42) == NULL) {
		goto end;
	}
	
	if ((json_payload = cJSON_Print(response)) == NULL) {
		LOG_ERR(&amp;quot;Failed to format response to JSON.&amp;quot;);
		goto end;
	}
	
	cJSON_FreeString(json_payload);
	LOG_INF(&amp;quot;String has been freed&amp;quot;);
end:
    cJSON_Delete(response);
	LOG_INF(&amp;quot;Object has been freed&amp;quot;);
	return;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So there seems to be an issue with cJSON_Number fields from my perspective that cause issues with memory which prevents the download client to perform OTA successfully. I did not include the OTA code but it is very similar to&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.9.0/page/nrf/samples/cellular/http_update/application_update/README.html"&gt;Cellular: HTTP application update&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I should also mention that I am using Zephyr&amp;#39;s allocators (k_malloc and k_free) on system heap. This is done by running cJSON_Init() from cjson_os.h at the beginning of the main application, before doing anything else. I am also freeing the string using cJSON_FreeString() in order to free memory for the output string using the same allocator I used to allocate it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>