<?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>customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48100/customize-publish-function-in-mqtt-sample</link><description>Hi, I am currently testing the MQTT Communication with our IoT-Platform. 
 I am successfully connected to the broker and I am able to receive messages from the subscribed topic. 
 Now I want to publish my own messages and not just reply the received message</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Jun 2019 10:23:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48100/customize-publish-function-in-mqtt-sample" /><item><title>RE: customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/thread/192011?ContentTypeID=1</link><pubDate>Tue, 11 Jun 2019 10:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f025c4f-2fa2-44a9-9777-a33a7745479d</guid><dc:creator>mschweig</dc:creator><description>&lt;p&gt;Hi, thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/thread/191990?ContentTypeID=1</link><pubDate>Tue, 11 Jun 2019 09:30:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d188c2a-c960-404a-ae2e-dd5a885e9a06</guid><dc:creator>Linus</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;You are using sprintf() in the wrong way. It doesn&amp;#39;t return a string, but the number of characters used in the result. Here&amp;#39;s how you should use it:&lt;/p&gt;
&lt;pre&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;sprintf(buffer, &amp;quot;%u&amp;quot;, val);
data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, buffer, 1);&lt;/pre&gt;&lt;/pre&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Linus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/thread/191561?ContentTypeID=1</link><pubDate>Fri, 07 Jun 2019 09:04:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6873e6bf-8aad-4b1e-a3b1-87c8fb17f950</guid><dc:creator>mschweig</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;yes, ofc I can call this and it is being successfully published, but I would like to call it on a event, for example on button press. Or publish the current button state.&lt;br /&gt;&lt;br /&gt;In would have used&amp;nbsp;gpio_pin_read in while (1) and the use the data_publish function, but that does not work.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;while (1) {

                u32_t val = 0;
                gpio_pin_read(gpiob, PIN, &amp;amp;val);
                printk(&amp;quot;Button: %d\n&amp;quot;, val);

                char buffer[2];

                
                data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE,sprintf(buffer,&amp;quot;%u&amp;quot;,val), 1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also tried it without conversion to string.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Do you have a better solution how to solve that?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/thread/191545?ContentTypeID=1</link><pubDate>Fri, 07 Jun 2019 08:22:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55848986-510f-4925-bb28-21da2113fd60</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hey, can&amp;#39;t you just call &lt;pre class="ui-code" data-mode="c_cpp"&gt;data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, &amp;quot;200,myCustomTemperatureMeasurement,fahrenheit,75.2,F&amp;quot;, strlen(&amp;quot;200,myCustomTemperatureMeasurement,fahrenheit,75.2,F&amp;quot;));&lt;/pre&gt;?&lt;/p&gt;
&lt;p&gt;Just make sure you run it after subscribing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: customize publish function in mqtt sample</title><link>https://devzone.nordicsemi.com/thread/190577?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 14:52:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3797b57-53c9-4832-9ff6-68f9c255979c</guid><dc:creator>mschweig</dc:creator><description>&lt;p&gt;For example I want to publish that string which can be used with our IoT-Platform:&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;quot;200,myCustomTemperatureMeasurement,fahrenheit,75.2,F&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>