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

nrf9160 mqtt keep alive longer than 30 minutes not working

sdk: 1.6

modem fw: 1.2.3

Hi,

Been trying to test mqtt every which way and not getting any success with mqtt keep alive longer than 30 minutes, the mqtt connection is only maintained when the keepalive is less than 30 minutes. Two problems are:

1. setting KEEPALIVE values 1800 or larger than that, the connection just gets dropped.

2. Cant figure out how to set 'will message'. What I currently have in the code I get, "mqtt_connect... -12". which is #define ENOMEM 12 /* Not enough space */.

Removing the will message solves the connection issue, but keepalive issue persists.

Regards

Noaman

6443.2021-09-17-proj.conf

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

menu "HTTP application update sample"

config DOWNLOAD_HOST
	string "Download host name"

config DOWNLOAD_FILE
	string "The file to download"

config APPLICATION_VERSION
	int "Application version"
	default 1

config USE_HTTPS
	bool
	prompt "Use HTTPS for download"

endmenu

menu "MQTT simple sample"
config MQTT_PUB_TOPIC
	string "MQTT publish topic"
	default "my/publish/topic"

config MQTT_SUB_TOPIC
	string "MQTT subscribe topic"
	default "my/subscribe/topic"

config MQTT_CLIENT_ID
	string "MQTT Client ID"
	help
	  Use a custom Client ID string. If not set, the client ID will be
	  generated based on IMEI number (for nRF9160 based targets) or
	  randomly (for other platforms).
	default "ltetest"

config MQTT_BROKER_HOSTNAME
	string "MQTT broker hostname"
	default "test.cloudmqtt.com"

config MQTT_BROKER_PORT
	int "MQTT broker port"
	default 16993

config MQTT_MESSAGE_BUFFER_SIZE
	int "MQTT message buffer size"
	default 1024

config MQTT_PAYLOAD_BUFFER_SIZE
	int "MQTT payload buffer size"
	default 1024

config BUTTON_EVENT_PUBLISH_MSG
	string "The message to publish on a button event"
	default "Hello from nRF91 MQTT Simple Sample"

config MQTT_KEEPALIVE
	int ""
	default 3600
	
config BUTTON_EVENT_BTN_NUM
	int "The button number"
	default 1

config MQTT_RECONNECT_DELAY_S
	int "Seconds to delay before attempting to reconnect to the broker."
	default 5

config LTE_CONNECT_RETRY_DELAY_S
	int "Seconds to delay before attempting to retry LTE connection."
	default 120

config MQTT_TLS_SEC_TAG
	int "TLS credentials security tag"
	default 24

config MQTT_TLS_SESSION_CACHING
	bool "Enable TLS session caching"

config MQTT_TLS_PEER_VERIFY
	int "Set peer verification level"
	default 0
	help
		Set to 0 for VERIFY_NONE, 1 for VERIFY_OPTIONAL, and 2 for
		VERIFY_REQUIRED.

endmenu

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu

module = MQTT_SIMPLE
module-str = MQTT Simple
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

#include "myMQTT.h"
#include "myLTE.h"
#include <net/mqtt.h>
#include <net/socket.h>
#include <random/rand32.h>
#include "global.h"
#include "myHTTPs.h"

#include <modem/at_cmd.h>
#include <modem/at_notif.h>
#include <power/reboot.h>

#include <logging/log.h>

char mqtt_client_id[17] = "ltet001122334455";
uint32_t msgIdCnt = 1000;
bool mqttInitialized = false;
bool mqttConnecting = false;


char CONFIG_MQTT_BROKER_HOSTNAME[50] = "custom.cloudmqtt.com"; //"tailor.cloudmqtt.com";
int CONFIG_MQTT_BROKER_PORT = 14339;
int CONFIG_MQTT_BROKER_PORT_SECURE = 8883; //24339;
char CONFIG_MQTT_USER[30] = "username";
char CONFIG_MQTT_PASSWORD[30] = "password"; 


