<?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>nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123324/nrf9160-mqtt-disconnects-after-some-time</link><description>Hello, 
 I am working with a thingy9160 to connect to an MQTT broker using TLS. 
 I have run into an issue where the MQTT connection is disconnected with error code #XMQTTEVT: 1,-128. 
 This sometimes happens within a few minutes and sometimes after hours</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 30 Sep 2025 12:02:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123324/nrf9160-mqtt-disconnects-after-some-time" /><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/550165?ContentTypeID=1</link><pubDate>Tue, 30 Sep 2025 12:02:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a885dab-f29d-4d0f-98f7-3a763fc03de5</guid><dc:creator>Hakon</dc:creator><description>[quote user="KR0731"]I will look at changing the line in the MQTT stack and let you know if that fixes things.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6835.Hive-MQTT-RRC-reconnect2.pcap"&gt;Hive MQTT RRC reconnect2.pcap&lt;/a&gt;[/quote]
&lt;p&gt;Yeah, I think that is your best option at this point.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549900?ContentTypeID=1</link><pubDate>Fri, 26 Sep 2025 12:18:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0acabf7d-856a-40b0-93c8-e28fca1b4255</guid><dc:creator>KR0731</dc:creator><description>&lt;p&gt;I tried two different networks with the same result. I also tried modifying the prj.conf for the SLM to set the keep alive time using&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MQTT_KEEPALIVE&lt;/span&gt;&lt;span&gt;=20&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;I still set the keep alive from the SLM&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;AT#XMQTTCFG command as well. It seems adding this to the project config has changed things and the device is able to keep the connection better, although the problem eventually does happen. See attached trace.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I will look at changing the line in the MQTT stack and let you know if that fixes things.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Hive-MQTT-RRC-reconnect2.pcap"&gt;devzone.nordicsemi.com/.../Hive-MQTT-RRC-reconnect2.pcap&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Thanks,&lt;/div&gt;
&lt;div&gt;Kevin&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549863?ContentTypeID=1</link><pubDate>Fri, 26 Sep 2025 07:39:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6299c53-0a95-48cc-a43c-8f47a19e7b0e</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Edit; Never mind, no trace needed.&lt;/p&gt;
&lt;p&gt;Can you try a different network, and see if the problem persists?&lt;/p&gt;
&lt;p&gt;It should also be possible to workaround the issue, but it requires a change in the Zephyr MQTT stack. If the keep-alive time requested from the server is multiplied by 2, a single dropped MQTT ping would not cause the connection to be dropped. The simplest way would be to do it here:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/28a66c4596248370f2e47b7ac8ec097ca6a0170f/subsys/net/lib/mqtt/mqtt_encoder.c#L765"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/28a66c4596248370f2e47b7ac8ec097ca6a0170f/subsys/net/lib/mqtt/mqtt_encoder.c#L765&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;For example:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;code style="white-space:pre;"&gt;&lt;span&gt;err_code = pack_uint16(client-&amp;gt;keepalive * 2, buf);&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;code style="white-space:pre;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Looking at the MQTT stack code, this should still keep the client keep-alive time the same.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;code style="white-space:pre;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In any case, it still makes sense to increase the session keep-alive time from 10 seconds.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;code style="white-space:pre;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549729?ContentTypeID=1</link><pubDate>Wed, 24 Sep 2025 20:17:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b968eb83-df29-47c5-9905-2d1a2ca4e3f6</guid><dc:creator>KR0731</dc:creator><description>&lt;p&gt;I have tried increasing the keep alive to 1 minute. It does seem to disconnect less, but still happens eventually.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549710?ContentTypeID=1</link><pubDate>Wed, 24 Sep 2025 14:51:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f711ea9-3b7a-4efa-9178-27025f86ea1b</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;You should try increasing the MQTT keep alive. The current value is 10 seconds, you can try to increase it to maybe a few minutes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549396?ContentTypeID=1</link><pubDate>Mon, 22 Sep 2025 09:22:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed9d1111-7a75-4159-bdc7-9afce66636ad</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Thanks, I will forward this to the modem team.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/549357?ContentTypeID=1</link><pubDate>Sat, 20 Sep 2025 01:11:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98c0a514-d08e-4423-be6c-6eb9a30a4f10</guid><dc:creator>KR0731</dc:creator><description>&lt;p&gt;Ok I was finally able to get the trace for this error. See file attached&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2025_2D00_09_2D00_20T01_2D00_00_2D00_47.060Z.mtrace"&gt;devzone.nordicsemi.com/.../trace_2D00_2025_2D00_09_2D00_20T01_2D00_00_2D00_47.060Z.mtrace&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/546971?ContentTypeID=1</link><pubDate>Wed, 27 Aug 2025 17:01:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:113be255-182b-46f3-8922-c6d576a7dcb9</guid><dc:creator>Hakon</dc:creator><description>[quote user="KR0731"]Is there a part of the trace you would like to see other than what is shown in the screen capture?[/quote]
&lt;p&gt;Yes, that&amp;#39;s why I&amp;#39;m asking for a .mtrace file. We use internal tools for analyzing what is going on in the modem firmware. Most of this information is not visible from a pcap file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/546506?ContentTypeID=1</link><pubDate>Fri, 22 Aug 2025 18:27:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ceeef26-5cff-49a8-8ca5-c3323fae7d4e</guid><dc:creator>KR0731</dc:creator><description>&lt;p&gt;I am still trying to collect this trace but am having trouble getting the trace to run long enough to capture the error. I did collect the trace file MQTT Error Capture. This showed most of the session except stopped just before the actual error. Any ideas why the trace keeps stopping? Can you gather any thing about the MQTT disconnect from the attached trace?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Kevin&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/MQTT-Error-Capture.mtrace"&gt;devzone.nordicsemi.com/.../MQTT-Error-Capture.mtrace&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/545226?ContentTypeID=1</link><pubDate>Mon, 11 Aug 2025 13:45:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:750fa055-978a-40c6-bd80-8645f3e630b8</guid><dc:creator>JONATHAN LL</dc:creator><description>&lt;p&gt;Nothing specific in mind, its just good to have the entire trace to see what is going on. bigger picture incase something is missed. But key thing is to get the error, if you get a run where it happens after a few minutes then its good to have as much as you can get.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Jonathan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/544846?ContentTypeID=1</link><pubDate>Wed, 06 Aug 2025 19:44:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de7b9da8-e40d-4b2e-9105-ab85684b9e16</guid><dc:creator>KR0731</dc:creator><description>&lt;p&gt;I am trying to get the modem trace to work again. The trace is currently stopping after a few seconds. Once I fix that I can upload the file.&lt;/p&gt;
&lt;p&gt;Is there a part of the trace you would like to see other than what is shown in the screen capture? Just so I can make sure I capture it.&lt;/p&gt;
&lt;p&gt;Thanks for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT Disconnects after some time</title><link>https://devzone.nordicsemi.com/thread/544300?ContentTypeID=1</link><pubDate>Fri, 01 Aug 2025 10:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cbc6010-dcbb-4e71-92cf-fc14df1379a6</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;can you upload the modem trace as a .bin or .mtrace file in this ticket?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>