<?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>First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47965/first-and-second-transmission-fails-in-nrf9160</link><description>hardware: nRF9160 DK 0.8.2 firmware: 0.7.0-29.alpha 
 I want to send data every a few seconds through MQTT. It fails in the first and second Tx after MQTT client initiation, and succeeds after that. It releases error = -57. Why does it fails in the first</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 Apr 2020 08:53:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47965/first-and-second-transmission-fails-in-nrf9160" /><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/244624?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 08:53:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0686bff9-89d2-41f8-a3a0-5a278bc57444</guid><dc:creator>dtquang89</dc:creator><description>&lt;p&gt;This helps me. Thank you a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/191136?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 13:39:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e871952-284a-4207-9e12-5abd4fe46fbd</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;OK. I figured out. mqtt_connect does not deal with CONNACK so that you need to poll after&amp;nbsp;&lt;span&gt;mqtt_connect&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void main(void)
{
	int err;

	printk(&amp;quot;The MQTT simple sample started\n&amp;quot;);

	modem_configure();

	client_init(&amp;amp;client);

	err = mqtt_connect(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: mqtt_connect %d\n&amp;quot;, err);
		return;
	}

	err = fds_init(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: fds_init %d\n&amp;quot;, err);
		return;
	}

    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);
    }

    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);
            }
    }

    while(1){
            err = data_publish(&amp;amp;client, MQTT_QOS_0_AT_MOST_ONCE, &amp;quot;a&amp;quot;, strlen(&amp;quot;a&amp;quot;)); // This works out
            printk(&amp;quot;err=%d\n&amp;quot;, err);
            printk(&amp;quot;Send reset message\n&amp;quot;);
            k_sleep(2*1000);
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190986?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 08:04:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b0cdc9a-1a7c-46e1-91b4-5cf27a6d213f</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi again.&lt;/p&gt;
&lt;p&gt;It is working for me now, but I moved &lt;strong&gt;data_publish()&lt;/strong&gt; to the connection event in the event handler,&amp;nbsp;&lt;strong&gt;MQTT_EVT_CONNACK&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The issue was probably that you tried to publish data without being in the connection state.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/572x420/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-297ba51f7d3e44599714c4363deee6d4/pastedimage1559721844849v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190730?ContentTypeID=1</link><pubDate>Tue, 04 Jun 2019 10:48:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c34b3a09-b99a-4588-b723-65b59995a948</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;same here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;$ git branch
* (HEAD detached at v0.4.0)
  master&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you try the same program above with your nRF9160 DK board?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190686?ContentTypeID=1</link><pubDate>Tue, 04 Jun 2019 08:52:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62901344-83ab-4083-9676-ff6e20afb1e8</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi again.&lt;/p&gt;
&lt;p&gt;Can you check that you have the latest &lt;a href="https://www.nordicsemi.com/Products/Low-power-cellular-IoT/nRF9160/Download#infotabs"&gt;modem firmware&lt;/a&gt; installed?&lt;/p&gt;
&lt;p&gt;Can you also check that you are in the v0.4.0 branch?&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/808x101/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-297ba51f7d3e44599714c4363deee6d4/pastedimage1559638325973v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190570?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 14:38:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:436c6594-3557-4c49-a23a-72be942610cc</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;I&amp;nbsp;added data_publish function to&amp;nbsp;the original mqtt_simple program tested it. It doesn&amp;#39;t work.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;lt;main.c&amp;gt;
.
.

/**@brief Initialize the MQTT client structure
 */
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;
	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;
}
.
.
void main(void)
{
	int err;

	printk(&amp;quot;The MQTT simple sample started\n&amp;quot;);

	modem_configure();

	client_init(&amp;amp;client);

	err = mqtt_connect(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: mqtt_connect %d\n&amp;quot;, err);
		return;
	}

	err = fds_init(&amp;amp;client);
	if (err != 0) {
		printk(&amp;quot;ERROR: fds_init %d\n&amp;quot;, err);
		return;
	}

        err = data_publish(&amp;amp;client, MQTT_QOS_0_AT_MOST_ONCE, &amp;quot;a&amp;quot;, strlen(&amp;quot;a&amp;quot;)); // TODO ADD HERE. Does not work
        printk(&amp;quot;err=%d\n&amp;quot;, err);
        printk(&amp;quot;Send reset message\n&amp;quot;);

	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;
		}
	}

	printk(&amp;quot;Disconnecting MQTT client...\n&amp;quot;);

	err = mqtt_disconnect(&amp;amp;client);
	if (err) {
		printk(&amp;quot;Could not disconnect MQTT client. Error: %d\n&amp;quot;, err);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;prj.conf&amp;gt;
.
.
# Appliaction
#CONFIG_MQTT_PUB_TOPIC=&amp;quot;/my/publish/topic&amp;quot;
#CONFIG_MQTT_SUB_TOPIC=&amp;quot;/my/subscribe/topic&amp;quot;
#CONFIG_MQTT_CLIENT_ID=&amp;quot;my-client-id&amp;quot;
#CONFIG_MQTT_BROKER_HOSTNAME=&amp;quot;iot.eclipse.org&amp;quot;
#CONFIG_MQTT_BROKER_PORT=1883
.
.&lt;/pre&gt;&lt;/p&gt;
&lt;p&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 ������������UUUU
Publishing: a
to topic: my/publish/topic len: 16
err=-57
Send reset message
mqtt_input start
[mqtt_evt_handler:166] MQTT client connected!
Subscribing to: my/subscribe/topic len 18
mqtt_input end
mqtt_input start
[mqtt_evt_handler:216] SUBACK packet id: 1234
mqtt_input end
mqtt_input start
mqtt_input end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So this issue should not be related to a broker.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m confused....&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190551?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 13:59:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36e2cc0e-7a18-4fa7-81b9-e67d2485fcb0</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;Thank you for your reply!&lt;/p&gt;
&lt;p&gt;It&amp;#39;s hard to check all the params of mqtt_client as it has a lot of params.....&lt;/p&gt;
&lt;p&gt;I compared my code with the lates mqtt_simple code&lt;br /&gt;&lt;a href="https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/mqtt_simple"&gt;https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/mqtt_simple&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are two differences.&lt;br /&gt;1. Line 264&amp;nbsp;&lt;span&gt;inet_ntop is added in&amp;nbsp;&lt;/span&gt;the latest code.&lt;br /&gt;2. I&amp;nbsp;add password and username in my code. Also I change MQTT version to 3.1.0&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;lt;main.c&amp;gt;
.
.
#define MQTT_PASSWORD &amp;quot;password&amp;quot;
#define MQTT_USERNAME &amp;quot;username&amp;quot;
.
.
/**@brief Initialize the MQTT client structure
 */
static void client_init(struct mqtt_client *client)
{
	mqtt_client_init(client);

	broker_init();

        /* Add from here */
        static struct mqtt_utf8 password;
	static struct mqtt_utf8 user_name;

	password.utf8 = (u8_t *)MQTT_PASSWORD;
	password.size = strlen(MQTT_PASSWORD);
	user_name.utf8 = (u8_t *)MQTT_USERNAME;
	user_name.size = strlen(MQTT_USERNAME);
        /* to here */

	/* 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 = &amp;amp;password; // Add here
	client-&amp;gt;user_name = &amp;amp;user_name; // Add here
	client-&amp;gt;protocol_version = MQTT_VERSION_3_1_0; // originally 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;p&gt;Do you have any advice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: First and second transmission fails in nRF9160</title><link>https://devzone.nordicsemi.com/thread/190424?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 07:26:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ca6734e-2e8a-4402-bce6-f71bb9bd85c2</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Looking in the SDK from when you call &lt;strong&gt;data_publish(&amp;amp;client, MQTT_QOS_0_AT_MOST_ONCE, &amp;quot;a&amp;quot;, strlen(&amp;quot;a&amp;quot;));&lt;/strong&gt; I end up in the function &lt;strong&gt;verify_tx_state(client)&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;(in mqtt.c)&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/578x224/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-297ba51f7d3e44599714c4363deee6d4/pastedimage1559546689801v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;This returns &lt;strong&gt;-ENOTCONN&lt;/strong&gt; which is &lt;strong&gt;-57&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;So it seems that this is the error. What values and so on does &lt;strong&gt;&lt;/strong&gt;the &lt;strong&gt;client&lt;/strong&gt; struct have?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>