/* Buffers for MQTT client. */
static uint8_t rx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
static uint8_t tx_buffer[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
static uint8_t payload_buf[CONFIG_MQTT_PAYLOAD_BUFFER_SIZE];

/* The mqtt client struct */
static struct mqtt_client client;

/* MQTT Broker details. */
static struct sockaddr_storage broker;

/* Connected flag */
static bool mqttIsConnected;

/* File descriptor */
static struct pollfd fds;

#define mqttWillMsg "nrf_lte_connection_terminate"
#define mqttWillTopic "lte/willTopic"

bool flag_is_mqtts_updated = false;

uint8_t mqttInitErrorCounter = 0;
uint8_t mqttConnectErrorCounter = 0;
uint8_t mqttPollErrorCounter = 0;
uint8_t mqttPublishErrorCounter = 0;

/**@brief Function to print strings without null-termination
 */
static void data_print(uint8_t *prefix, uint8_t *data, size_t len)
{
	char buf[len + 1];

	memcpy(buf, data, len);
	buf[len] = 0;
	if (DEBUG_PRINT_MQTT) printk("%s%s\n", prefix, buf);
}

/**@brief Function to publish data on the configured topic
 */
static int data_publish(struct mqtt_client *c, enum mqtt_qos qos,
	uint8_t *data, size_t len)
{
	struct mqtt_publish_param param;

	param.message.topic.qos = qos;
	param.message.topic.topic.utf8 = CONFIG_MQTT_PUB_TOPIC;
	param.message.topic.topic.size = strlen(CONFIG_MQTT_PUB_TOPIC);
	param.message.payload.data = data;
	param.message.payload.len = len;
	param.message_id = msgIdCnt++;//sys_rand32_get();
	param.dup_flag = 0;
	param.retain_flag = 0;

	if (DEBUG_PRINT_MQTT)
	{
		data_print("Publishing: ", data, len);
		// printk("to topic: %s len: %u\n", CONFIG_MQTT_PUB_TOPIC, (unsigned int)strlen(CONFIG_MQTT_PUB_TOPIC));
	}
	return mqtt_publish(c, &param);
}

/**@brief Function to subscribe to the configured topic
 */
static int subscribe(void)
{
 /*
	struct mqtt_topic subscribe_topic = {
		.topic = {
			.utf8 = CONFIG_MQTT_SUB_TOPIC,
			.size = strlen(CONFIG_MQTT_SUB_TOPIC)
		},
		.qos = MQTT_QOS_1_AT_LEAST_ONCE
	};

	const struct mqtt_subscription_list subscription_list = {
		.list = &subscribe_topic,
		.list_count = 1,
		.message_id = 1234
	};

	printk("Subscribing to: %s len %u\n", CONFIG_MQTT_SUB_TOPIC,
		(unsigned int)strlen(CONFIG_MQTT_SUB_TOPIC));

	return mqtt_subscribe(&client, &subscription_list);
        */
}

/**@brief Function to read the published payload.
 */
static int publish_get_payload(struct mqtt_client *c, size_t length)
{
	//uint8_t *buf = payload_buf;
	//uint8_t *end = buf + length;

	//if (length > sizeof(payload_buf)) {
	//	return -EMSGSIZE;
	//}

	//while (buf < end) {
	//	int ret = mqtt_read_publish_payload(c, buf, end - buf);

	//	if (ret < 0) {
	//		int err;

	//		if (ret != -EAGAIN) {
	//			return ret;
	//		}

	//		if (DEBUG_PRINT_MQTT) printk("mqtt_read_publish_payload: EAGAIN\n");

	//		err = poll(&fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
	//		if (err > 0 && (fds.revents & POLLIN) == POLLIN) {
	//			continue;
	//		} else {
	//			return -EIO;
	//		}
	//	}

	//	if (ret == 0) {
	//		return -EIO;
	//	}

	//	buf += ret;
	//}

	return 0;
}

/**@brief MQTT client event handler
 */
void mqtt_evt_handler(struct mqtt_client *const c,
		      const struct mqtt_evt *evt)
{
	int err;

	switch (evt->type) {
	case MQTT_EVT_CONNACK:
		if (evt->result != 0) {
			if (DEBUG_PRINT_MQTT) printk("MQTT connect failed: %d", evt->result);
			break;
		}

		if (DEBUG_PRINT_MQTT) printk("MQTT client connected");
		subscribe();
		break;

	case MQTT_EVT_DISCONNECT:
		if (DEBUG_PRINT_MQTT) printk("MQTT client disconnected: %d", evt->result);
		break;

	case MQTT_EVT_PUBLISH: {
		const struct mqtt_publish_param *p = &evt->param.publish;

		if (DEBUG_PRINT_MQTT) printk("MQTT PUBLISH result=%d len=%d",
			evt->result, p->message.payload.len);
		err = publish_get_payload(c, p->message.payload.len);

		if (p->message.topic.qos == MQTT_QOS_1_AT_LEAST_ONCE) {
			const struct mqtt_puback_param ack = {
				.message_id = p->message_id
			};

			/* Send acknowledgment. */
			mqtt_publish_qos1_ack(&client, &ack);
		}

		if (err >= 0) {
			data_print("Received: ", payload_buf,
				p->message.payload.len);
			/* Echo back received data */
			data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE,
				payload_buf, p->message.payload.len);
		} else {
			if (DEBUG_PRINT_MQTT) printk("publish_get_payload failed: %d", err);
			if (DEBUG_PRINT_MQTT) printk("Disconnecting MQTT client...");

			err = mqtt_disconnect(c);
			if (err) {
				if (DEBUG_PRINT_MQTT) printk("Could not disconnect: %d", err);
			}
		}
	} break;

	case MQTT_EVT_PUBACK:
		if (evt->result != 0) {
			if (DEBUG_PRINT_MQTT) printk("MQTT PUBACK error: %d", evt->result);
			break;
		}

		if (DEBUG_PRINT_MQTT) printk("PUBACK packet id: %u", evt->param.puback.message_id);
		break;

	case MQTT_EVT_SUBACK:
		if (evt->result != 0) {
			if (DEBUG_PRINT_MQTT) printk("MQTT SUBACK error: %d", evt->result);
			break;
		}

		if (DEBUG_PRINT_MQTT) printk("SUBACK packet id: %u", evt->param.suback.message_id);
		break;

	case MQTT_EVT_PINGRESP:
		if (evt->result != 0) {
			if (DEBUG_PRINT_MQTT) printk("MQTT PINGRESP error: %d", evt->result);
		}
		break;

	default:
		if (DEBUG_PRINT_MQTT) printk("Unhandled MQTT event type: %d", evt->type);
		break;
	}
}

/**@brief Resolves the configured hostname and
 * initializes the MQTT broker structure
 */
static int broker_init(void)
{
	int err;
	struct addrinfo *result;
	struct addrinfo *addr;
	struct addrinfo hints = {
		.ai_family = AF_INET,
		.ai_socktype = SOCK_STREAM
	};

	err = getaddrinfo(CONFIG_MQTT_BROKER_HOSTNAME, NULL, &hints, &result);
	if (err) {
		if (DEBUG_PRINT_MQTT) printk("getaddrinfo failed: %d", err);
		return -ECHILD;
	}

	addr = result;

	/* Look for address of the broker. */
	while (addr != NULL) {
		/* IPv4 Address. */
		if (addr->ai_addrlen == sizeof(struct sockaddr_in)) {
			struct sockaddr_in *broker4 =
				((struct sockaddr_in *)&broker);
			char ipv4_addr[NET_IPV4_ADDR_LEN];

			broker4->sin_addr.s_addr =
				((struct sockaddr_in *)addr->ai_addr)
				->sin_addr.s_addr;
			broker4->sin_family = AF_INET;
			broker4->sin_port = htons(CONFIG_MQTT_BROKER_PORT);

			inet_ntop(AF_INET, &broker4->sin_addr.s_addr,
				  ipv4_addr, sizeof(ipv4_addr));
			if (DEBUG_PRINT_MQTT) printk("IPv4 Address found %s", ipv4_addr);

			break;
		} else {
			if (DEBUG_PRINT_MQTT) printk("ai_addrlen = %u should be %u or %u",
				(unsigned int)addr->ai_addrlen,
				(unsigned int)sizeof(struct sockaddr_in),
				(unsigned int)sizeof(struct sockaddr_in6));
		}

		addr = addr->ai_next;
	}

	/* Free the address. */
	freeaddrinfo(result);

	return err;
}

#if defined(CONFIG_NRF_MODEM_LIB)
#define IMEI_LEN 15
#define CGSN_RESPONSE_LENGTH 19
#define CLIENT_ID_LEN sizeof("nrf-") + IMEI_LEN
#else
#define RANDOM_LEN 10
#define CLIENT_ID_LEN sizeof(CONFIG_BOARD) + 1 + RANDOM_LEN
#endif /* defined(CONFIG_NRF_MODEM_LIB) */

