<?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>MQTT - Cannot connect to broker when using username and PW</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15291/mqtt---cannot-connect-to-broker-when-using-username-and-pw</link><description>Hi, I use the following. 
 
 Raspberry Pi 3 (RPi3 with Raspbian Jessie 4.4) as a router, 
 
 RPi3 is connected to a Wi-Fi router to access the Internet by using the built-in Wi-Fi BLE BCM43438 chip. 
 
 
 IoT SDK 0.9 (nrf5_iot_sdk_3288530) 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Jul 2016 15:13:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15291/mqtt---cannot-connect-to-broker-when-using-username-and-pw" /><item><title>RE: MQTT - Cannot connect to broker when using username and PW</title><link>https://devzone.nordicsemi.com/thread/58408?ContentTypeID=1</link><pubDate>Fri, 29 Jul 2016 15:13:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b99cab09-13c5-4fad-b47d-a9d7ad87ff4a</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;My mistake. Thanks for pointing it out and it works as you mentioned.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MQTT - Cannot connect to broker when using username and PW</title><link>https://devzone.nordicsemi.com/thread/58407?ContentTypeID=1</link><pubDate>Wed, 27 Jul 2016 15:02:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb64a4cd-ff4e-47bc-a663-b381af80b0c4</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi, the problem is how you declare and define the &lt;code&gt;mqtt_utf8_t pw&lt;/code&gt; and &lt;code&gt;user&lt;/code&gt; variables, and also the strings within them. Remember that you pass the pointers to the &lt;code&gt;m_app_mqtt_client&lt;/code&gt; varable, so when the function returns they will no longer be valid. You should declare them as global variables at the top of &lt;strong&gt;main.c&lt;/strong&gt;. Something like this should work:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint8_t username[] = &amp;quot;test&amp;quot;;
static uint8_t password[] = &amp;quot;test&amp;quot;;
static mqtt_utf8_t pw;
static mqtt_utf8_t user;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then in &lt;code&gt;button_event_handler()&lt;/code&gt; you can assign the values:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pw.p_utf_str = password;
pw.utf_strlen = strlen(password);
user.p_utf_str = username;
user.utf_strlen = strlen(username);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And pass the pointers &lt;code&gt;m_app_mqtt_client&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;m_app_mqtt_client.p_password           = &amp;amp;pw;
m_app_mqtt_client.p_user_name          = &amp;amp;user;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PS. I also tried with Mosquitto and the Auth plugin, and I got it working by following the guide you linked to. Just remember to get the apostrophes right (&amp;#39;%s&amp;#39;) if you are copy/pasting the &lt;em&gt;/etc/mosquitto/mosquitto.conf&lt;/em&gt; example directly. I also had to do the fix described here: &lt;a href="https://github.com/jpmens/mosquitto-auth-plug/issues/33"&gt;github.com/.../33&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>