<?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>Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/73886/issue-when-using-qos1-for-sending-data-through-mqtt</link><description>Hi Dev Team, 
 I am enhancing my Thingy91 application using the mqtt_simple sample and NCS v1.5.0. I am basically connecting to the MQTT broker, sending data and then disconnecting MQTT broker. 
 I am facing a peculiar issue when sending my data through</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Apr 2021 23:04:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/73886/issue-when-using-qos1-for-sending-data-through-mqtt" /><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304941?ContentTypeID=1</link><pubDate>Wed, 14 Apr 2021 23:04:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ebc5895-5df4-43de-96f5-9fc32a931f72</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Yes, the solution you offer works for now. I am able to get the data through QoS1.&lt;/p&gt;
&lt;p&gt;I will try to get this functionality in a separate thread. Thanks for the help on this &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304805?ContentTypeID=1</link><pubDate>Wed, 14 Apr 2021 12:15:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efb101e7-51b5-49a5-8f7e-cad347a0b7da</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi!&lt;br /&gt;&lt;br /&gt;The reason why you aren&amp;#39;t getting the MQTT_EVT_PUBACK messages is that you&amp;#39;re only checking incoming MQTT traffic using &lt;strong&gt;mqtt_run&lt;/strong&gt;. You probably can solve this by calling this function each time you have used&amp;nbsp;&lt;strong&gt;data_publish&lt;/strong&gt;, but ideally I would have the this kind of functionality in a separate thread.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304764?ContentTypeID=1</link><pubDate>Wed, 14 Apr 2021 10:18:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bef8fc6-dc10-4036-839c-0b9f1e2da5b4</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/73886/issue-when-using-qos1-for-sending-data-through-mqtt/304713#304713"]The issue likely stems from how the application currently releases the message data after it&amp;#39;s sent and then proceed with queuing up new messages.&amp;nbsp;[/quote]
&lt;p&gt;You are right. That is the exact reason.&lt;/p&gt;
&lt;p&gt;I tried to take a look at the example in this link :&amp;nbsp;&lt;a href="https://github.com/crfosse/ncs_projects/blob/779ccbf1a58bb2ecef45f2aa1e2c100698e0f034/cellular/mqtt_work/src/main.c"&gt;https://github.com/crfosse/ncs_projects/blob/779ccbf1a58bb2ecef45f2aa1e2c100698e0f034/cellular/mqtt_work/src/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I implemented the semaphores in the way its done but I noticed that I don&amp;#39;t receive the&amp;nbsp;&lt;span&gt;MQTT_EVT_PUBACK at all. Could you let me know what could be the issue with my code.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I expected that once I change my QoS in data_publish() function to QoS1, I should get the MQTT_EVT_PUCKACK automatically. But I dont get any PUBACK messages for some reason I do not understand.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304713?ContentTypeID=1</link><pubDate>Wed, 14 Apr 2021 07:34:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c2de768-cbba-4155-ab22-943aa622b5dc</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello again!&lt;br /&gt;&lt;br /&gt;Understood. As you may know QoS1 means that the message is required to arrive &amp;quot;at least once&amp;quot; and a transaction is not considered finished before MQTT_EVT_PUBACK is received. The sender retains the message during this time. The issue likely stems from how the application currently releases the message data after it&amp;#39;s sent and then proceed with queuing up new messages.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I suggest making sure that a MQTT_EVT_PUBACK event is received before transmitting the next message. This can be done by taking a semaphore after the message is sent, and giving it when the PUBACK is received. It could be a good idea that messages are sent successfully as well by&amp;nbsp;printing the return code from&amp;nbsp;&lt;strong&gt;data_publish&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304584?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 13:46:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c6cc18a-3589-4812-aa5b-509c3166fc51</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/73886/issue-when-using-qos1-for-sending-data-through-mqtt/304557#304557"]Could you please elaborate on the issue?&amp;nbsp;[/quote]
&lt;p&gt;Sure. If you see in the QoS0 log that I posted, the MQTT connects, sends the data and then disconnects. After that , the process of logging the data is started again. This is perfect as it should happen.&lt;/p&gt;
&lt;p&gt;But in the QoS1 log, the data sending stops in between. All the data is not sent and the program does nothing after that. It is just stuck as seen in the log. Normally, I hoped that it did the same functionality of sending the data and disconnecting the MQTT and then start logging data again as is happening with QoS0 log. But it gets stuck in the process of data sending.&lt;/p&gt;
[quote userid="68044" url="~/f/nordic-q-a/73886/issue-when-using-qos1-for-sending-data-through-mqtt/304557#304557"]In addition, when using QoS1, you should receive&amp;nbsp;MQTT_EVT_PUBACK for each message, but I can&amp;#39;t see any of those.[/quote]
&lt;p&gt;Do I receive this from my broker ? I am using&amp;nbsp;broker.hivemq.com (HIVE MQ) as my broker along with the MQTT.fx software. Do I need to do any configurations there ? I have set the QoS in the MQTT.fx to QoS1.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue when using QoS1 for sending data through MQTT</title><link>https://devzone.nordicsemi.com/thread/304557?ContentTypeID=1</link><pubDate>Tue, 13 Apr 2021 13:13:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e2c4eef-6480-4bcc-a74f-1382e6f9894a</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello, Adeel!&lt;br /&gt;&lt;br /&gt;The behavior you are describing is interesting. I will do some testing, but from what I can see in your logs it doesn&amp;#39;t hang anywhere. Could you please elaborate on the issue?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;In addition, when using QoS1, you should receive&amp;nbsp;MQTT_EVT_PUBACK for each message, but I can&amp;#39;t see any of those. Please make sure that the broker actually receives and responds properly to you MQTT messages. You can try to increase the message buffer as well using&lt;span&gt; CONFIG_MQTT_MESSAGE_BUFFER_SIZE.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>