<?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 Serial</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55244/nrf9160-mqtt-serial</link><description>Hello All, 
 I am trying to publish the data gathered from UART using MQTT . So far I was able to get serial data in the inData buffer. I am not able to publish data automatically as soon as data is received on serial port. Can some one please help me</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 Dec 2019 09:50:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55244/nrf9160-mqtt-serial" /><item><title>RE: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/224644?ContentTypeID=1</link><pubDate>Tue, 10 Dec 2019 09:50:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e15a189a-a88e-4c39-a537-27e75cd7b319</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Let&amp;#39;s continue the discussion in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/55431/nrf-9160-serial-mqtt"&gt;this thread&lt;/a&gt;.&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: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/224342?ContentTypeID=1</link><pubDate>Mon, 09 Dec 2019 09:08:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fb77937-c5e8-43c6-ac9d-55d22da98403</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you check the return code from data_publish()?&lt;/p&gt;
[quote user="nordicuser91"]Still triggers after I get the published data[/quote]
&lt;p&gt;What is triggered, what is the behavior that you&amp;#39;re seeing?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/224254?ContentTypeID=1</link><pubDate>Fri, 06 Dec 2019 19:51:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2718b9e-9816-4b87-9e4b-7f91f301a696</guid><dc:creator>nordicuser91</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I made a global int variable monitor (as flag) and added it in the while loop of the main function.&lt;pre class="ui-code" data-mode="c_cpp"&gt;while (1) {


		err = poll(&amp;amp;fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
		if (err &amp;lt; 0) {
			printk(&amp;quot;ERROR: poll %d\n&amp;quot;, errno);
			break;
		}

		err = mqtt_live(&amp;amp;client);
		if (err != 0) {
			printk(&amp;quot;ERROR: mqtt_live %d\n&amp;quot;, err);
			break;
		}

		if ((fds.revents &amp;amp; POLLIN) == POLLIN) {
			err = mqtt_input(&amp;amp;client);
			if (err != 0) {
				printk(&amp;quot;ERROR: mqtt_input %d\n&amp;quot;, err);
				break;
			}
		}

		if ((fds.revents &amp;amp; POLLERR) == POLLERR) {
			printk(&amp;quot;POLLERR\n&amp;quot;);
			break;
		}

		if ((fds.revents &amp;amp; POLLNVAL) == POLLNVAL) {
			printk(&amp;quot;POLLNVAL\n&amp;quot;);
			break;
		}
                
                if(monitor == 1){
                data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE,
				inData, sizeof(inData));
                monitor = 0;
                } 
                
	}&lt;/pre&gt;I set the flag in the interrupt handler as shown here&lt;pre class="ui-code" data-mode="text"&gt;void uart_cb(struct device *x)
{
	uart_irq_update(x);
	int data_length = 0;

	if (uart_irq_rx_ready(x)) {
		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
		uart_buf[data_length] = 0;
	}

        if(i==19 || *uart_buf == &amp;#39;?&amp;#39;){ 
        inData[i] = &amp;#39;\0&amp;#39;;
        printk(&amp;quot;%s\n&amp;quot;,inData);
        i=0;
        monitor = 1; // flag
        }
        else{
        memcpy(&amp;amp;inData[i], uart_buf, 1); 
        i++;
        }
}&lt;/pre&gt; Still triggers after I get the published data. Don&amp;#39;t know what to do&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;NordicUser&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/224101?ContentTypeID=1</link><pubDate>Fri, 06 Dec 2019 09:24:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbee1d27-cbae-4d21-9fc2-1a39238d6ed0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You&amp;#39;re calling data_publish() directly from the interrupt, which will not work. Could you try to set a flag and handle it in the main thread instead?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/224030?ContentTypeID=1</link><pubDate>Thu, 05 Dec 2019 20:01:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64e70394-d018-4c85-80a4-cf3d93d7ff89</guid><dc:creator>nordicuser91</dc:creator><description>&lt;p&gt;Thanks for the reply &lt;span&gt;H&amp;aring;kon&lt;/span&gt;, The following is the code which I am using. &lt;pre class="ui-code" data-mode="c_cpp"&gt;void uart_cb(struct device *x)
{
	uart_irq_update(x);
	int data_length = 0;

	if (uart_irq_rx_ready(x)) {
		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
		uart_buf[data_length] = 0;
	}

        if(i==19 || *uart_buf == &amp;#39;?&amp;#39;){ 
        inData[i] = &amp;#39;\0&amp;#39;;
        printk(&amp;quot;%s\n&amp;quot;,inData); // loopback
        i=0;
        data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE,inData, sizeof(inData));
        }
        else{
        memcpy(&amp;amp;inData[i], uart_buf, 1); 
        i++;
        }
}&lt;/pre&gt;In the function uart_cb I make a string of 20 characters or a smaller string when UART sees &amp;quot;?&amp;quot;. I store this string in inData variable and add null terminator to make it a string. Then I add data_publish function to publish the data. This doesn&amp;#39;t seem to work. On the serial port, I get the loop back as mentioned in the code in comments but the publish function doesn&amp;#39;t work. In addition to that once I try to write on serial port, the serial port doesn&amp;#39;t responds back. Don&amp;#39;t know what to do. Could you please help me out with this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 MQTT Serial</title><link>https://devzone.nordicsemi.com/thread/223907?ContentTypeID=1</link><pubDate>Thu, 05 Dec 2019 12:59:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cffba683-0e9d-4623-a45a-53fbe977224d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]I am trying to publish the data gathered from UART using &lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/mqtt_simple/src/main.c"&gt;MQTT&lt;/a&gt;. So far I was able to get serial data in the inData buffer. I am not able to publish data automatically as soon as data is received on serial port. Can some one please help me out with the same. I would really appreciate it.[/quote]
&lt;p&gt;&amp;nbsp;How are you pushing the data from the uart to the mqtt module? Your uart_evt_handler will likely execute from an interrupt, which then needs to be scheduled to main priority before calling a mqtt_* prefixed function. I would recommend using a workqueue for such task:&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/reference/kernel/threads/workqueue.html?highlight=workqueue"&gt;https://docs.zephyrproject.org/latest/reference/kernel/threads/workqueue.html?highlight=workqueue#&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>