This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Multiple MQTT pub at QoS 0

Hi,

I'm trying to send multiple messages to a MQTT server at QoS 0, but the client gets disconnected after +8 messages. I'm able to send more then 8 if I add a delay of 1000 ms between each message, but it disconnects at +32 messages.

What would it be the correct way to implement this? The goal is to potentially send +1000 messages to the server.

I'm using SDK 0.4.0 and mfw_nrf9160_0.7.0-29.alpha. I'm connection to Telia Denmark NB-Iot. I'm testing with the Nordic sample code at SDK v0.4.0:

https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/mqtt_simple

Here is the dump from the terminal:

The MQTT simple sample started
LTE Link Connecting ...
LTE Link Connected!
IPv4 Address found 0xf11e29c6
[mqtt_evt_handler:166] MQTT client connected!
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
Publishing: test
to topic: my/publish/topic len: 16
[mqtt_evt_handler:177] MQTT client disconnected -45
POLLNVAL
Disconnecting MQTT client...
Could not disconnect MQTT client. Error: -57

Here is my while(1) from main.h

while (1) {
		err = poll(&fds, 1, 10/*K_SECONDS(CONFIG_MQTT_KEEPALIVE)*/);
		if (err < 0) {
			printk("ERROR: poll %d\n", errno);
			break;
		}

		err = mqtt_live(&client);
		if (err != 0) {
			printk("ERROR: mqtt_live %d\n", err);
			break;
		}

		if ((fds.revents & POLLIN) == POLLIN) {
			err = mqtt_input(&client);
			if (err != 0) {
				printk("ERROR: mqtt_input %d\n", err);
				break;
			}
		}

		if ((fds.revents & POLLERR) == POLLERR) {
			printk("POLLERR\n");
			break;
		}

		if ((fds.revents & POLLNVAL) == POLLNVAL) {
			printk("POLLNVAL\n");
			break;
		}
		
        if(connected){
            if((k_uptime_get_32() - client.internal.last_activity) >= 1000)
                data_publish(&client, MQTT_QOS_0_AT_MOST_ONCE, "test", strlen("test"));
        }
	}

Parents Reply Children
No Data
Related