<?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 sample problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48030/nrf9160-mqtt-sample-problem</link><description>Hello. I have problem with MQTT sample. I use NB-IoT network. 
 If I use public MQTT server without username and password, then MQTT sample ist works. But if I use MQTT server with username and password, then I have this response 
 
 
 Error 61 is for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jun 2019 12:34:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48030/nrf9160-mqtt-sample-problem" /><item><title>RE: nrf9160 MQTT sample problem</title><link>https://devzone.nordicsemi.com/thread/190779?ContentTypeID=1</link><pubDate>Tue, 04 Jun 2019 12:34:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0264032-bc98-4b43-a9e8-edd24d55f715</guid><dc:creator>MiroslavP</dc:creator><description>&lt;p&gt;It looks like an code optimization error.&amp;nbsp;I must to add a print NAME and PASS&amp;nbsp; to the console, and then it works. Thank you. Please close ticket.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void client_init(struct mqtt_client *client)
{
	mqtt_client_init(client);

	broker_init();

	/* MQTT client configuration */
	client-&amp;gt;broker = &amp;amp;broker;
	client-&amp;gt;evt_cb = mqtt_evt_handler;
	client-&amp;gt;client_id.utf8 = (u8_t *)CONFIG_MQTT_CLIENT_ID;
	client-&amp;gt;client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
	//client-&amp;gt;password = NULL;
	//client-&amp;gt;user_name = NULL;

        struct mqtt_utf8 pass,name;
        pass.size = (u32_t) strlen(&amp;quot;PASS&amp;quot;);
        pass.utf8 =(u8_t*)&amp;quot;PASS&amp;quot;;
        printk(&amp;quot;pass: %d,%s\n&amp;quot;,pass.size,pass.utf8);
        name.size = (u32_t) strlen(&amp;quot;NAME&amp;quot;);
        name.utf8 = (u8_t*)&amp;quot;NAME&amp;quot;;
        printk(&amp;quot;name: %d,%s\n&amp;quot;,name.size,name.utf8);

        client-&amp;gt;password = &amp;amp;pass;
        client-&amp;gt;user_name = &amp;amp;name;
	client-&amp;gt;protocol_version = MQTT_VERSION_3_1_1;

	/* MQTT buffers configuration */
	client-&amp;gt;rx_buf = rx_buffer;
	client-&amp;gt;rx_buf_size = sizeof(rx_buffer);
	client-&amp;gt;tx_buf = tx_buffer;
	client-&amp;gt;tx_buf_size = sizeof(tx_buffer);

	/* MQTT transport configuration */
	client-&amp;gt;transport.type = MQTT_TRANSPORT_NON_SECURE;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT sample problem</title><link>https://devzone.nordicsemi.com/thread/190486?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 11:39:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42ce18a4-88f6-4a53-ab13-30d8633119c7</guid><dc:creator>MiroslavP</dc:creator><description>&lt;p&gt;Bug is maybe on the line with HOSTNAME.&lt;/p&gt;
&lt;p&gt;If I use hostname&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CONFIG_MQTT_BROKER_HOSTNAME &amp;quot;iot.eclipse.org&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then on the console is output&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ERROR: getaddrinfo failed 22
ERROR: mqtt_connect -47
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And error 22 is for Invaid argument ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But if I use IP address on&amp;nbsp;the this format&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CONFIG_MQTT_BROKER_HOSTNAME &amp;quot;198.41.30.241&amp;quot;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then I have on the console this&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;***** Booting Zephyr OS v1.14.99-ncs1 *****
The MQTT simple sample started
LTE Link Connecting ...
LTE Link Connected!
IPv4 Address found 0xf11e29c6
Exception occurred in Secure State
***** HARD FAULT *****
  Fault escalation (see below)
***** BUS FAULT *****
  Precise data bus error
  BFAR Address: 0x50008120
***** Hardware exception *****
Current thread ID = 0x20020284
Faulting instruction address = 0x1b8c0
Fatal fault in ISR! Spinning...&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But why ? What I&amp;#39;m doing wrong ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT sample problem</title><link>https://devzone.nordicsemi.com/thread/190480?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 11:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11e1b277-e47e-4235-8a28-a70a2c75ce08</guid><dc:creator>MiroslavP</dc:creator><description>&lt;p&gt;Yes, I have question. He stopped working for me mqtt_siple example. I do not know why, but I&amp;#39;ve tried everything.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I only changed&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CONFIG_MQTT_BROKER_HOSTNAME &amp;quot;18.194.228.78&amp;quot;
#define CONFIG_MQTT_BROKER_PORT 1883
//#define CONFIG_LTE_NETWORK_MODE_LTE_M 1
#define CONFIG_LTE_NETWORK_MODE_NBIOT 1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And after rebuild and flashing, I have this output on the console&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1559560905489v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I do not know why.&amp;nbsp;I reverted from git all source code, and change only this 4 line on the file autoconf.h. AT_client example is working. But mqtt_simple have this output.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please what is bad ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT sample problem</title><link>https://devzone.nordicsemi.com/thread/190425?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 07:29:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61cab815-37b0-4030-8add-a9862f22a069</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Great to hear that you found the solution &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;Let me know if any other issues/questions should pop up.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&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 sample problem</title><link>https://devzone.nordicsemi.com/thread/190423?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 07:24:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a4a64b3-d7d3-40e9-b2b5-93d024365db5</guid><dc:creator>MiroslavP</dc:creator><description>&lt;p&gt;Yes this morning I found out. Well thank you.&lt;/p&gt;
&lt;p&gt;But password, and user_name is pointer to struct. I used this solution&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct mqtt_utf8 pass,name;

pass.size = strlen(&amp;quot;PASS&amp;quot;);
pass.utf8 = (u8_t*)&amp;quot;PASS&amp;quot;
name.size = strlen(&amp;quot;NAME&amp;quot;);
name.utf8 = (u8_t *)&amp;quot;NAME&amp;quot;;

client-&amp;gt;password = &amp;amp;pass;
client-&amp;gt;user_name = &amp;amp;name;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf9160 MQTT sample problem</title><link>https://devzone.nordicsemi.com/thread/190415?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 06:45:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6e7a695-c0ba-4e1a-90e5-9f64087d2b67</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;&amp;nbsp;&lt;/p&gt;
[quote user=""]Error 61 is for&amp;nbsp;Connection refused, right ?[/quote]
&lt;p&gt;For the inbuilt minimal libc in zephyr, that is correct (if you choose to use newlib-nano, errno.h will be different). Here from errno.h:&lt;/p&gt;
&lt;p&gt;#define ECONNREFUSED 61 /* Connection refused */&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the .password and .user_name, these are both of struct mqtt_utf8, so you&amp;#39;ll have to populate both the string and the size of the string:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;client-&amp;gt;password.utf8 = (u8_t*)MY_PWD;
client-&amp;gt;password.size = strlen(MY_PWD);
client-&amp;gt;user_name.utf8 = (u8_t*)USER;
client-&amp;gt;user_name.size = strlen(USER);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you check if this helps?&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 sample problem</title><link>https://devzone.nordicsemi.com/thread/190308?ContentTypeID=1</link><pubDate>Fri, 31 May 2019 13:45:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16edacf0-9034-4492-bd14-7f40c7fbbdca</guid><dc:creator>MiroslavP</dc:creator><description>&lt;p&gt;Sorry, here&amp;#39;s the complete log&lt;/p&gt;
&lt;p&gt;&lt;img style="font-family:inherit;" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1559310294930v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>