/* Function to get the client id */
static const uint8_t* client_id_get(void)
{
	static uint8_t client_id[MAX(sizeof(CONFIG_MQTT_CLIENT_ID),
				     CLIENT_ID_LEN)];

	if (strlen(CONFIG_MQTT_CLIENT_ID) > 0) {
		snprintf(client_id, sizeof(client_id), "%s",
			 CONFIG_MQTT_CLIENT_ID);
		goto exit;
	}

 #if defined(CONFIG_NRF_MODEM_LIB)
	char imei_buf[CGSN_RESPONSE_LENGTH + 1];
	int err;

	if (!IS_ENABLED(CONFIG_AT_CMD_SYS_INIT)) {
		err = at_cmd_init();
		if (err) {
			if (DEBUG_PRINT_MQTT) printk("at_cmd failed to initialize, error: %d", err);
			goto exit;
		}
	}

	err = at_cmd_write("AT+CGSN", imei_buf, sizeof(imei_buf), NULL);
	if (err) {
		if (DEBUG_PRINT_MQTT) printk("Failed to obtain IMEI, error: %d", err);
		goto exit;
	}

	imei_buf[IMEI_LEN] = '\0';

	snprintf(client_id, sizeof(client_id), "nrf-%.*s", IMEI_LEN, imei_buf);
 #else
	uint32_t id = sys_rand32_get();
	snprintf(client_id, sizeof(client_id), "%s-%010u", CONFIG_BOARD, id);
 #endif /* !defined(NRF_CLOUD_CLIENT_ID) */

 exit:
	if (DEBUG_PRINT_MQTT) printk("client_id = %s", client_id);

	return client_id;
}

/**@brief Initialize the MQTT client structure
 */
static int client_init(struct mqtt_client *client)
{
	int err;

	mqtt_client_init(client);

	err = broker_init();
	if (err) {
		if (DEBUG_PRINT_MQTT) printk("Failed to initialize broker connection");
		return err;
	}

	struct mqtt_utf8 mqtt_user;
	struct mqtt_utf8 mqtt_password;
        struct mqtt_utf8 myWillMsg; //mqtt_user;
        struct mqtt_topic myWillTopic;

    mqtt_user.utf8 = (uint8_t *)(CONFIG_MQTT_USER);
	mqtt_user.size = strlen(CONFIG_MQTT_USER);

	mqtt_password.utf8 = (uint8_t *)(CONFIG_MQTT_PASSWORD);
	mqtt_password.size = strlen(CONFIG_MQTT_PASSWORD);

	/* MQTT client configuration */
	client->broker = &broker;
	client->evt_cb = mqtt_evt_handler;
	client->client_id.utf8 = client_id_get();
	client->client_id.size = strlen(client->client_id.utf8);
	client->password = &mqtt_password;
	client->user_name = &mqtt_user;
	client->protocol_version = MQTT_VERSION_3_1_1;

	/* MQTT buffers configuration */
	client->rx_buf = rx_buffer;
	client->rx_buf_size = sizeof(rx_buffer);
	client->tx_buf = tx_buffer;
	client->tx_buf_size = sizeof(tx_buffer);    

        myWillTopic.topic.utf8 = (uint8_t *)mqttWillTopic;
	myWillTopic.topic.size = strlen(myWillTopic.topic.utf8);
        myWillTopic.qos = MQTT_QOS_1_AT_LEAST_ONCE;
	client->will_topic = &myWillTopic;

        myWillMsg.utf8 = (uint8_t *)mqttWillMsg;
	myWillMsg.size = strlen(myWillMsg.utf8);
	client->will_message = &myWillMsg;
//client->will_topic->topic.size = myWillTopic.size;



	/* MQTT transport configuration */
 #if defined(CONFIG_MQTT_LIB_TLS)
	struct mqtt_sec_config *tls_cfg = &(client->transport).tls.config;
	static sec_tag_t sec_tag_list[] = { CONFIG_MQTT_TLS_SEC_TAG };

	if (DEBUG_PRINT_MQTT) printk("TLS enabled");
	client->transport.type = MQTT_TRANSPORT_SECURE;

	tls_cfg->peer_verify = CONFIG_MQTT_TLS_PEER_VERIFY;
	tls_cfg->cipher_count = 0;
	tls_cfg->cipher_list = NULL;
	tls_cfg->sec_tag_count = ARRAY_SIZE(sec_tag_list);
	tls_cfg->sec_tag_list = sec_tag_list;
	tls_cfg->hostname = CONFIG_MQTT_BROKER_HOSTNAME;

 #if defined(CONFIG_NRF_MODEM_LIB)
	tls_cfg->session_cache = IS_ENABLED(CONFIG_MQTT_TLS_SESSION_CACHING) ?
					    TLS_SESSION_CACHE_ENABLED :
					    TLS_SESSION_CACHE_DISABLED;
 #else
	/* TLS session caching is not supported by the Zephyr network stack */
	tls_cfg->session_cache = TLS_SESSION_CACHE_DISABLED;

 #endif

 #else
	client->transport.type = MQTT_TRANSPORT_NON_SECURE;
 #endif

	return err;
}

/**@brief Initialize the file descriptor structure used by poll.
 */
static int fds_init(struct mqtt_client *c)
{
	if (c->transport.type == MQTT_TRANSPORT_NON_SECURE) {
		fds.fd = c->transport.tcp.sock;
	} else {
#if defined(CONFIG_MQTT_LIB_TLS)
		fds.fd = c->transport.tls.sock;
#else
		return -ENOTSUP;
#endif
	}

	fds.events = POLLIN;

	return 0;
}

void myMqttWorkHandler(struct k_work *work)
{
  	//char msg[100] = 
	printk("Now publishing mqtt data\n");
	int ret = data_publish(&client,
					MQTT_QOS_0_AT_MOST_ONCE,
					CONFIG_BUTTON_EVENT_PUBLISH_MSG,
					sizeof(CONFIG_BUTTON_EVENT_PUBLISH_MSG)-1);
	if (ret) {
		printk("Publish failed: %d\n", ret);
	}
	else
	{
		printk("mqtt sent successfully\n");
	}
}

void test5_mqttKeepAlive()
{
  int err = 0;
  uint32_t connect_attempt = 0;


	err = client_init(&client);
	if (err != 0) {
		if (DEBUG_PRINT_MQTT) printk("client_init: %d", err);
		return;
	}

 do_connect:
	if (connect_attempt++ > 0) {
		if (DEBUG_PRINT_MQTT) printk("Reconnecting in %d seconds...",
			CONFIG_MQTT_RECONNECT_DELAY_S);
		k_sleep(K_SECONDS(CONFIG_MQTT_RECONNECT_DELAY_S));
	}
	err = mqtt_connect(&client);
	if (err != 0) {
		if (DEBUG_PRINT_MQTT) printk("mqtt_connect %d", err);
		goto do_connect;
	}

	err = fds_init(&client);
	if (err != 0) {
		if (DEBUG_PRINT_MQTT) printk("fds_init: %d", err);
		return;
	}

	while (1) {
		err = poll(&fds, 1, mqtt_keepalive_time_left(&client));
		if (err < 0) {
			if (DEBUG_PRINT_MQTT) printk("poll: %d", errno);
			break;
		}

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

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

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

		if ((fds.revents & POLLNVAL) == POLLNVAL) {
			if (DEBUG_PRINT_MQTT) printk("POLLNVAL");
			break;
		}
	}

	if (DEBUG_PRINT_MQTT) printk("Disconnecting MQTT client...");

	err = mqtt_disconnect(&client);
	if (err) {
		if (DEBUG_PRINT_MQTT) printk("Could not disconnect MQTT client: %d", err);
	}
	goto do_connect;
}

