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

MQTTS connection speed that does not require any certificate is very slow.

I verify the TLS connection without a certificate in the matt_samples routine. I found that the connection to the server is very slow, it takes more than 20 seconds, how can I solve this problem?

I use NBIOT and ncs1.5.0.

Here is my mqtt_init:

static int client_init(struct mqtt_client *client)
{
	int err;

	mqtt_client_init(client);

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

	/* MQTT client configuration */
	client->broker = &broker;
	client->evt_cb = mqtt_evt_handler;
	client->client_id.utf8 = (uint8_t *)CONFIG_MQTT_CLIENT_ID;
	client->client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
	client->password = NULL;
	client->user_name = NULL;
	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);

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

	LOG_INF("TLS enabled");
	client->transport.type = MQTT_TRANSPORT_SECURE;

	tls_cfg->peer_verify = TLS_PEER_VERIFY_NONE;
	tls_cfg->cipher_count = 0;
	tls_cfg->cipher_list = NULL;
	tls_cfg->sec_tag_count = 0;
	tls_cfg->sec_tag_list = NULL;
	tls_cfg->hostname = CONFIG_MQTT_BROKER_HOSTNAME;

	tls_cfg->session_cache = IS_ENABLED(CONFIG_MQTT_TLS_SESSION_CACHING) ?
					    TLS_SESSION_CACHE_ENABLED :
					    TLS_SESSION_CACHE_DISABLED;

	return err;
}

prj.conf:

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

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_NBIOT=y
CONFIG_LTE_LEGACY_PCO_MODE=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# Modem library
CONFIG_NRF_MODEM_LIB=y

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y

# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=y
CONFIG_MQTT_CLEAN_SESSION=y

# Application
CONFIG_MQTT_PUB_TOPIC="my/publish/topic"
CONFIG_MQTT_SUB_TOPIC="my/subscribe/topic"
CONFIG_MQTT_CLIENT_ID="my/test/id"
CONFIG_MQTT_BROKER_HOSTNAME="47.106.164.80"
CONFIG_MQTT_BROKER_PORT=18883

# Button support
CONFIG_DK_LIBRARY=y

# Enable logging
CONFIG_LOG=y
CONFIG_MQTT_SIMPLE_LOG_LEVEL_DBG=y

# Memory
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=2048

Serial log:

Non-secure callable region 0 placed in flash region 0 with size 32.


[17:52:21.884]收←◆SRAM region		Domain		Permissions
00 07 0x00000 0x10000 	Secure		rwxl
08 31 0x10000 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_EGU1             Non-Secure	OK
22 NRF_EGU2             Non-Secure	OK
23 NRF_DPPIC            Non-Secure	OK
24 NRF_REGULATORS       Non-Secure	OK
25 NRF_GPIOTE1          Non-Secure	OK

SPM: NS image at 0xc000
SPM: NS MSP at 0x20019740
SPM: NS reset vector at 0x10021
SPM: prepare to jump to Non-Secure image.

[17:52:22.196]收←◆*** Booting Zephyr OS build v2.4.99-ncs1  ***

[17:52:23.200]收←◆[00:00:00.205,413] <inf> mqtt_simple: The MQTT simple sample started
[00:00:00.205,413] <inf> mqtt_simple: Provisioning certificates
[00:00:00.205,413] <inf> mqtt_simple: Disabling PSM and eDRX
[00:00:00.207,000] <inf> mqtt_simple: LTE Link Connecting...
[00:00:00.216,705] <inf> lte_lc: Using legacy LTE PCO mode...

[17:52:23.946]收←◆+CEREG: 
[17:52:23.978]收←◆2,"1D2C","0D61D950",9,0,0,"11100000","11100000"

[17:52:24.560]收←◆+CSCON: 1

[17:52:26.341]收←◆+CEREG: 1,"1D2C","0D61D950",9,,,"11100000","11100000"

[17:52:26.516]收←◆+CSC
[17:52:26.544]收←◆ON: 0

