Issues with running FOTA and cJSON

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 MQTT messages. When adding FOTA support to the project, I migrated to NCS 2.9.0 to facilitate the switch to sysbuild, which allowed be to embed MCUBoot as the bootloader. I implemented FOTA using the FOTA download library.

However, I am now having issues with the MQTT payload that I send periodically. Whenever a payload is sent, which is formatted in JSON using cJSON library, I know I will be unable to perform an FOTA update if I do not reboot first. My first guess would be memory management but I am not sure about it.

The error I get from the FOTA download is as such : 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[00:00:26.841,094] <inf> mqtt: topic received gateway/update/0011ce
[00:00:26.841,156] <inf> mqtt: Received: https://to-delete-testing.s3.ca-central-1.amazonaws.com/zephyr.signed.bin
[00:00:26.841,186] <inf> main: Update queried
[00:00:26.841,186] <inf> ota: https://bucket.s3.ca-central-1.amazonaws.com/zephyr.signed.bin
[00:00:26.841,247] <inf> ota: host : bucket.s3.ca-central-1.amazonaws.com
[00:00:26.841,918] <inf> ota: file : zephyr.signed.bin
[00:00:26.844,512] <inf> mqtt: Deiniting MQTT
[00:00:26.844,543] <inf> mqtt: Disconnecting MQTT client
[00:00:26.846,221] <inf> mqtt: MQTT client disconnected: 0
[00:00:26.846,252] <inf> mqtt: mqtt thread suspended
[00:00:26.846,252] <inf> ota: Mqtt was closed. Starting FOTA
[00:00:26.846,313] <inf> ota: FOTA inited
[00:00:26.846,405] <inf> download_client: Downloading: zephyr.signed.bin [0]
[00:00:26.846,405] <inf> ota: FOTA started
[00:00:26.973,480] <err> download_client: DNS lookup failed bucket.s3.ca-central-1.amazonaws.com
[00:00:26.973,510] <err> fota_download: Download client error
[00:00:26.973,510] <inf> ota: Received error from fota_download, 2
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

However, when I do not use the cJSON library prior to starting the update, it works flawlessly.

I was wondering if there are know changes I should know about between versions 2.7.0 and 2.9.0 of NCS whcich affect the way I should configure my project. My configuration file is a such

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CONFIG_GPIO=n
## To remove on production version
# Printing to UART
CONFIG_SERIAL=n
# Logging
CONFIG_LOG=n
# Wi-Fi
CONFIG_WIFI=y
CONFIG_NRF70_SR_COEX=y
CONFIG_NRF70_SR_COEX_RF_SWITCH=y
# WPA supplicant
CONFIG_WIFI_NM_WPA_SUPPLICANT=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_OFF=y
CONFIG_NRF70_RX_NUM_BUFS=16
CONFIG_NRF70_MAX_TX_AGGREGATION=4
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Network
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NANOPB=y
# Memory
CONFIG_NET_MGMT_EVENT_STACK_SIZE=5120
CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000
# Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=75
CONFIG_BT_WIFI_PROV=y
CONFIG_BT_BONDABLE=n
#CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_BUF_ACL_RX_SIZE=151
CONFIG_BT_L2CAP_TX_MTU=147
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and here is an excerpt of the app code that uses the cJSON library

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void device_publish_status(void) {
int err;
char *json_payload = NULL;
cJSON *response = NULL;
// Root section
if ((response = cJSON_CreateObject()) == NULL) {
goto end;
}
if (cJSON_AddStringToObject(response, "device_id", device_id) == NULL) {
goto end;
}
if (cJSON_AddStringToObject(response, "device_type", "room-lp") == NULL) {
goto end;
}
if (cJSON_AddStringToObject(response, "topic", MQTT_TOPIC_STR[TOPIC_GATEWAY_STATUS]) == NULL) {
goto end;
}
if (cJSON_AddNumberToObject(response, "uptime_mins", k_uptime_seconds()/60) == NULL) {
goto end;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX