Not able to publish more than 22 MQTT messages in one shot mode with nRF9160

Hello,

I'm trying to make a one-shot MQTT publisher and I'm able to get 22 messages published but every time I try to publish the 23rd the code hangs in mqtt_transport_write in mqtt_transport.c

Here's relevant code.

Calling code (in a loop):

err = send_one_shot_mqtt_msg(MQTT_QOS_1_AT_LEAST_ONCE, nmea_strings[0], strlen(nmea_strings[0]), CONFIG_MQTT_PUB_TOPIC);
if (err != 0){
    printk("Error: send_one_shot_mqtt_msg: %u\n", err);
    return -1;
}

connect_count++;

printk("Connected count: %d\n", connect_count);

send_on_shot_mqtt_mdg:

int8_t send_one_shot_mqtt_msg(enum mqtt_qos qos, u8_t *data, size_t len, char *topic) 
{
	int err = 0;

	err = mqtt_connect(&client);
	if (err != 0) {
		printk("ERROR: mqtt_connect %d\n", err);
		return -1;
	}
	printk("after mqtt_connect\n");

	err = fds_init(&client);
	if (err != 0) {
		printk("ERROR: fds_init %d\n", err);
		return -1;
	}

	err = poll_and_check_rcv_data(K_SECONDS(10)); // Wait for CONNACK
	if (err != 0) {
		printk("ERROR: poll_and_check_rcv_data %d\n", err);
		return -1;
	}

	err = data_publish(&client, qos, data, len);
	if(err < 0){
		printk("fail sending reset message\n");
	}
	
	err = poll_and_check_rcv_data(K_SECONDS(5));
	if (err != 0) {
		printk("ERROR: poll_and_check_rcv_data %d\n", err);
		return -1;
	}

    err = unsubscribe();
	if (err) {
		printk("Could not unsubscribe MQTT client. Error: %d\n", err);
		return -1;
	}

	err = mqtt_disconnect(&client);
	if (err) {
		printk("Could not disconnect MQTT client. Error: %d\n", err);
		return -1;
	}

	return 0;
}

poll_and_check_rcv_data:

int8_t poll_and_check_rcv_data(u32_t interval_msec)
{
	int8_t err = poll(&fds, 1, interval_msec); // Check if any data comes through LTE-M. When it is waiting for an incoming data, it sleeps
	if (err < 0) {
		printk("ERROR: poll %d\n", errno);
		return -1;
	}

	/* Check if data is received through LTE-M */
	if ((fds.revents & POLLIN) == POLLIN) { // If get data
		err = mqtt_input(&client);
		if (err < 0) {
			printk("ERROR: poll %d\n", errno);
			return -1;
		}
	}
	if ((fds.revents & POLLERR) == POLLERR) {
		printk("POLLERR\n");
		return -1;
	}
	if ((fds.revents & POLLNVAL) == POLLNVAL) {
		printk("POLLNVAL\n");
		return -1;
	}

	return 0;
}

Is there something I'm missing here?

Related