Parents
  • Hi Oyvind,

    I had given up on this until I had to come back to it just recently.

    Please find attached the Uart output with debug enabled. I just cannot get the keep-alive period longer than 30 minutes to work. I have even test disabled PSM, using edrx, using PSM of 5 minutes etc. to try and keep the connectiion with LTE network active. I also checked with Bell and Rogers support they both informed me that they do not put any such limitation on keeping the connection open. Bell also confirm that their IP lease time should be more than 4 hours and longer so the 30 minutes time out does not work.

    I was just thinking about how gps also does a cold-start if fixes are requested more than 30 mintues apart. Is there anything in the modem fw that resets the connection, closes the socket or clears the memory?

    I am using mfw: 1.2.3 

    sdk 1.6

    Regards

    Noaman

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0x10000
    I: Jumping to the first image slot
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    Branch. LTE_65. 2021-06-08
    
    Initializing bsdlib
    [00:00:00.000,030] <dbg> net_core.net_init: (0x20017a58): Priority 90
    [00:00:00.000,030] <dbg> net_core.l3_init: (0x20017a58): Network L3 init done
    [00:00:00.000,030] <dbg> net_if.net_if_init: (0x20017a58): 
    [00:00:00.000,030] <dbg> net_if.init_iface: (0x20017a58): On iface 0x20014f5c
    [00:00:00.000,061] <dbg> net_if.net_if_post_init: (0x20017a58): 
    [00:00:00.000,061] <dbg> net_if.net_if_up: (0x20017a58): iface 0x20014f5c
    Provisioning certificate
    Disabling interrupt on Power ADC Pin
    Setting LTE INT GPIO 22 as Input
    Modem fw is: mfw_nrf9160_1.2.3
    
    gps turned off
    Setting up WDT
    wdt device bound
    watchdog set
    
    sensor handler
    ffff180a6c9cb66841abc401010019000000000000000000
    Not starting BLE Work. isMoving: 0
    Waiting for network.. 
    Trying to connect
    LTE cell changed: Cell ID: 141267985, Tracking area: 55012
    RRC mode: Connected
    Network registration status: Connected - home network
    PSM bits: 001
    PSM Interval: 00100
    PSM parameter update: TAU: -1, Active time: -1
    lte_lc_rai_req, error: -95
    Modem fw is: mfw_nrf9160_1.2.3
    
    reading ccid
    nrf9160 ccid: 89302690201009303499
    Network time not read
    SMS waiting...
    initialization done
    Mqtt Thread Started
    PSM Settings: +CPSMS: 1,,,"00100100","00000001"
    
    CEREG: +CEREG: 5,1,"D6E4","086B9411",7,,,"11100000","11100000"
    
    PSM parameter update: TAU: 14400, Active time: 2
    [00:00:06.941,162] <err> lte_lc: RAI not supported for LTE-M networks
    IPv4 Address found 34.227.176.196client_id = nrf-352656106019501TLS enabled[00:00:14.558,441] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015148): Created socket 1
    [00:00Now entering Mqtt While loop
    :15.852,294] <dbg> net_mqtt_enc.pack_uint8: (0x20015148): >> val:04 cur:0x20022310, end:0x20022705
    --- 6 messages dropped ---
    [00:00:15.852,325] <dbg> net_mqtt_enc.connect_request_encode: (0x20015148): Encoding Keep Alive Time 0e10.
    [00:00:15.852,325] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0e10 cur:0x20022312, end:0x20022705
    [00:00:15.852,325] <dbg> net_mqtt_enc: Encoding Client Id.
                                           6e 72 66 2d 33 35 32 36  35 36 31 30 36 30 31 39 |nrf-3526 56106019
                                           35 30 31                                         |501              
    [00:00:15.852,355] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:00000015 cur:0x20022314, end:0x20022705
    [00:00:15.852,355] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0013 cur:0x20022314, end:0x20022705
    [00:00:15.852,386] <dbg> net_mqtt_enc: Encoding Username.
                                           61 73 73 65 74 54 61 67                          |assetTag         
    [00:00:15.852,386] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:0000000a cur:0x20022329, end:0x20022705
    [00:00:15.852,386] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0008 cur:0x20022329, end:0x20022705
    [00:00:15.852,386] <dbg> net_mqtt_enc: Encoding Password.
                                           4c 54 45 54 61 67 40 21  31                      |LTETag@! 1       
    [00:00:15.852,416] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:0000000b cur:0x20022333, end:0x20022705
    [00:00:15.852,416] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0009 cur:0x20022333, end:0x20022705
    [00:00:15.852,416] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015148): << msg type:0x10 length:0x00000034
    [00:00:15.852,447] <dbg> net_mqtt_enc.packet_length_encode: (0x20015148): >> length:0x00000034 cur:(nil), end:(nil)
    [00:00:15.852,478] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015148): Fixed header length = 02
    [00:00:15.852,508] <dbg> net_mqtt_enc.pack_uint8: (0x20015148): >> val:10 cur:0x20022308, end:0x20022705
    [00:00:15.852,508] <dbg> net_mqtt_enc.packet_length_encode: (0x20015148): >> length:0x00000034 cur:0x20022309, end:0x20022705
    [00:00:15.853,240] <dbg> net_mqtt.client_connect: (0x20015148): Connect completed
    In MQTT poll loop - 16135
    Ping Sent - -11
    MQTT client connected
    [00:0Ping Sent from CONNACK: 0
    0:16.138,885] <dbg> net_mqtt.mqtt_input: (0x20015148): state:0x00000002
    [00:00:16.138,946] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f05, end:0x20021f07
    [00:00:16.138,977] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:20
    [00:00:16.138,977] <dbg> net_mqtt_dec.packet_length_decode: (0x20015148): length:0x00000002
    [00:00:16.139,038] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: Received MQTT_PKT_TYPE_CONNACK!
    [00:00:16.139,068] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f07, end:0x20021f09
    [00:00:16.139,068] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:01
    [00:00:16.139,068] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f08, end:0x20021f09
    [00:00:16.139,068] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:00
    [00:00:16.139,099] <dbg> net_mqtt_dec.connect_ack_decode: (0x20015148): [CID 0x2001829c]: session_present_flag: 1
    [00:00:16.139,099] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: return_code: 0
    [00:00:16.141,143] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport writing 2 bytes.
    [00:00:16.141,723] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport write complete.
    In MQTT poll loop - 16291
    Ping Sent - -11
    MQTT PINGRESP received
    [00:00:16.294,891] <dbg> net_mqtt.mqtt_input: (0x20015148): state:0x00000006
    [00:00:16.295,013] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f05, end:0x20021f07
    [00:00:16.295,013] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:d0
    [00:00:16.295,013] <dbg> net_mqtt_dec.packet_length_decode: (0x20015148): length:0x00000000
    [00:00:16.295,013] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: Received MQTT_PKT_TYPE_PINGRSP!
    RRC mode: Idle
    BLE WORK TIMER - 26959
    isMoving==false. Sending scheduled Idle event
    Event Start Timestamp - 26
    
    
    
    ble monitor timer
    came to myPollSemSendLTEData
    LTE Freq: 3800
    
    sent the MQTT data
    Event: time taken - 139
    Event Start Timestamp - 26
    Event: time taken - 9
    Event End Timestamp - 35
    [00:00:35.274,566] <dbg> net_mqtt.mqtt_publish: (0x20017a58): [CID 0x2001829c]:[State 0x06]: >> Topic size 0x00000005, Data size 0x0000018a
    [00:00:35.274,688] <dbg> net_mqtt_enc.pack_utf8_str: (0x20017a58): >> str_size:00000007 cur:0x2002230a, end:0x20022705
    [00:00:35.274,719] <dbg> net_mqtt_enc.pack_uint16: (0x20017a58): >> val:0005 cur:0x2002230a, end:0x20022705
    [00:00:35.274,719] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20017a58): << msg type:0x30 length:0x00000191
    [00:00:35.274,719] <dbg> net_mqtt_enc.packet_length_encode: (0x20017a58): >> length:0x00000191 cur:(nil), end:(nil)
    [00:00:35.274,749] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20017a58): Fixed header length = 03
    [00:00:35.274,749] <dbg> net_mqtt_enc.pack_uint8: (0x20017a58): >> val:30 cur:0x20022307, end:0x20022705
    [00:00:35.274,749] <dbg> net_mqtt_enc.packet_length_encode: (0x20017a58): >> length:0x00000191 cur:0x20022308, end:0x20022705
    [00:00:35.274,780] <dbg> net_mqtt.client_write_msg: (0x20017a58): [0x2001829c]: Transport writing message.
    [00:00:35.310,302] <dbg> net_mqtt.client_write_msg: (0x20017a58): [0x2001829c]: Transport write complete.
    [00:00:35.310,333] <dbg> net_mqtt.mqtt_publish: (0x20017a58): [CID 0x2001829c]:[State 0x06]: << result 0x00000000
    RRC mode: Connected
    RRC mode: Idle
    WDT Feed 
    WDT Feed 
    WDT Feed 
    WDT Feed 
    WDT Feed 
    WDT Feed 
    WDT Feed 
    RRC mode: Connected
    [01:00:01.492,767] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): li               0
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): vn               3
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): mode             4
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): stratum:         2
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): poll:            3
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): precision:       e8
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): root_delay:      7f030000
    [01:00:01.492,797] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): root_dispersion: 5a0a0000
    [01:00:01.492,828] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): ref_id:          14cb3ac2
    [01:00:01.492,828] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): ref_tm_s:        85f6f9e5
    [01:00:01.492,828] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): ref_tm_f:        4208e9ef
    [01:00:01.492,828] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): orig_tm_s:       918caa83
    [01:00:01.492,828] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): orig_tm_f:       0
    [01:00:01.492,858] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): rx_tm_s:         17fdf9e5
    [01:00:01.492,858] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): rx_tm_f:         d990b0c
    [01:00:01.492,858] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): tx_tm_s:         17fdf9e5
    [01:00:01.492,858] <dbg> net_sntp.sntp_pkt_dump: (0x20015718): tx_tm_f:         d7bb0f0c
    [01:00:01.492,889] <dbg> net_sock.z_impl_zsock_close: (0x20015718): close: ctx=0x20018bf8, fd=2
    RRC mode: Idle
    In MQTT poll loop - 3616141
    Ping Sent - -11
    In MQTT poll loop - 3635310
    Ping Sent - 0
    RRC mode: Connected
    [01:00:35.313,201] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport writing 2 bytes.
    [01:00:35.319,915] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport write complete.
    In MQTT poll loop - 3636369
    Ping Sent - -11
    MQTT client disconnected: -128
    mqtt_input: -128Disconnecting MQTT client...Could not disconnect MQTT client: -128Reconnecting in 1 seconds...[01:00:36.373,504] <dbg> net_mqtt.mqtt_input: (0x20015148): state:0x00000006
    [01:00:36.373,565] <dbg> net_mqtt_rx.mqtt_read_message_chunk: (0x20015148): [CID 0x2001829c]: Connection closed.
    [01:00:36.373,565] <dbg> net_mqtt_sock_tls.mqtt_client_tls_disconnect: (0x20015148): Closing socket 1
    [01:00:36.373,596] <dbg> net_sock.z_impl_zsock_close: (0x20015148): close: ctx=0x20018bf0, fd=1
    [01:00:37.386,474] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015148): Created socket 1
    [01:00:Now entering Mqtt While loop
    39.741,149] <dbg> net_mqtt_enc.pack_uint8: (0x20015148): >> val:04 cur:0x20022310, end:0x20022705
    --- 6 messages dropped ---
    [01:00:39.741,180] <dbg> net_mqtt_enc.connect_request_encode: (0x20015148): Encoding Keep Alive Time 0e10.
    [01:00:39.741,180] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0e10 cur:0x20022312, end:0x20022705
    [01:00:39.741,180] <dbg> net_mqtt_enc: Encoding Client Id.
                                           6e 72 66 2d 33 35 32 36  35 36 31 30 36 30 31 39 |nrf-3526 56106019
                                           35 30 31                                         |501              
    [01:00:39.741,210] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:00000015 cur:0x20022314, end:0x20022705
    [01:00:39.741,210] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0013 cur:0x20022314, end:0x20022705
    [01:00:39.741,241] <dbg> net_mqtt_enc: Encoding Username.
                                                                              
    [01:00:39.741,241] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:0000000a cur:0x20022329, end:0x20022705
    [01:00:39.741,241] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0008 cur:0x20022329, end:0x20022705
    [01:00:39.741,241] <dbg> net_mqtt_enc: Encoding Password.
                                                              |       
    [01:00:39.741,271] <dbg> net_mqtt_enc.pack_utf8_str: (0x20015148): >> str_size:0000000b cur:0x20022333, end:0x20022705
    [01:00:39.741,271] <dbg> net_mqtt_enc.pack_uint16: (0x20015148): >> val:0009 cur:0x20022333, end:0x20022705
    [01:00:39.741,271] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015148): << msg type:0x10 length:0x00000034
    [01:00:39.741,302] <dbg> net_mqtt_enc.packet_length_encode: (0x20015148): >> length:0x00000034 cur:(nil), end:(nil)
    [01:00:39.741,333] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015148): Fixed header length = 02
    [01:00:39.741,333] <dbg> net_mqtt_enc.pack_uint8: (0x20015148): >> val:10 cur:0x20022308, end:0x20022705
    [01:00:39.741,363] <dbg> net_mqtt_enc.packet_length_encode: (0x20015148): >> length:0x00000034 cur:0x20022309, end:0x20022705
    [01:00:39.742,187] <dbg> net_mqtt.client_connect: (0x20015148): Connect completed
    In MQTT poll loop - 3640014
    Ping Sent - -11
    MQTT client connected
    [01:00:Ping Sent from CONNACK: 0
    40.017,944] <dbg> net_mqtt.mqtt_input: (0x20015148): state:0x00000002
    [01:00:40.018,005] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f05, end:0x20021f07
    [01:00:40.018,005] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:20
    [01:00:40.018,035] <dbg> net_mqtt_dec.packet_length_decode: (0x20015148): length:0x00000002
    [01:00:40.018,096] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: Received MQTT_PKT_TYPE_CONNACK!
    [01:00:40.018,127] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f07, end:0x20021f09
    [01:00:40.018,127] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:01
    [01:00:40.018,127] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f08, end:0x20021f09
    [01:00:40.018,127] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:00
    [01:00:40.018,127] <dbg> net_mqtt_dec.connect_ack_decode: (0x20015148): [CID 0x2001829c]: session_present_flag: 1
    [01:00:40.018,157] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: return_code: 0
    [01:00:40.020,202] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport writing 2 bytes.
    [01:00:40.021,026] <dbg> net_mqtt.client_write: (0x20015148): [0x2001829c]: Transport write complete.
    In MQTT poll loop - 3640145
    Ping Sent - -11
    MQTT PINGRESP received
    [01:00:40.149,932] <dbg> net_mqtt.mqtt_input: (0x20015148): state:0x00000006
    [01:00:40.150,024] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): >> cur:0x20021f05, end:0x20021f07
    [01:00:40.150,024] <dbg> net_mqtt_dec.unpack_uint8: (0x20015148): << val:d0
    [01:00:40.150,024] <dbg> net_mqtt_dec.packet_length_decode: (0x20015148): length:0x00000000
    [01:00:40.150,054] <dbg> net_mqtt_rx.mqtt_handle_packet: (0x20015148): [CID 0x2001829c]: Received MQTT_PKT_TYPE_PINGRSP!
    RRC mode: Idle
    BLE WORK TIMER - 3835320
    isMoving==false. Sending scheduled Idle event
    Event Start Timestamp - 3835
    
    
    
    ble monitor timer
    came to myPollSemSendLTEData
    LTE Freq: 3800
    
    sent the MQTT data
    Event: time taken - 139
    Event Start Timestamp - 3835
    Event: time taken - 8
    Event End Timestamp - 3843
    [01:04:03.636,016] <dbg> net_mqtt.mqtt_publish: (0x20017a58): [CID 0x2001829c]:[State 0x06]: >> Topic size 0x00000005, Data size 0x0000018a
    [01:04:03.636,138] <dbg> net_mqtt_enc.pack_utf8_str: (0x20017a58): >> str_size:00000007 cur:0x2002230a, end:0x20022705
    [01:04:03.636,169] <dbg> net_mqtt_enc.pack_uint16: (0x20017a58): >> val:0005 cur:0x2002230a, end:0x20022705
    [01:04:03.636,169] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20017a58): << msg type:0x30 length:0x00000191
    [01:04:03.636,169] <dbg> net_mqtt_enc.packet_length_encode: (0x20017a58): >> length:0x00000191 cur:(nil), end:(nil)
    [01:04:03.636,199] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20017a58): Fixed header length = 03
    [01:04:03.636,199] <dbg> net_mqtt_enc.pack_uint8: (0x20017a58): >> val:30 cur:0x20022307, end:0x20022705
    [01:04:03.636,199] <dbg> net_mqtt_enc.packet_length_encode: (0x20017a58): >> length:0x00000191 cur:0x20022308, end:0x20022705
    [01:04:03.636,199] <dbg> net_mqtt.client_write_msg: (0x20017a58): [0x2001829c]: Transport writing message.
    [01:04:03.671,722] <dbg> net_mqtt.client_write_msg: (0x20017a58): [0x2001829c]: Transport write complete.
    [01:04:03.671,752] <dbg> net_mqtt.mqtt_publish: (0x20017a58): [CID 0x2001829c]:[State 0x06]: << result 0x00000000
    LTE cell changed: Cell ID: 141494803, Tracking area: 55012
    RRC mode: Connected
    WDT Feed 
    RRC mode: Idle
    LTE cell changed: Cell ID: 141267985, Tracking area: 55012
    WDT Feed 
    WDT Feed 
    WDT Feed 
    

  • Hello Noaman, 

    Please note that due to Easter Holiday, our tech support team is lower staffed than normal, and a delay in answers must be expected.




    First of all, from the logs you have provided I see the following

    PSM Settings: +CPSMS: 1,,,"00100100","00000001"
    
    CEREG: +CEREG: 5,1,"D6E4","086B9411",7,,,"11100000","11100000"

    Your network does not provide PSM, i.e. GPS would not work if not setting modem function to e.g. Flight Mode. 

    Stratosphere said:
    I just cannot get the keep-alive period longer than 30 minutes to work.

    Could you please explain what keepalive you are referring to, MQTT or the network? 


    The MQTT server you are connecting to, does this use TLS? Have you verified that the MQTT server does not disconnect device?

    We will need a modem trace for more information.

    Kind regards;
    Øyvind

  • Your network does not provide PSM, i.e. GPS would not work if not setting modem function to e.g. Flight Mode. 

    ...

    I tried many configurations both with and without PSM. This output i shared is where i disable PSM.

    Could you please explain what keepalive you are referring to, MQTT or the network? 

    As per the title of the ticket, I am referring to MQTT keepalive of more than 30 minutes.

    The MQTT server you are connecting to, does this use TLS? Have you verified that the MQTT server does not disconnect device?

    I have tried both with and without TLS, the result is no different. 
    I know my mqtt server does not disconnect because I have tried keepalive to the same server on ESP32 as well and desktop Mqtt client and they both keep the connection.

    Modem trace as well as other files are attached.

    mqtt - keepalive fail 30mins - trace and others.zip

  • Stratosphere said:
    I know my mqtt server does not disconnect because I have tried keepalive to the same server on ESP32 as well and desktop Mqtt client and they both keep the connection.

    Is the ESP32 connecting via cellular or WiFi? 

    mqtt keep alive longer than 30 minutes

    Can you provide some information for why you want to have 30 minutes keepalive? This for our developers to understand what you are trying to achieve. 

    Øyvind said:
    Please note that due to Easter Holiday, our tech support team is lower staffed than normal, and a delay in answers must be expected.
  • Hi Oyvind,

    I have attached the updated modem trace.

    once again: keepalive is 40 minutes

    mqtt publish freq: 40 min

    modem fw: 1.2.3

    ESP is connecting via Wifi. I have confirmed with Bell that connections of any sort are not being reset or terminated by them in 30 minutes. IP lease time is also in hours/days not in minutes.

    I do not want 30 minute keep alive. I want >12 hour keepalive. Our use-case for asset tracking requires 12 hours pings on idle and more frequent pings on motion. so we could be sending 5-10 pings on a daily basis for typical application. I do not want to establish a new connection every time as it adds up on power consumption as well as data requirements on reconnection especially on TLS. TLS session caching does reduce data consumption and connection time but it is still more than what a keepalive duration of 12 hours would allow us to acheive.

    trace-2022-04-19T03-16-06.348Z.bin

    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Flash regions		Domain		Permissions
    00 02 0x00000 0x18000 	Secure		rwxl
    03 31 0x18000 0x100000 	Non-Secure	rwxl
    
    Non-secure callable region 0 placed in flash region 2 with size 32.
    
    SRAM region		Domain		Permissions
    00 03 0x00000 0x08000 	Secure		rwxl
    04 31 0x08000 0x40000 	Non-Secure	rwxl
    
    Peripheral		Domain		Status
    00 NRF_P0               Non-Secure	OK
    01 NRF_CLOCK            Non-Secure	OK
    02 NRF_RTC0             Non-Secure	OK
    03 NRF_RTC1             Non-Secure	OK
    04 NRF_NVMC             Non-Secure	OK
    05 NRF_UARTE1           Non-Secure	OK
    06 NRF_UARTE2           Secure		SKIP
    07 NRF_TWIM2            Non-Secure	OK
    08 NRF_SPIM3            Non-Secure	OK
    09 NRF_TIMER0           Non-Secure	OK
    10 NRF_TIMER1           Non-Secure	OK
    11 NRF_TIMER2           Non-Secure	OK
    12 NRF_SAADC            Non-Secure	OK
    13 NRF_PWM0             Non-Secure	OK
    14 NRF_PWM1             Non-Secure	OK
    15 NRF_PWM2             Non-Secure	OK
    16 NRF_PWM3             Non-Secure	OK
    17 NRF_WDT              Non-Secure	OK
    18 NRF_IPC              Non-Secure	OK
    19 NRF_VMC              Non-Secure	OK
    20 NRF_FPU              Non-Secure	OK
    21 NRF_EGU0             Non-Secure	OK
    22 NRF_EGU1             Non-Secure	OK
    23 NRF_EGU2             Non-Secure	OK
    24 NRF_EGU3             Non-Secure	OK
    25 NRF_EGU4             Non-Secure	OK
    26 NRF_EGU5             Non-Secure	OK
    27 NRF_DPPIC            Non-Secure	OK
    28 NRF_REGULATORS       Non-Secure	OK
    29 NRF_PDM              Non-Secure	OK
    30 NRF_I2S              Non-Secure	OK
    31 NRF_GPIOTE1          Non-Secure	OK
    
    SPM: NS image at 0x18200
    SPM: NS MSP at 0x20014368
    SPM: NS reset vector at 0x1bb11
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    [00:00:00.231,018] <inf> mqtt_simple: The MQTT simple sample started
    [00:00:00.231,048] <inf> mqtt_simple: Disabling PSM and eDRX
    [00:00:00.231,781] <inf> mqtt_simple: LTE Link Connecting...
    [00:00:04.703,369] <inf> mqtt_simple: LTE Link Connected!
    [00:00:04.894,226] <inf> mqtt_simple: IPv4 Address found 34.227.176.196
    [00:00:04.897,033] <dbg> mqtt_simple.client_id_get: client_id = nrf-352656101085366
    [00:00:05.352,478] <inf> mqtt_simple: MQTT client connected
    In Timer Callback - time: 24897
    [00:00:24.900,238] <inf> mqtt_simple: Publishing: {"channel":"lte","topic":"location","data":"f~
    [00:00:24.900,268] <inf> mqtt_simple: Time: 24900 - to topic: feed/ len: 5
    POLLHUP
    [00:40:25.240,753] <inf> mqtt_simple: Disconnecting MQTT client...
    [00:40:25.240,997] <inf> mqtt_simple: MQTT client disconnected: -104
    [00:40:25.241,027] <err> mqtt_simple: Could not disconnect MQTT client: -104
    [00:40:25.241,027] <inf> mqtt_simple: Reconnecting in 60 seconds...
    [00:41:25.792,602] <inf> mqtt_simple: MQTT client connected
    In Timer Callback - time: 2724897
    [00:45:24.900,390] <inf> mqtt_simple: Publishing: {"channel":"lte","topic":"location","data":"f~
    [00:45:24.900,421] <inf> mqtt_simple: Time: 2724900 - to topic: feed/ len: 5
    

Reply
  • Hi Oyvind,

    I have attached the updated modem trace.

    once again: keepalive is 40 minutes

    mqtt publish freq: 40 min

    modem fw: 1.2.3

    ESP is connecting via Wifi. I have confirmed with Bell that connections of any sort are not being reset or terminated by them in 30 minutes. IP lease time is also in hours/days not in minutes.

    I do not want 30 minute keep alive. I want >12 hour keepalive. Our use-case for asset tracking requires 12 hours pings on idle and more frequent pings on motion. so we could be sending 5-10 pings on a daily basis for typical application. I do not want to establish a new connection every time as it adds up on power consumption as well as data requirements on reconnection especially on TLS. TLS session caching does reduce data consumption and connection time but it is still more than what a keepalive duration of 12 hours would allow us to acheive.

    trace-2022-04-19T03-16-06.348Z.bin

    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Flash regions		Domain		Permissions
    00 02 0x00000 0x18000 	Secure		rwxl
    03 31 0x18000 0x100000 	Non-Secure	rwxl
    
    Non-secure callable region 0 placed in flash region 2 with size 32.
    
    SRAM region		Domain		Permissions
    00 03 0x00000 0x08000 	Secure		rwxl
    04 31 0x08000 0x40000 	Non-Secure	rwxl
    
    Peripheral		Domain		Status
    00 NRF_P0               Non-Secure	OK
    01 NRF_CLOCK            Non-Secure	OK
    02 NRF_RTC0             Non-Secure	OK
    03 NRF_RTC1             Non-Secure	OK
    04 NRF_NVMC             Non-Secure	OK
    05 NRF_UARTE1           Non-Secure	OK
    06 NRF_UARTE2           Secure		SKIP
    07 NRF_TWIM2            Non-Secure	OK
    08 NRF_SPIM3            Non-Secure	OK
    09 NRF_TIMER0           Non-Secure	OK
    10 NRF_TIMER1           Non-Secure	OK
    11 NRF_TIMER2           Non-Secure	OK
    12 NRF_SAADC            Non-Secure	OK
    13 NRF_PWM0             Non-Secure	OK
    14 NRF_PWM1             Non-Secure	OK
    15 NRF_PWM2             Non-Secure	OK
    16 NRF_PWM3             Non-Secure	OK
    17 NRF_WDT              Non-Secure	OK
    18 NRF_IPC              Non-Secure	OK
    19 NRF_VMC              Non-Secure	OK
    20 NRF_FPU              Non-Secure	OK
    21 NRF_EGU0             Non-Secure	OK
    22 NRF_EGU1             Non-Secure	OK
    23 NRF_EGU2             Non-Secure	OK
    24 NRF_EGU3             Non-Secure	OK
    25 NRF_EGU4             Non-Secure	OK
    26 NRF_EGU5             Non-Secure	OK
    27 NRF_DPPIC            Non-Secure	OK
    28 NRF_REGULATORS       Non-Secure	OK
    29 NRF_PDM              Non-Secure	OK
    30 NRF_I2S              Non-Secure	OK
    31 NRF_GPIOTE1          Non-Secure	OK
    
    SPM: NS image at 0x18200
    SPM: NS MSP at 0x20014368
    SPM: NS reset vector at 0x1bb11
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    [00:00:00.231,018] <inf> mqtt_simple: The MQTT simple sample started
    [00:00:00.231,048] <inf> mqtt_simple: Disabling PSM and eDRX
    [00:00:00.231,781] <inf> mqtt_simple: LTE Link Connecting...
    [00:00:04.703,369] <inf> mqtt_simple: LTE Link Connected!
    [00:00:04.894,226] <inf> mqtt_simple: IPv4 Address found 34.227.176.196
    [00:00:04.897,033] <dbg> mqtt_simple.client_id_get: client_id = nrf-352656101085366
    [00:00:05.352,478] <inf> mqtt_simple: MQTT client connected
    In Timer Callback - time: 24897
    [00:00:24.900,238] <inf> mqtt_simple: Publishing: {"channel":"lte","topic":"location","data":"f~
    [00:00:24.900,268] <inf> mqtt_simple: Time: 24900 - to topic: feed/ len: 5
    POLLHUP
    [00:40:25.240,753] <inf> mqtt_simple: Disconnecting MQTT client...
    [00:40:25.240,997] <inf> mqtt_simple: MQTT client disconnected: -104
    [00:40:25.241,027] <err> mqtt_simple: Could not disconnect MQTT client: -104
    [00:40:25.241,027] <inf> mqtt_simple: Reconnecting in 60 seconds...
    [00:41:25.792,602] <inf> mqtt_simple: MQTT client connected
    In Timer Callback - time: 2724897
    [00:45:24.900,390] <inf> mqtt_simple: Publishing: {"channel":"lte","topic":"location","data":"f~
    [00:45:24.900,421] <inf> mqtt_simple: Time: 2724900 - to topic: feed/ len: 5
    

Children
Related