nrf9160 reboots sporadically after some time.

Hi,

I searched the forum and could not find a solution to my problem. So I decided to ask it here.

I am developing an application that sends some data to the cloud via MQTT. I receive the data and it works fine. However, after some time, the application restarts and I do not know why. This behaviour can be seen  on the lines 86, 127and 163 in the LTE link monitor. 

I thought it has some thing to do with deep sleep and tried to prevend deep sleep by changing the power management, but I have no idea if it had any affect. 

My other idea  was that it may be an exception or a hard fault, and I tried setting CONFIG_REBOOT=n to see if that changes anything, but it doesn't. The compiler just does not change it to false and gives me information that, after looking on the internet, I couldn't do anything with. 

Has anyone some tips why is this happening?

OS: Windows

SDK: 2.3.0

IDE: Visual Studio Code

Hardware: nRF9160 Development Kid

LTE Link Monitor:

2023-03-20T12:08:23.597Z INFO Using nrf-device-lib-js version: 0.5.0
2023-03-20T12:08:23.598Z INFO Using nrf-device-lib version: 0.13.11
2023-03-20T12:08:23.598Z INFO Using nrfjprog DLL version: 10.18.2
2023-03-20T12:08:23.598Z INFO Using JLink version: JLink_V7.80c
2023-03-20T12:08:23.792Z INFO Installed JLink version does not match the provided version (V7.66a)
2023-03-20T12:08:37.442Z INFO Modem port is opened
2023-03-20T12:08:37.450Z DEBUG modem >> AT+CFUN?
2023-03-20T12:08:38.316Z DEBUG modem << [00:00:02.699,401] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:08:39.365Z DEBUG modem << [00:00:03.746,032] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:08:39.370Z DEBUG modem << [0m
2023-03-20T12:08:39.372Z DEBUG modem << [00:00:03.789,520] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:08:39.374Z DEBUG modem << [0m
2023-03-20T12:08:44.419Z DEBUG modem << [00:00:08.800,781] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:08:44.423Z DEBUG modem << [0m
2023-03-20T12:08:44.427Z DEBUG modem << [00:00:08.800,933] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:08:44.432Z DEBUG modem << [00:00:08.802,154] [0m<inf> aero_sens2: PSM parameter update: TAU: 5760, Active time: 60
2023-03-20T12:08:44.434Z DEBUG modem << [0m
2023-03-20T12:08:44.439Z DEBUG modem << [00:00:08.984,741] [0m<inf> aero_sens2: IPv4 Address found 3.123.222.80[0m
2023-03-20T12:08:44.444Z DEBUG modem << [00:00:08.984,771] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:08:44.451Z DEBUG modem << [00:00:08.984,771] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:08:48.149Z DEBUG modem << [00:00:12.534,576] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:08:48.155Z DEBUG modem << 
2023-03-20T12:08:48.158Z DEBUG modem << [00:00:12.534,667] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:08:48.160Z DEBUG modem << [00:00:12.536,041] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:08:48.162Z DEBUG modem << 
2023-03-20T12:08:48.166Z DEBUG modem << [00:00:12.537,200] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:08:48.167Z DEBUG modem << 
2023-03-20T12:08:48.173Z DEBUG modem << [00:00:12.539,276] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:08:51.762Z DEBUG modem << [00:00:16.147,125] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:08:51.768Z DEBUG modem << [0m
2023-03-20T12:08:51.775Z DEBUG modem << [00:00:16.539,367] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:08:51.778Z DEBUG modem << [00:00:16.650,909] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:08:51.779Z DEBUG modem << [0m
2023-03-20T12:08:55.927Z DEBUG modem << [00:00:20.312,713] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:08:55.934Z DEBUG modem << [00:00:20.312,805] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:08:55.938Z DEBUG modem << [00:00:20.314,147] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:08:55.940Z DEBUG modem << 
2023-03-20T12:08:55.944Z DEBUG modem << [00:00:20.315,338] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:08:55.945Z DEBUG modem << 
2023-03-20T12:08:55.950Z DEBUG modem << [00:00:20.317,382] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:08:59.499Z DEBUG modem << [00:00:23.884,307] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:08:59.505Z DEBUG modem << [0m
2023-03-20T12:08:59.507Z DEBUG modem << [00:00:24.317,474] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:08:59.510Z DEBUG modem << [00:00:24.420,135] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:08:59.511Z DEBUG modem << [0m
2023-03-20T12:09:04.622Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:09:04.630Z DEBUG modem << [00:00:00.494,140] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:09:06.682Z DEBUG modem << [00:00:02.551,177] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:09:06.684Z DEBUG modem << 
2023-03-20T12:09:06.691Z DEBUG modem << [00:00:03.552,185] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:09:06.692Z DEBUG modem << [0m
2023-03-20T12:09:07.725Z DEBUG modem << [00:00:03.595,581] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:07.731Z DEBUG modem << [0m
2023-03-20T12:09:09.905Z DEBUG modem << [00:00:05.773,040] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:09:09.916Z DEBUG modem << [0m
2023-03-20T12:09:09.920Z DEBUG modem << [00:00:05.773,162] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:09:09.921Z DEBUG modem << [00:00:05.774,383] [0m<inf> aero_sens2: PSM parameter update: TAU: 3960, Active time: 60
2023-03-20T12:09:09.923Z DEBUG modem << [0m
2023-03-20T12:09:09.926Z DEBUG modem << [00:00:05.973,724] [0m<inf> aero_sens2: IPv4 Address found 3.127.15.183[0m
2023-03-20T12:09:09.927Z DEBUG modem << 
2023-03-20T12:09:09.931Z DEBUG modem << [00:00:05.973,754] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:09:09.932Z DEBUG modem << 
2023-03-20T12:09:09.941Z DEBUG modem << [00:00:05.973,754] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:14.669Z DEBUG modem << [00:00:10.539,886] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:09:14.678Z DEBUG modem << [00:00:10.540,008] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:09:14.680Z DEBUG modem << [00:00:10.541,381] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:09:14.685Z DEBUG modem << [00:00:10.542,480] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:09:14.687Z DEBUG modem << 
2023-03-20T12:09:14.692Z DEBUG modem << [00:00:10.544,433] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:09:14.693Z DEBUG modem << 
2023-03-20T12:09:18.386Z DEBUG modem << [00:00:14.257,141] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:09:18.388Z DEBUG modem << [0m
2023-03-20T12:09:18.391Z DEBUG modem << [00:00:14.544,525] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:18.404Z DEBUG modem << [00:00:14.665,924] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:18.405Z DEBUG modem << [0m
2023-03-20T12:09:22.922Z DEBUG modem << [00:00:18.793,701] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:09:22.932Z DEBUG modem << [00:00:18.793,823] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:09:22.935Z DEBUG modem << [00:00:18.795,135] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:09:22.945Z DEBUG modem << [00:00:18.796,234] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:09:22.946Z DEBUG modem << [00:00:18.798,370] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:09:26.377Z DEBUG modem << [00:00:22.249,237] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:09:26.387Z DEBUG modem << [0m
2023-03-20T12:09:26.389Z DEBUG modem << [00:00:22.798,461] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:26.392Z DEBUG modem << [00:00:22.896,179] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:26.393Z DEBUG modem << [0m
2023-03-20T12:09:31.376Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:09:31.385Z DEBUG modem << 
2023-03-20T12:09:31.388Z DEBUG modem << [00:00:00.493,988] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:09:33.435Z DEBUG modem << [00:00:02.550,994] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:09:33.445Z DEBUG modem << 
2023-03-20T12:09:34.484Z DEBUG modem << [00:00:03.598,236] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:09:34.487Z DEBUG modem << [0m
2023-03-20T12:09:34.490Z DEBUG modem << [00:00:03.642,608] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:34.492Z DEBUG modem << [0m
2023-03-20T12:09:38.771Z DEBUG modem << [00:00:07.885,864] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:09:38.782Z DEBUG modem << [0m
2023-03-20T12:09:38.785Z DEBUG modem << [00:00:07.886,016] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:09:38.787Z DEBUG modem << [00:00:07.887,237] [0m<inf> aero_sens2: PSM parameter update: TAU: 4320, Active time: 60
2023-03-20T12:09:38.788Z DEBUG modem << [0m
2023-03-20T12:09:38.792Z DEBUG modem << [00:00:08.128,814] [0m<inf> aero_sens2: IPv4 Address found 3.124.136.60[0m
2023-03-20T12:09:38.797Z DEBUG modem << [00:00:08.128,845] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:09:38.798Z DEBUG modem << 
2023-03-20T12:09:38.811Z DEBUG modem << [00:00:08.128,875] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:42.514Z DEBUG modem << [00:00:11.631,530] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:09:42.526Z DEBUG modem << [00:00:11.631,652] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:09:42.527Z DEBUG modem << [00:00:11.633,026] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:09:42.530Z DEBUG modem << [00:00:11.634,124] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:09:42.532Z DEBUG modem << 
2023-03-20T12:09:42.537Z DEBUG modem << [00:00:11.636,230] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:09:42.538Z DEBUG modem << 
2023-03-20T12:09:46.218Z DEBUG modem << [00:00:15.335,205] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:09:46.230Z DEBUG modem << [0m
2023-03-20T12:09:46.234Z DEBUG modem << [00:00:15.636,322] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:46.235Z DEBUG modem << [00:00:15.751,983] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:46.236Z DEBUG modem << [0m
2023-03-20T12:09:50.414Z DEBUG modem << [00:00:19.531,982] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:09:50.427Z DEBUG modem << [00:00:19.532,073] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:09:50.429Z DEBUG modem << [00:00:19.533,416] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:09:50.432Z DEBUG modem << [00:00:19.534,545] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:09:50.437Z DEBUG modem << [00:00:19.536,590] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:09:50.439Z DEBUG modem << 
2023-03-20T12:09:54.170Z DEBUG modem << [00:00:23.287,597] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:09:54.183Z DEBUG modem << [0m
2023-03-20T12:09:54.185Z DEBUG modem << [00:00:23.536,682] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:09:54.187Z DEBUG modem << [00:00:23.632,232] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:09:54.188Z DEBUG modem << [0m
2023-03-20T12:09:58.912Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:09:58.924Z DEBUG modem << 
2023-03-20T12:09:58.926Z DEBUG modem << [00:00:00.493,774] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:10:00.971Z DEBUG modem << [00:00:02.550,811] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:10:02.005Z DEBUG modem << [00:00:03.582,153] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:10:02.017Z DEBUG modem << [0m
2023-03-20T12:10:02.019Z DEBUG modem << [00:00:03.639,495] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:02.021Z DEBUG modem << [0m
2023-03-20T12:10:04.257Z DEBUG modem << [00:00:05.834,716] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:10:04.270Z DEBUG modem << [0m
2023-03-20T12:10:04.273Z DEBUG modem << [00:00:05.834,869] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:10:04.275Z DEBUG modem << [00:00:05.836,059] [0m<inf> aero_sens2: PSM parameter update: TAU: 6120, Active time: 60
2023-03-20T12:10:04.275Z DEBUG modem << [0m
2023-03-20T12:10:05.494Z DEBUG modem << [00:00:07.073,669] [0m<inf> aero_sens2: IPv4 Address found 18.192.60.140[0m
2023-03-20T12:10:05.509Z DEBUG modem << [00:00:07.073,699] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:10:05.510Z DEBUG modem << [00:00:07.073,730] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:08.938Z DEBUG modem << [00:00:10.519,409] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:10:08.957Z DEBUG modem << [00:00:10.519,500] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:10:08.958Z DEBUG modem << [00:00:10.520,874] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:10:08.960Z DEBUG modem << [00:00:10.521,972] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:10:08.962Z DEBUG modem << [00:00:10.524,108] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:10:12.943Z DEBUG modem << [00:00:14.524,200] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:12.966Z DEBUG modem << [00:00:15.320,159] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:10:12.968Z DEBUG modem << [0m
2023-03-20T12:10:12.969Z DEBUG modem << [00:00:15.505,889] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:12.970Z DEBUG modem << [0m
2023-03-20T12:10:19.712Z DEBUG modem << [00:00:21.293,121] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:10:19.730Z DEBUG modem << [00:00:21.293,212] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:10:19.731Z DEBUG modem << [00:00:21.294,525] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:10:19.733Z DEBUG modem << [00:00:21.295,623] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:10:19.748Z DEBUG modem << [00:00:21.297,668] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:10:23.676Z DEBUG modem << [00:00:25.257,324] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:10:23.692Z DEBUG modem << [0m
2023-03-20T12:10:23.694Z DEBUG modem << [00:00:25.297,760] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:23.695Z DEBUG modem << [00:00:25.356,170] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:23.696Z DEBUG modem << [0m
2023-03-20T12:10:28.610Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:10:28.627Z DEBUG modem << 
2023-03-20T12:10:28.629Z DEBUG modem << [00:00:00.493,957] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:10:30.670Z DEBUG modem << [00:00:02.550,994] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:10:31.685Z DEBUG modem << [00:00:03.564,056] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:10:31.700Z DEBUG modem << [0m
2023-03-20T12:10:31.702Z DEBUG modem << [00:00:03.617,553] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:31.703Z DEBUG modem << [0m
2023-03-20T12:10:33.945Z DEBUG modem << [00:00:05.824,737] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:10:33.962Z DEBUG modem << [0m
2023-03-20T12:10:33.967Z DEBUG modem << [00:00:05.824,890] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:10:33.969Z DEBUG modem << [00:00:05.826,080] [0m<inf> aero_sens2: PSM parameter update: TAU: 5760, Active time: 60
2023-03-20T12:10:33.970Z DEBUG modem << [0m
2023-03-20T12:10:33.975Z DEBUG modem << [00:00:05.978,424] [0m<inf> aero_sens2: IPv4 Address found 35.157.131.254[0m
2023-03-20T12:10:33.976Z DEBUG modem << [00:00:05.978,454] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:10:33.992Z DEBUG modem << [00:00:05.978,454] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:37.829Z DEBUG modem << [00:00:09.711,425] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:10:37.845Z DEBUG modem << 
2023-03-20T12:10:37.848Z DEBUG modem << [00:00:09.711,547] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:10:37.850Z DEBUG modem << [00:00:09.712,921] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:10:37.851Z DEBUG modem << [00:00:09.713,989] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:10:37.852Z DEBUG modem << [00:00:09.716,094] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:10:41.596Z DEBUG modem << [00:00:13.478,973] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:10:41.612Z DEBUG modem << [0m
2023-03-20T12:10:41.614Z DEBUG modem << [00:00:13.716,186] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:41.616Z DEBUG modem << [00:00:13.837,860] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:41.617Z DEBUG modem << [0m
2023-03-20T12:10:45.792Z DEBUG modem << [00:00:17.674,682] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:10:45.809Z DEBUG modem << 
2023-03-20T12:10:45.812Z DEBUG modem << [00:00:17.674,804] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:10:45.814Z DEBUG modem << [00:00:17.676,116] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:10:45.815Z DEBUG modem << [00:00:17.677,215] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:10:45.817Z DEBUG modem << [00:00:17.679,290] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:10:49.435Z DEBUG modem << [00:00:21.318,145] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:10:49.456Z DEBUG modem << [0m
2023-03-20T12:10:49.459Z DEBUG modem << [00:00:21.679,382] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:10:49.461Z DEBUG modem << [00:00:21.798,095] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:49.462Z DEBUG modem << [0m
2023-03-20T12:10:54.950Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:10:54.970Z DEBUG modem << [00:00:00.493,774] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:10:57.009Z DEBUG modem << [00:00:02.550,811] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:10:57.030Z DEBUG modem << 
2023-03-20T12:10:57.034Z DEBUG modem << [00:00:03.544,219] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:10:57.036Z DEBUG modem << [0m
2023-03-20T12:10:58.075Z DEBUG modem << [00:00:03.617,584] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:10:58.093Z DEBUG modem << [0m
2023-03-20T12:11:00.425Z DEBUG modem << [00:00:05.965,057] [0m<inf> aero_sens2: Network registration status: Connected - roaming
2023-03-20T12:11:00.445Z DEBUG modem << [0m
2023-03-20T12:11:00.448Z DEBUG modem << [00:00:05.965,209] [0m<inf> aero_sens2: Got semaphore[0m
2023-03-20T12:11:00.449Z DEBUG modem << [00:00:05.966,369] [0m<inf> aero_sens2: PSM parameter update: TAU: 5040, Active time: 60
2023-03-20T12:11:00.450Z DEBUG modem << [0m
2023-03-20T12:11:00.451Z DEBUG modem << [00:00:06.159,454] [0m<inf> aero_sens2: IPv4 Address found 3.127.15.183[0m
2023-03-20T12:11:00.453Z DEBUG modem << [00:00:06.159,484] [0m<inf> aero_sens2: TLS enabled[0m
2023-03-20T12:11:00.456Z DEBUG modem << [00:00:06.159,484] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:11:00.457Z DEBUG modem << 
2023-03-20T12:11:04.665Z DEBUG modem << [00:00:10.207,855] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:11:04.687Z DEBUG modem << [00:00:10.207,946] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:11:04.689Z DEBUG modem << [00:00:10.209,320] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:11:04.691Z DEBUG modem << [00:00:10.210,510] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:11:04.693Z DEBUG modem << [00:00:10.212,463] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:11:08.164Z DEBUG modem << [00:00:13.706,695] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:11:08.185Z DEBUG modem << [0m
2023-03-20T12:11:08.189Z DEBUG modem << [00:00:14.212,554] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:11:08.191Z DEBUG modem << [00:00:14.327,941] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:11:08.193Z DEBUG modem << [0m
2023-03-20T12:11:13.264Z DEBUG modem << [00:00:18.806,732] [0m<inf> aero_sens2: mqtt input![0m
2023-03-20T12:11:13.287Z DEBUG modem << [00:00:18.806,854] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-20T12:11:13.289Z DEBUG modem << [00:00:18.808,166] [0m<inf> aero_sens2: Publish![0m
2023-03-20T12:11:13.291Z DEBUG modem << [00:00:18.809,234] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-20T12:11:13.292Z DEBUG modem << [00:00:18.811,309] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-20T12:11:16.973Z DEBUG modem << [00:00:22.516,601] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-20T12:11:16.997Z DEBUG modem << [0m
2023-03-20T12:11:16.999Z DEBUG modem << [00:00:22.811,401] [0m<inf> aero_sens2: Connecting![0m
2023-03-20T12:11:17.001Z DEBUG modem << [00:00:22.928,192] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-20T12:11:17.002Z DEBUG modem << [0m
2023-03-20T12:11:21.933Z DEBUG modem << *** Booting Zephyr OS build v3.2.99-ncs2 ***
2023-03-20T12:11:21.955Z DEBUG modem << 
2023-03-20T12:11:21.959Z DEBUG modem << [00:00:00.493,927] [0m<inf> aero_sens2: Lets start[0m
2023-03-20T12:11:23.992Z DEBUG modem << [00:00:02.550,994] [0m<inf> aero_sens2: waiting for the semphore![0m
2023-03-20T12:11:24.021Z DEBUG modem << 
2023-03-20T12:11:24.027Z DEBUG modem << [00:00:03.518,035] [0m<inf> aero_sens2: LTE cell changed: Cell ID: 18298629, Tracking area: 303
2023-03-20T12:11:24.028Z DEBUG modem << [0m

main.c

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#include <zephyr/logging/log.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <zephyr/init.h>
#include <zephyr/pm/pm.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/policy.h>

#include <modem/lte_lc.h>
#include <modem/modem_info.h>
#include <nrf_modem_at.h>

#include <zephyr/net/socket.h>
#include <zephyr/net/mqtt.h>

#include "common_struct.h"
#include "json_lib.h"


#define SLEEP_TIME_MS   4*1000


static K_SEM_DEFINE(lte_connected, 0, 1);

LOG_MODULE_REGISTER(aero_sens2,LOG_LEVEL_DBG);

static void lte_handler(const struct lte_lc_evt *const evt);
static int broker_init(void);
void mqtt_evt_handler(struct mqtt_client *const c,
		      const struct mqtt_evt *vt);

// The mqtt client struct 
static struct mqtt_client client;

/* MQTT Broker details. */
static struct sockaddr_storage broker;

// File descriptor 
static struct pollfd fds;

// data and medata
static aero_sens_metadata_t data;


/* Buffers for MQTT client. */
static uint8_t rx_buffer[128];
static uint8_t tx_buffer[128];
static uint8_t payload_buf[128];


/* Prevent deep sleep (system off) from being entered on long timeouts
 * or `K_FOREVER` due to the default residency policy.
 *
 * This has to be done before anything tries to sleep, which means
 * before the threading system starts up between PRE_KERNEL_2 and
 * POST_KERNEL.  Do it at the start of PRE_KERNEL_2.
 */

static int disable_ds_1(const struct device *dev)
{
	ARG_UNUSED(dev);

	pm_policy_state_lock_get(PM_STATE_SOFT_OFF, PM_ALL_SUBSTATES);
	return 0;
}

SYS_INIT(disable_ds_1, PRE_KERNEL_2, 0);


static int json_add_obj(cJSON *parent, const char *str, cJSON *item)
{
	cJSON_AddItemToObject(parent, str, item);

	return 0;
}



static int json_add_number(cJSON *parent, const char *str, double item)
{
	cJSON *json_num;

	json_num = cJSON_CreateNumber(item);
	if (json_num == NULL) {
		return -ENOMEM;
	}

	return json_add_obj(parent, str, json_num);
}



void main(void)
{
	int err;
	struct mqtt_publish_param param;
	LOG_INF("Lets start");
	k_msleep(2000);


	err = lte_lc_init_and_connect_async(lte_handler);
	if (err) {
		LOG_ERR("Modem could not be configured, error: %d\n", err);
		return ;
	}

	err = modem_info_init();
	if (err) {
		LOG_ERR("Failed initializing modem info module, error: %d\n",
		err);
	}

	LOG_INF("waiting for the semphore!");
	k_sem_take(&lte_connected, K_FOREVER);
	LOG_INF("Got semaphore");
	cJSON_Init();

	mqtt_client_init(&client);

	/* Resolves the configured hostname and initializes the MQTT broker structure */
	err = broker_init();
	if (err) {
		LOG_ERR("Failed to initialize broker connection");
		k_msleep(25);
		err = broker_init();
		if (err) {
			LOG_ERR("Failed to initialize broker connection");
			return;
		}

	}

	/* MQTT client configuration */
	client.broker = &broker;
	client.evt_cb = mqtt_evt_handler;
	client.client_id.utf8 = "test-123";//client_id_get();
	client.client_id.size = 8;//strlen(client->client_id.utf8);
	client.password = NULL;
	client.user_name = NULL;
	client.protocol_version = MQTT_VERSION_3_1_1;

	/* MQTT buffers configuration */
	client.rx_buf = rx_buffer;
	client.rx_buf_size = sizeof(rx_buffer);
	client.tx_buf = tx_buffer;
	client.tx_buf_size = sizeof(tx_buffer);

	//get a pointer to the TLS configration 
	struct mqtt_sec_config *tls_cfg = &(client.transport).tls.config;
	static sec_tag_t sec_tag_list[] = { CONFIG_MQTT_TLS_SEC_TAG };

	LOG_INF("TLS enabled");
	client.transport.type = MQTT_TRANSPORT_SECURE;

	tls_cfg->peer_verify = CONFIG_MQTT_TLS_PEER_VERIFY; // verfiy required
	tls_cfg->cipher_list = NULL;
	tls_cfg->cipher_count = 0;
	tls_cfg->sec_tag_count = ARRAY_SIZE(sec_tag_list);
	tls_cfg->sec_tag_list = sec_tag_list;
	tls_cfg->hostname = CONFIG_MQTT_BROKER_HOSTNAME;

	tls_cfg->session_cache = TLS_SESSION_CACHE_DISABLED ;

	while (1) {
    LOG_INF("Connecting!");
    //k_msleep(1);
    err = mqtt_connect(&client);
		if (err) {
			LOG_INF("Error in mqtt_connect: %d", err);

		}

    fds.fd = client.transport.tls.sock;
    fds.events = POLLIN;
    
  	err = poll(&fds, 1, mqtt_keepalive_time_left(&client));
	  if (err < 0) {
		  LOG_INF("Error in poll(): %d", err);
		  return ;
	  }

    LOG_INF("mqtt input!");
    err = mqtt_input(&client);
		if (err != 0) {
			LOG_INF("Error in mqtt_input: %d", err);
			return ;
		}
	//char* message; = json_create(&data);
	{
		char* message;
		cJSON *reported_obj = cJSON_CreateObject();
		cJSON *bms_680 = cJSON_CreateObject();
		err += json_add_number(reported_obj, "pckt",  1);
		err += json_add_number(reported_obj, "bat",  data.bat_voltage);
		err += json_add_number(reported_obj, "rsrp",  data.rsrp);

		err += json_add_number(bms_680, "tmp_exp",  data.temp.val1);
		err += json_add_number(bms_680, "tmp_frc",  data.temp.val2);
		err += json_add_number(bms_680, "psr_exp", data.press.val1);
		err += json_add_number(bms_680, "hum_exp",  data.humidity.val1);
		err += json_add_number(bms_680, "gas_exp", data.gas_res.val1);
		err += json_add_number(bms_680, "alrm", 0);

		err += json_add_obj(reported_obj , "bms860", bms_680);

		if (err) {
			LOG_ERR("json_add, error: %d", err);
		}
		message = cJSON_Print(reported_obj);
		param.message.topic.qos = MQTT_QOS_1_AT_LEAST_ONCE;
		param.message.topic.topic.utf8 = "test/topic1";
		param.message.topic.topic.size = strlen("test/topic1");
		param.message.payload.data = (uint8_t*)message;
		param.message.payload.len = strlen(message);
		param.message_id = 12;
		param.dup_flag = 0;
		param.retain_flag = 0;
		LOG_INF("Publish!");
		mqtt_publish(&client, &param);
		cJSON_FreeString(message);

	}
    



    LOG_INF("Disconnecting MQTT!");
		err = mqtt_disconnect(&client);
		if (err) {
			LOG_ERR("Could not disconnect MQTT client: %d", err);
		}
    k_msleep(SLEEP_TIME_MS); 
	}
}


static void lte_handler(const struct lte_lc_evt *const evt)
{
     switch (evt->type) {

     case LTE_LC_EVT_NW_REG_STATUS:
        if ((evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_HOME) &&
            (evt->nw_reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)) {
            break;
        }
            LOG_INF("Network registration status: %s\n",
			    evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_HOME ?
			    "Connected - home network" : "Connected - roaming");
		//lte_connected=true;
		k_sem_give(&lte_connected);
        break;

    case LTE_LC_EVT_PSM_UPDATE:
		LOG_INF("PSM parameter update: TAU: %d, Active time: %d\n",
			evt->psm_cfg.tau, evt->psm_cfg.active_time);
		break;

 	case LTE_LC_EVT_EDRX_UPDATE: {
		char log_buf[60];
		ssize_t len;

		len = snprintf(log_buf, sizeof(log_buf),
			       "eDRX parameter update: eDRX: %f, PTW: %f",
			       evt->edrx_cfg.edrx, evt->edrx_cfg.ptw);
		if (len > 0) {
			printk("%s\n", log_buf);
		}
		break;
	}      

	case LTE_LC_EVT_RRC_UPDATE:
		 LOG_INF("RRC mode: %s\n", evt->rrc_mode == LTE_LC_RRC_MODE_CONNECTED ? "Connected" : "Idle");
		break;

	case LTE_LC_EVT_CELL_UPDATE:
		LOG_INF("LTE cell changed: Cell ID: %d, Tracking area: %d\n",
			evt->cell.id, evt->cell.tac);
		break;	

     default:
        break;
    }
}

/**@brief Resolves the configured hostname and
 * initializes the MQTT broker structure
 */
static int broker_init(void)
{
	int err;
	struct addrinfo *result;
	struct addrinfo *addr;
	struct addrinfo hints = {
		.ai_family = AF_INET,
		.ai_socktype = SOCK_STREAM
	};

	err = getaddrinfo(CONFIG_MQTT_BROKER_HOSTNAME, NULL, &hints, &result);
	if (err) {
		LOG_ERR("getaddrinfo failed: %d", err);
		return -ECHILD;
	}

	addr = result;

	/* Look for address of the broker. */
	while (addr != NULL) {
		/* IPv4 Address. */
		if (addr->ai_addrlen == sizeof(struct sockaddr_in)) {
			struct sockaddr_in *broker4 =
				((struct sockaddr_in *)&broker);
			char ipv4_addr[NET_IPV4_ADDR_LEN];

			broker4->sin_addr.s_addr =
				((struct sockaddr_in *)addr->ai_addr)
				->sin_addr.s_addr;
			broker4->sin_family = AF_INET;
			broker4->sin_port = htons(8883);

			inet_ntop(AF_INET, &broker4->sin_addr.s_addr,
				  ipv4_addr, sizeof(ipv4_addr));
			LOG_INF("IPv4 Address found %s", (char *)(ipv4_addr));

			break;
		} else {
			LOG_ERR("ai_addrlen = %u should be %u or %u",
				(unsigned int)addr->ai_addrlen,
				(unsigned int)sizeof(struct sockaddr_in),
				(unsigned int)sizeof(struct sockaddr_in6));
		}

		addr = addr->ai_next;
	}

	/* Free the address. */
	freeaddrinfo(result);

	return err;
}
static int get_received_payload(struct mqtt_client *c, size_t length)
{
	int ret;
	int err = 0;

	/* Return an error if the payload is larger than the payload buffer.
	 * Note: To allow new messages, we have to read the payload before returning.
	 */
	if (length > sizeof(payload_buf)) {
		err = -EMSGSIZE;
	}

	/* Truncate payload until it fits in the payload buffer. */
	while (length > sizeof(payload_buf)) {
		ret = mqtt_read_publish_payload_blocking(
				c, payload_buf, (length - sizeof(payload_buf)));
		if (ret == 0) {
			return -EIO;
		} else if (ret < 0) {
			return ret;
		}

		length -= ret;
	}

	ret = mqtt_readall_publish_payload(c, payload_buf, length);
	if (ret) {
		return ret;
	}

	return err;
}  
static void data_print(uint8_t *prefix, uint8_t *data, size_t len)
{
	char buf[len + 1];

	memcpy(buf, data, len);
	buf[len] = 0;
	LOG_INF("%s%s", (char *)prefix, (char *)buf);
}

void mqtt_evt_handler(struct mqtt_client *const c,
		      const struct mqtt_evt *evt)
{
	int err;

	switch (evt->type) {
	case MQTT_EVT_CONNACK:
		if (evt->result != 0) {
			LOG_ERR("MQTT connect failed: %d", evt->result);
			break;
		}

		LOG_INF("MQTT client connected");
		//subscribe(c);
		break;

	case MQTT_EVT_DISCONNECT:
		LOG_INF("MQTT client disconnected: %d", evt->result);
		break;

	case MQTT_EVT_PUBLISH:
	{
		const struct mqtt_publish_param *p = &evt->param.publish;
		//Print the length of the recived message 
		LOG_INF("MQTT PUBLISH result=%d len=%d",
			evt->result, p->message.payload.len);

		//json_release_mem();
		//Extract the data of the recived message 
		err = get_received_payload(c, p->message.payload.len);
		
		//Send acknowledgment to the broker on receiving QoS1 publish message 
		if (p->message.topic.qos == MQTT_QOS_1_AT_LEAST_ONCE) {
			const struct mqtt_puback_param ack = {
				.message_id = p->message_id
			};

			/* Send acknowledgment. */
			mqtt_publish_qos1_ack(c, &ack);
		}
		
		//On successful extraction of data 
		if (err >= 0) {
			data_print("Received: ", payload_buf, p->message.payload.len);
	
		// On failed extraction of data - Payload buffer is smaller than the recived data . Increase 
		} else if (err == -EMSGSIZE) {
			LOG_ERR("Received payload (%d bytes) is larger than the payload buffer "
				"size (%d bytes).",
				p->message.payload.len, sizeof(payload_buf));
		//On failed extraction of data - Failed to extract data, disconnect 
		} else {
			LOG_ERR("get_received_payload failed: %d", err);
			LOG_INF("Disconnecting MQTT client...");

			err = mqtt_disconnect(c);
			if (err) {
				LOG_ERR("Could not disconnect: %d", err);
			}
		}
	} break;

	case MQTT_EVT_PUBACK:
		if (evt->result != 0) {
			LOG_ERR("MQTT PUBACK error: %d", evt->result);
			break;
		}

		LOG_INF("PUBACK packet id: %u", evt->param.puback.message_id);
		break;

	case MQTT_EVT_SUBACK:
		if (evt->result != 0) {
			LOG_ERR("MQTT SUBACK error: %d", evt->result);
			break;
		}

		LOG_INF("SUBACK packet id: %u", evt->param.suback.message_id);
		break;

	case MQTT_EVT_PINGRESP:
		if (evt->result != 0) {
			LOG_ERR("MQTT PINGRESP error: %d", evt->result);
		}
		break;

	default:
		LOG_INF("Unhandled MQTT event type: %d", evt->type);
		break;
	}
}

Update: 

prj.conf:

# For logging
CONFIG_LOG=y

# NEWLIB C
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# Modem library
CONFIG_NRF_MODEM_LIB=y

# Modem information
CONFIG_MODEM_INFO=y

CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_CLIENT_ID_STATIC="aero_sens"
CONFIG_AWS_IOT_BROKER_HOST_NAME="example.endpoint.com"
CONFIG_AWS_IOT_SEC_TAG=201
CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_LAST_WILL=y
CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y

# MQTT - Maximum MQTT keepalive timeout specified by AWS IoT Core (in Sec)
CONFIG_MQTT_KEEPALIVE=1200  


# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# CJSON
CONFIG_CJSON_LIB=y

CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_THREAD_NAME=y

# CONFIG_PM=y
# CONFIG_PM_DEVICE=y

LTE Link Monitor 2:

2023-03-21T16:29:45.568Z INFO Using nrf-device-lib-js version: 0.5.0
2023-03-21T16:29:45.568Z INFO Using nrf-device-lib version: 0.13.11
2023-03-21T16:29:45.569Z INFO Using nrfjprog DLL version: 10.18.2
2023-03-21T16:29:45.569Z INFO Using JLink version: JLink_V7.80c
2023-03-21T16:29:45.671Z INFO Installed JLink version does not match the provided version (V7.66a)
2023-03-21T16:29:47.167Z INFO Modem port is opened
2023-03-21T16:29:47.176Z DEBUG modem >> AT+CFUN?
2023-03-21T16:31:32.863Z INFO Modem port is opened
2023-03-21T16:31:32.865Z DEBUG modem >> AT+CFUN?
2023-03-21T16:31:36.226Z DEBUG modem << [00:00:06.676,605] [0m<inf> aero_sens2: mqtt input![0m
2023-03-21T16:31:36.232Z DEBUG modem << [00:00:06.676,727] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-21T16:31:36.237Z DEBUG modem << [00:00:06.678,161] [0m<inf> aero_sens2: Publish![0m
2023-03-21T16:31:36.270Z DEBUG modem << [00:00:06.679,565] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-21T16:31:36.272Z DEBUG modem << [00:00:06.681,365] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-21T16:31:39.859Z DEBUG modem << [00:00:10.309,875] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-21T16:31:39.864Z DEBUG modem << [0m
2023-03-21T16:31:44.231Z DEBUG modem << [00:00:14.681,488] [0m<inf> aero_sens2: Connecting![0m
2023-03-21T16:31:44.236Z DEBUG modem << [00:00:14.775,817] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-21T16:31:44.238Z DEBUG modem << [0m
2023-03-21T16:31:47.899Z DEBUG modem << [00:00:18.349,945] [0m<inf> aero_sens2: mqtt input![0m
2023-03-21T16:31:47.905Z DEBUG modem << [00:00:18.350,067] [0m<inf> aero_sens2: MQTT client connected[0m
2023-03-21T16:31:47.910Z DEBUG modem << [00:00:18.351,470] [0m<inf> aero_sens2: Publish![0m
2023-03-21T16:31:47.916Z DEBUG modem << [00:00:18.352,874] [0m<inf> aero_sens2: Disconnecting MQTT![0m
2023-03-21T16:31:47.922Z DEBUG modem << [00:00:18.354,736] [0m<inf> aero_sens2: MQTT client disconnected: 0[0m
2023-03-21T16:31:51.491Z DEBUG modem << [00:00:21.942,687] [0m<inf> aero_sens2: RRC mode: Idle
2023-03-21T16:31:51.497Z DEBUG modem << [0m
2023-03-21T16:31:55.904Z DEBUG modem << [00:00:26.354,858] [0m<inf> aero_sens2: Connecting![0m
2023-03-21T16:31:55.910Z DEBUG modem << [00:00:26.456,146] [0m<inf> aero_sens2: RRC mode: Connected
2023-03-21T16:31:55.912Z DEBUG modem << [0m

Thanks for the help!

  • Hi,

    The reboot is probably because the application crashes.

    Could you add CONFIG_RESET_ON_FATAL_ERROR=n and CONFIG_THREAD_NAME=y to your prj.conf?

    That should give us more information about why the application crashes.

    Best regards,

    Didrik

  • Hi Didrik,

    I added the flags to prj.conf and added a new LTE link monitor result in the first post. Basically, there is now the prj.conf file and the lte link monitor 2 file. From the logs, it appears that the application just stops and waits after it sends the second time. After debugging the application, I found that it was stuck in a secure error handler. I tried tracing the call stack to see what the error could be, but I couldn't dig deeper because the "source is unknown". Below is a snippet of my ide and the call stack.

    snipped of the IDE:

    What could be the reason to execute the secure fault handler?

  • Could you add CONFIG_TFM_SECURE_UART_SHARE_INSTANCE=y to your prj.conf as well?

    That should let the secure fault handler output some information about the crash.

    J0sh1101 said:
    What could be the reason to execute the secure fault handler?

    The application trying to access something in secure memory is the most likely cause. The reason for this might be a stack or buffer overflow, or another form of pointer error.

  • I added CONFIG_TFM_SECURE_UART_SHARE_INSTANCE to prj.conf, but I did not notice any difference. After hovering over the CONFIG_TFM_SECURE_UART_SHARE_INSTANCE , I got this text:

    CONFIG_TFM_SECURE_UART_SHARE_INSTANCE was assigned the value y, but got the value n. Missing dependencies:
    TFM_SECURE_UART

    Should I add the CONFIG_TFM_SECURE_UART=y?

    In proj.conf I have the AWS_IOT flags in there, even though I don't use the aws_iot library. Is this ok? Could this produce the problem. When I try to remove them, I get an error message. (I have used the AWS IOT example  as a base).

    I have this flags:

     

    CONFIG_AWS_IOT=y
    CONFIG_AWS_IOT_CLIENT_ID_STATIC="aero_sens"
    CONFIG_AWS_IOT_BROKER_HOST_NAME="example.endpoint.com"
    CONFIG_AWS_IOT_SEC_TAG=201
    CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
    CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
    CONFIG_AWS_IOT_LAST_WILL=y
    CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
    CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y
  • Hello,

    I have cleaned up my code and updated prj.conf, but I still end up in the Secure Hard Fault Handler. Now, every time I try to connect to the cloud, using the mqtt_conect(), I am landing in the secure hard fault handler. I tried increasing the mqtt buffers, and also increased the heap and stack to 4 kB, but it didn't change anything. It's a bit annoying that I can't look back in the stack frame to see where the error is occurring.

    I noticed that the error occurs whenever there is a context switch in the arch_swap function. There is probably a backend in Zephyr that does all the work with sockets and that is where the exception is thrown.

    Are there any other options in zephyr or nordic where I can change something in the pry.conf file to get more logs or information? Or call a function to give me more info?

    Thanks for your time and help!

Related