[17:52:27.346]收←◆[00:00:04.35
[17:52:27.372]收←◆0,799] <inf> mqtt_simple: LTE Link Connected!
[00:00:04.351,196] <inf> mqtt_simple: IPv4 Address found 47.106.164.80
[00:00:04.351,226] <inf> mqtt_simple: TLS enabled

[17:52:29.634]收←◆+CSCON: 1

[17:52:29.955]收←◆+CSCON: 0

[17:52:32.176]收←◆+CSCON: 1

[17:52:34.195]收←◆+CSCON: 0

[17:52:37.291]收←◆+CSCON: 1

[17:52:39.053]收←◆+CSCON: 0

[17:52:42.416]收←◆+CSCON:
[17:52:42.436]收←◆ 1

[17:52:43.329]收←◆+CSCON: 0

[17:52:44.995]收←◆+CSCON: 1

[17:52:46.699]收←◆+CSCON: 0

[17:52:47.531]收←◆+CSCON: 1

[17:52:47.669]收←◆+CSCON: 0

[17:52:54.576]收←◆+CSCON: 1

[17:52:54.754]收←◆+CSCON: 0

[17:52:57.772]收←◆+CSCON: 1

[17:52:58.029]收←◆+CSCON: 0

[17:53:00.354]收←◆+CSCON: 1

[17:53:00.673]收←◆+CSCON: 0

[17:53:02.896]收←◆+CSCON:
[17:53:02.923]收←◆ 1

[17:53:03.164]收←◆+CSCON: 0
[17:53:03.191]收←◆

[17:53:04.045]收←◆[00:00:41.050,811] <inf> mqtt_simple: MQTT client connected
[00:00:41.050,842] <inf> mqtt_simple: Subscribing to: my/subscribe/topic len 18

[17:53:05.474]收←◆+CSCON:
[17:53:05.496]收←◆ 1

[17:53:06.164]收←◆+CSCON: 0

[17:53:06.642]收←◆[00:00:43.647,888] <inf> mqtt_simple: SUBACK packet id: 1234

I use MQTT BOX for connection test, the connection speed is very fast. The following are my configuration parameters. 

   

Parents
  • Hello,

    can you set

    CONFIG_NET_LOG=y
    CONFIG_MQTT_LOG_LEVEL_DBG=y

    for more detailed log output?

  • Hi,

    I changed to another 91 chip and burned the same program. -45 error occurred in mqtt connection : Operation not supported on socket. Here is my log:

    [00:00:00.243,316] <inf> main: Connecting to LTE network.
    [00:00:00.243,316] <inf> main: This may take several minutes.
    [00:00:00.243,377] <inf> flash_control: No apn found, use default apn
    [00:00:00.249,908] <inf> main: Set to the default APN CMNBIOT2.
    [00:00:00.258,087] <inf> lte_lc: Using legacy LTE PCO mode...
    
    [18:48:48.897]收←◆[00:00:01.725,158] <inf> mai
    [18:48:48.919]收←◆n: LTE ERROR
    [00:00:02.258,117] <inf> main: CSCON : 1
    
    [18:48:50.833]收←◆[00:00:04.283,386] <inf> main: Connected to LTE network.
    [00:00:04.283,477] <inf> main: LTE SUCCESS
    [00:00:04.286,163] <inf> mqtt_engine: IPv4 Address found 47.106.164.80
    [00:00:04.286,193] <inf> mqtt_engine: TLS enabled
    [00:00:04.286,468] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015220): Created socket 1
    [00:00:04.660,552] <err> mqtt_engine: mqtt_connect -45
    [00:00:04.660,583] <err> mqtt_engine: ERROR: mqtt_disconnect -57

    -45 is EOPNOTSUPP, and typically indicates that you have written wrong certificates to the device. But I had peer_verify set to 0. 

  • As far as I know you should not attempt to use TLS without a CA certificate on the device, even though you are not using it.

Reply Children
Related