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

NRF9160 MQTT Client error -12 (ENOMEM) when Host url is very long

Hello, 

I'm using the mqtt_simple example with the following changes to add WebSockets Secure Support:

# Networking
CONFIG_NET_NATIVE=y

# MQTT
CONFIG_MQTT_LIB_TLS=y
CONFIG_MQTT_LIB_WEBSOCKET=y
CONFIG_WEBSOCKET_CLIENT=y

# Logs
CONFIG_NET_LOG=y
CONFIG_MQTT_LOG_LEVEL_DBG=y

Also I set the Application MQTT topics, clientId, host, port and everything using the CONFIG.

The only change I made in the code was this:

client->transport.type = MQTT_TRANSPORT_SECURE_WEBSOCKET;

The issue is that our Amazon AWS IoT broker url is very long, exactly 1.681 bytes, this is because Amazon give us a url with the token and all the credentials embedded in the url. When I run the code I'm seeing a ENOMEM (-12) when calling the mqtt_connect function.

This is the log:

*** Booting Zephyr OS build v2.4.0-ncs1  ***
The MQTT simple sample started
Provisioning certificates
LTE Link Connecting ...<CR><LF>
+CEREG: 2,"3174","02D71604",7,0,0,"11100000","11100000"
+CSCON: 1
+CEREG: 1,"3174","02D71604",7,,,"11100000","11100000"
LTE Link Connected!
IPv4 Address found 3.211.121.218
ERROR: mqtt_connect -12
[00:00:03.320,220] <ESC><dbg> net_mqtt.client_connect: (0x20020e08): Using transport type 3<ESC>
[00:00:03.320,587] <ESC><dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20020e08): Created socket 1<ESC>[0
[00:00:03.321,044] <ESC><dbg> net_mqtt_websocket.mqtt_client_websocket_connect: (0x20020e08): mqtt_client_tls_connect: -12<ESC>
[00:00:03.321,075] <ESC><dbg> net_mqtt.mqtt_connect: (0x20020e08): client_connect: -12<ESC>

I was able to debug the error to the following function in mqtt_transport_socket_tls.c

int mqtt_client_tls_connect(struct mqtt_client *client)
{
    .
    .
    .
    
    if (tls_config->hostname) {
		ret = setsockopt(client->transport.tls.sock, SOL_TLS,
				 TLS_HOSTNAME, tls_config->hostname,
				 strlen(tls_config->hostname));
		if (ret < 0) {
			goto error;
		}
	}
	
	.
	.
	.
	
}

So my question is how I can somehow increase the memory that the setsockopt function uses when setting the hostname on the socket.

I already tested increasing the main stack and heap memory using the CONFIG with no luck.

# Memory
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=16384

Btw I'm using NCS v1.4.0 and modem fw 1.2.3.

Any help will be appreciated.

Thanks! 

  • Hi,

    I don't think there are any ways to increase the max size of an socket option in NCS v1.4.0.

    However, in NCS 1.5.0 and newer, we have changed the arcitecture of the bsd library (and renamed it to modem_lib), which allows more control over the sizes of the shared memory buffers between the modem and the application.

    It might be that you can get it to work if you increase CONFIG_NRF_MODEM_LIB_HEAP_SIZE (the default is 1024). But, as I said, that requires you to upgrade to NCS v1.5.0 or newer.

    Best regards,

    Didrik

  • Hi,

    Thanks for the reply. Now the error is gone with the latest NCS 1.6.1 and the CONFIG_NRF_MODEM_LIB_HEAP_SIZE set to a bigger number (2048 in my case).

    However, now I'm getting another error -104 (ECONNRESET) when trying to connect to the host.

    My broker url is something like this: 

    wss://a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA5LIR3OD4PNZVUF73%2F20210818%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20210818T160046Z&X-Amz-SignedHeaders=host&X-Amz-Signature=71799e3b5b11041c942f91a08104496728ae010871689c5cbb353b59765f224a&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEGgaCXVzLWVhc3QtMSJHMEUCIQDN734sppYDiuxLqXcqLgdfME8k%2F68eQEs7Ws6xcabfVwIgGoOd5Vr6LUWLtLemX0HSLZN7YrrKFwL7jnf4bh9q%2FVcqmgQIkf%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgw5MTc1NDk4Mzg1ODQiDIw8KE5rmwBVO6O%2FEiruA%2FubL8pj9ycCNm2EO8B%2F%2BZuMnQMydHsoGQVfMN6lmHS%2FIkpqopmm6mlwZ1rphA2bhHrRx%2BnSN5v092TrU%2BMT8IN%2FFVaDy3HCDaJeqC3X6u4Cbzyq98kn4sf8vNc2KoO180ryYyXb2z2KwbWckcsXge8Kv7EVW5NU3AwHJ9sD3g2YW0rNe83GWiWOk96j0j26sQjosdUFaIB%2ByTy8rp6%2FxP3la%2FnCCJ59ORUrCOybJX7xpO6hbPJqLeJ3r04hl2Q5NuN1LNzS61c9NS6OrFHqW9adt%2B91MxmpgYQrnFRn9CD72Er1vg1Rb8yAmN%2FRBUyd4Ac5Gi%2Bh%2BCAZa6RclJDI%2B5PRYbWfr6LQK5emy9jCw%2BEYPtxtSb8DGC3fI5A2IBTuqq8HM6XE%2BBrjEea2%2B5PuDrJx4OIe6G8buHnLsbDTs%2FkNPR7IMu0NNFj%2B%2F6roJxjPQZngktj1d6VT1XzWPgLSO5a2bffYCyQVFBmw0WiI4DNSIEVonmZ9oDZHo9OWlt6i8vnxJd1tEw97R2JSK2i%2FWMIero%2F2UJ6ZEmtVA%2BiSkaRd09iVf62cN4Hoq20RIJEHk%2FTp6DCbBaJAZ93pWUSh3xfqgu1iuNsUm76D%2BZyGIsTFNtDJdepULq18o2my91dHNmnxlIyk7H4spkK%2FSI0FMK7d9IgGOoUC0aFuhth7Awb05SsYETk5RBycwcMH6V9bIffIoZYCzai5g3%2Fio%2Ff22INC0OUZR4%2B6QA8PDZJPHu8qVk%2B%2FeIAWsOd%2Fbbty5xg16UmLabps6%2B7U3DHTPlVbbX7qoviD1YCWQ7xdc2CqNSK9PqKGEwI5T7jIzfFjWIc5Tubil1e7GY9g7aLonwKPV12mKpmOzxmt0PSqI1AgVIaxRx6dh0PGHh7MsrB%2ByKrHA4YMM%2B1pggjFg%2Bv4I1AP0GxnLnZLfa5Uoqawap68KBBWznXyy0RmOVKP6gSI9CAM%2FGxff1aFPbNI60PWQvCRJsIQ0n85CHaBR%2B2dzX98CTE6izFRhJJ8Yn7IaOpO

    And because of our policy it only works if the cliend_id is set this one (it changes depending on the broker url): 

    devices:60de0ce0ed9a344969e7063c:5dea729db307982a01eb5b47:p:h4Y
     

    If I set the CONFIG_MQTT_BROKER_HOSTNAME to the full url the getaddrinfo function fails to resolve the host so I had to modify a little bit the code to add the short hostname that will be only a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com. That way the getaddrinfo function resolves the ip address of the host.

    Also I enabled Websockets and TLS and changed the MQTT transport type to secure websocket.

    client->transport.type = MQTT_TRANSPORT_SECURE_WEBSOCKET;

    and inside the TLS config I set the 

    tls_cfg->hostname = MQTT_BROKER_HOSTNAME_FULL;
    
    // Where MQTT_BROKER_HOSTNAME_FULL is the full broker url: a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA5LIR3OD4PNZVUF73%2F20210818%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20210818T160046Z&X-Amz-SignedHeaders=host&X-Amz-Signature=71799e3...

    When I run the application this is the LOG I get:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    [00:00:00.212,707] <ESC><inf> mqtt_simple: The MQTT simple sample started<ESC>
    [00:00:00.220,092] <ESC><inf> mqtt_simple: Provisioning certificates<ESC>
    [00:00:00.227,111] <ESC><inf> mqtt_simple: Disabling PSM and eDRX<ESC>
    [00:00:00.240,966] <ESC><inf> mqtt_simple: LTE Link Connecting...<ESC>
    
    8/18/2021 08:18:09.703 [RX] - +CEREG: 2,"3174","02D71604",7,0,0,"11100000","11100000"
    +CSCON: 1
    +CEREG: 1,"3174","02D71604",7,,,"11100000","11100000"
    [00:00:02.127,532] <ESC><inf> mqtt_simple: LTE Link Connected!<ESC>
    [00:00:02.283,996] <ESC><inf> mqtt_simple: IPv4 Address found 3.212.203.9<ESC>
    client_id = devices:60de0ce0ed9a344969e7063c:5dea729db307982a01eb5b47:p:h4Y
    [00:00:02.298,828] <ESC><inf> mqtt_simple: TLS enabled<ESC>
    [00:00:02.304,473] <ESC><inf> mqtt_simple: Full hostname: a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA5LIR3OD4PNZVUF73%2F20210818%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20210818T160046Z&X-Amz-SignedHeaders=host&X-Amz-Signature=71799e3b5b11041c942f91a08104496728ae010871689c5cbb353b59765f224a&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEGgaCXVzLWVhc3QtMSJHMEUCIQDN734sppYDiuxLqXcqLgdfME8k%2F68eQEs7Ws6xcabfVwIgGoOd5Vr6LUWLtLemX0HSLZN7YrrKFwL7jnf4bh9q%2FVcqmgQIkf%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgw5MTc1NDk4Mzg1ODQiDIw8KE5rmwBVO6O%2FEiruA%2FubL8pj9ycCNm2EO8B%2F%2BZuMnQMydHsoGQVfMN6lmHS%2FIkpqopmm6mlwZ1rphA2bhHrRx%2BnSN5v092TrU%2BMT8IN%2FFVaDy3HCDaJeqC3X6u4Cbzyq98kn4sf8vNc2KoO180ryYyXb2z2KwbWckcsXge8Kv7EVW5NU3AwHJ9sD3g2YW0rNe83GWiWOk96j0j26sQjosdUFaIB%2ByTy8rp6%2FxP3la%2FnCCJ59ORUrCOybJX7xpO6hbPJqLeJ3r04hl2Q5NuN1LNzS61c9NS6OrFHqW9adt%2B91MxmpgYQrnFRn9CD72Er1vg1Rb8yAmN%2FRBUyd4Ac5Gi%2Bh%2BCAZa6RclJDI%2B5PRYbWfr6LQK5emy9jCw%2BEYPtxtSb8DGC3fI5A2IBTuqq8HM6XE%2BBrjEea2%2B5PuDrJx4OIe6G8buHnLsbDTs%2FkNPR7IMu0NNFj%2B%2F6roJxjPQZngktj1d6VT1XzWPgLSO5a2bffYCyQVFBmw0WiI4DNSIEVonmZ9oDZHo9OWlt6i8vnxJd1tEw97R2JSK2i%2FWMIero%2F2UJ6ZEmtVA%2BiSkaRd09iVf62cN4Hoq20RIJEHk%2FTp6DCbBaJAZ93pWUSh3xfqgu1iuNsUm76D%2BZyGIsTFNtDJdepULq18o2my91dHNmnxlIyk7H4spkK%2FSI0FMK7d9IgGOoUC0aFuhth7Awb05SsYETk5RBycwcMH6V9bIffIoZYCzai5g3%2Fio%2Ff22INC0OUZR4%2B6QA8PDZJPHu8qVk%2B%2FeIAWsOd%2Fbbty5xg16UmLabps6%2B7U3DHTPlVbbX7qoviD1YCWQ7xdc2CqNSK9PqKGEwI5T7jIzfFjWIc5Tubil1e7GY9g7aLonwKPV12mKpmOzxmt0PSqI1AgVIaxRx6dh0PGHh7MsrB%2ByKrHA4YMM%2B1pggjFg%2Bv4I1AP0GxnLnZLfa5Uoqawap68KBBWznXyy0RmOVKP6gSI9CAM%2FGxff1aFPbNI60PWQvCRJsIQ0n85CHaBR%2B2dzX98CTE6izFRhJJ8Yn7IaOpO<ESC>
    Connecting to a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com:8883
    [00:00:02.477,691] <ESC><dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015170): Created socket 1<ESC>
    [00:00:03.712,066] <ESC><err> mqtt_simple: mqtt_connect -104<ESC>
    [00:00:03.720,336] <ESC><inf> mqtt_simple: Reconnecting in 60 seconds...<ESC>

    I know that the Broker Url and Client_id works because I'm using MQTTBox client and I can connect to the broker using the same certificate file that I uploaded to the modem.

    As you can see in the following image the MQTT Box Mqtt client is connected to the broker using websockets secure.

    I'm not sure why Im getting that ECONNRESET error. I traced the error to the following function:

    int mqtt_client_tls_connect(struct mqtt_client *client) {
        .
        .
        .
        
        ret = zsock_connect(client->transport.tls.sock, client->broker,
    			    peer_addr_size);
    	if (ret < 0) {
    		goto error;
    	}
        
        .
        .
        .
    }

    The client->broker is set to the result of the getaddrinfo function inside the broker_init() function on main.c.

    Can you help me with this issue? 

    To summarize:

    • I'm trying to connect to a AMZ iot broker that has a long url because of the token being embedded on the url.
    • The broker uses Secure Web Sockets
    • I'm getting the ECONNRESET when trying to connect to the socket using zsock_connect function.

    Thanks in advance.

  • The hostname in this case is just a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com. So that is what you should use with getaddrinfo (as you are already doing), and what you should use for hostname verification.

    My guess is that the error is because you use the full URL, and not just the hostname for hostname verification.

  • Hi,

    You are right, the hostname in this case should be only the a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com.

    When I changed it the device could create the socket and connect to it.

    After that, the device sends the WS handshake and I get the "Connect completed" message.

    This is the function I'm on:

    static int client_connect(struct mqtt_client *client)
    {
    	int err_code;
    	struct buf_ctx packet;
    
    	err_code = mqtt_transport_connect(client);
    	if (err_code < 0) {
    		return err_code;
    	}
    
    	tx_buf_init(client, &packet);
    	MQTT_SET_STATE(client, MQTT_STATE_TCP_CONNECTED);
    
    	err_code = connect_request_encode(client, &packet);
    	if (err_code < 0) {
    		goto error;
    	}
    
    	/* Send MQTT identification message to broker. */
    	err_code = mqtt_transport_write(client, packet.cur,
    					packet.end - packet.cur);
    	if (err_code < 0) {
    		goto error;
    	}
    
    	client->internal.last_activity = mqtt_sys_tick_in_ms_get();
    
    	/* Reset the unanswered ping count for a new connection */
    	client->unacked_ping = 0;
    
    	MQTT_TRC("Connect completed");
    
    	return 0;
    
    error:
    	client_disconnect(client, err_code, false);
    	return err_code;
    }

    The mqtt_transport_connect function is returning fine (err_code is 0, and I get the "Connect Completed" message).

    But now, I'm having another issue on the function mqtt_transport_write when sending the MQTT identification message to the broker, the device just hangs inside that function and never returns.

    I debugged the code, and I put a breakpoint inside the function mqtt_transport_write() -> websocket_send_msg() -> websocket_prepare_and_send() the function that never returns is the send_msg().

    static int websocket_prepare_and_send(struct websocket_context *ctx,
    				      uint8_t *header, size_t header_len,
    				      uint8_t *payload, size_t payload_len,
    				      int32_t timeout)
    {
    	struct iovec io_vector[2];
    	struct msghdr msg;
    
    	io_vector[0].iov_base = header;
    	io_vector[0].iov_len = header_len;
    	io_vector[1].iov_base = payload;
    	io_vector[1].iov_len = payload_len;
    
    	memset(&msg, 0, sizeof(msg));
    
    	msg.msg_iov = io_vector;
    	msg.msg_iovlen = ARRAY_SIZE(io_vector);
    
    	if (HEXDUMP_SENT_PACKETS) {
    		LOG_HEXDUMP_DBG(header, header_len, "Header");
    		LOG_HEXDUMP_DBG(payload, payload_len, "Payload");
    	}
    
    #if defined(CONFIG_NET_TEST)
    	/* Simulate a case where the payload is split to two. The unit test
    	 * does not set mask bit in this case.
    	 */
    	return verify_sent_and_received_msg(&msg, !(header[1] & BIT(7)));
    #else
    	k_timeout_t tout = K_FOREVER;
    
    	if (timeout != SYS_FOREVER_MS) {
    		tout = K_MSEC(timeout);
    	}
    
    	return sendmsg(ctx->real_sock, &msg,
    		       K_TIMEOUT_EQ(tout, K_NO_WAIT) ? MSG_DONTWAIT : 0);
    #endif /* CONFIG_NET_TEST */
    }

    I noticed that the timeout is SYS_FOREVER_MS and it came from the function mqtt_client_websocket_write:

    int mqtt_client_websocket_write(struct mqtt_client *client, const uint8_t *data,
    				uint32_t datalen)
    {
    	uint32_t offset = 0U;
    	int ret;
    
    	while (offset < datalen) {
    		ret = websocket_send_msg(client->transport.websocket.sock,
    					 data + offset, datalen - offset,
    					 WEBSOCKET_OPCODE_DATA_BINARY,
    					 true, true, SYS_FOREVER_MS);
    		if (ret < 0) {
    			return -errno;
    		}
    
    		offset += ret;
    	}
    
    	return 0;
    }

    I have other question:

    Where I should add the other part of the broker url after the /mqtt (?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA5LIR3OD4PNZVUF73%2F20210818%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20210818...) because if I add it on the client->transport.websocket.config.url, I got an error when doing the WS handshake.

    Btw, this is the log I have:

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    [00:00:00.218,536] <ESC><inf> mqtt_simple: The MQTT simple sample started<ESC>
    [00:00:00.225,860] <ESC><inf> mqtt_simple: Provisioning certificates<ESC>
    [00:00:00.232,818] <ESC><inf> mqtt_simple: Disabling PSM and eDRX<ESC>
    [00:00:00.246,643] <ESC><inf> mqtt_simple: LTE Link Connecting...<ESC>
    
    8/20/2021 08:22:45.075 [RX] - +CEREG: 2,"3174","02D71604",7,0,0,"11100000","11100000"
    +CSCON: 1
    +CEREG: 1,"3174","02D71604",7,,,"11100000","11100000"
    [00:00:02.242,706] <ESC><inf> mqtt_simple: LTE Link Connected!<ESC>
    [00:00:02.485,595] <ESC><inf> mqtt_simple: IPv4 Address found 3.218.12.230<ESC>
    client_id = devices:60de0ce0ed9a344969e7063c:5dea729db307982a01eb5b47:p:tJH
    [00:00:02.500,488] <ESC><inf> mqtt_simple: TLS enabled<ESC>
    Connecting to a272tdymsn5n79-ats.iot.us-east-1.amazonaws.com:443
    [00:00:02.512,756] <ESC><dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015170): Created socket 1<ESC>
    [00:00:03.937,988] <ESC><dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20015170): Connect completed<ESC>
    [00:00:03.948,883] <ESC><dbg> net_http.Data to send
                                      47 45 54 20 2f 6d 71 74  74 20 48 54 54 50 2f 31 |GET /mqt t HTTP/1
                                      2e 31 0d 0a 48 6f 73 74  3a 20 61 32 37 32 74 64 |.1..Host : a272td
                                      79 6d 73 6e 35 6e 37 39  2d 61 74 73 2e 69 6f 74 |ymsn5n79 -ats.iot
                                      2e 75 73 2d 65 61 73 74  2d 31 2e 61 6d 61 7a 6f |.us-east -1.amazo
                                      6e 61 77 73 2e 63 6f 6d  0d 0a 53 65 63 2d 57 65 |naws.com ..Sec-We
                                      62 53 6f 63 6b 65 74 2d  50 72 6f 74 6f 63 6f 6c |bSocket- Protocol
                                      3a 20 6d 71 74 74 0d 0a  53 65 63 2d 57 65 62 53 |: mqtt.. Sec-WebS
                                      6f 63 6b 65 74 2d 4b 65  79 3a 20 64 75 6f 30 42 |ocket-Ke y: duo0B
                                      38 64 47 6a 42 69 44 42  44 6a 39 76 49 58 2f 4f |8dGjBiDB Dj9vIX/O
                                      51 3d 3d 0d 0a 55 70 67  72 61 64 65 3a 20 77 65 |Q==..Upg rade: we
                                      62 73 6f 63 6b 65 74 0d  0a 43 6f 6e 6e 65 63 74 |bsocket. .Connect
                                      69 6f 6e 3a 20 55 70 67  72 61 64 65 0d 0a 53 65 |ion: Upg rade..Se<ESC>
    [00:00:04.073,760] <ESC><dbg> net_http.Data to send
                                      63 2d 57 65 62 53 6f 63  6b 65 74 2d 56 65 72 73 |c-WebSoc ket-Vers
                                      69 6f 6e 3a 20 31 33 0d  0a 0d 0a                |ion: 13. ...     <ESC>
    [00:00:04.099,548] <ESC><dbg> net_http.http_client_req: (0x20015170): Sent 731 bytes<ESC>
    [00:00:04.564,910] <ESC><dbg> net_http.on_message_begin: (0x20015170): -- HTTP GET response (headers) --<ESC>
    [00:00:04.575,225] <ESC><dbg> net_http.on_status: (0x20015170): HTTP response status 101 Switching Protocols<ESC>
    [00:00:04.586,059] <ESC><dbg> net_http.print_header_field: (0x20015170): [14] content-length<ESC>
    [00:00:04.595,336] <ESC><dbg> net_http.print_header_field: (0x20015170): [1] 0<ESC>
    [00:00:04.603,271] <ESC><dbg> net_http.print_header_field: (0x20015170): [7] upgrade<ESC>
    [00:00:04.611,785] <ESC><dbg> net_http.print_header_field: (0x20015170): [9] websocket<ESC>
    [00:00:04.620,483] <ESC><dbg> net_http.print_header_field: (0x20015170): [10] connection<ESC>
    [00:00:04.629,364] <ESC><dbg> net_http.print_header_field: (0x20015170): [7] upgrade<ESC>
    [00:00:04.637,817] <ESC><dbg> net_http.print_header_field: (0x20015170): [20] sec-websocket-accept<ESC>
    [00:00:04.647,705] <ESC><dbg> net_http.print_header_field: (0x20015170): [28] 1KnKUuefVsvww3RJ7D4dvX6XCRc=<ESC>
    [00:00:04.658,325] <ESC><dbg> net_http.print_header_field: (0x20015170): [22] sec-websocket-protocol<ESC>
    [00:00:04.668,273] <ESC><dbg> net_http.print_header_field: (0x20015170): [4] mqtt<ESC>
    [00:00:04.676,422] <ESC><dbg> net_http.on_headers_complete: (0x20015170): Headers complete<ESC>
    [00:00:04.685,516] <ESC><dbg> net_http.on_message_complete: (0x20015170): -- HTTP GET response (complete) --<ESC>
    [00:00:04.696,258] <ESC><dbg> net_websocket.response_cb: (0x20015170): [0x20014f10] All the data received (178 bytes)<ESC>
    [00:00:04.707,855] <ESC><dbg> net_http.http_client_req: (0x20015170): Received 178 bytes<ESC>
    [00:00:04.716,705] <ESC><dbg> net_websocket.websocket_connect: (0x20015170): [0x20014f10] WS connection to peer established (fd 2)<ESC>
    [00:00:04.729,553] <ESC><dbg> net_mqtt_websocket.mqtt_client_websocket_connect: (0x20015170): Connect completed<ESC>
    [00:00:04.740,844] <ESC><dbg> net_mqtt_enc.Encoding Protocol Description.
                                          4d 51 54 54                                      |MQTT             <ESC>
    [00:00:04.758,514] <ESC><dbg> net_mqtt_enc.pack_utf8_str: (0x20015170): >> str_size:00000006 cur:0x2001c124, end:0x2001c91f<ESC>
    [00:00:04.770,751] <ESC><dbg> net_mqtt_enc.pack_uint16: (0x20015170): >> val:0004 cur:0x2001c124, end:0x2001c91f<ESC>
    [00:00:04.781,951] <ESC><dbg> net_mqtt_enc.connect_request_encode: (0x20015170): Encoding Protocol Version 04.<ESC>
    [00:00:04.792,877] <ESC><dbg> net_mqtt_enc.pack_uint8: (0x20015170): >> val:04 cur:0x2001c12a, end:0x2001c91f<ESC>
    [00:00:04.803,802] <ESC><dbg> net_mqtt_enc.pack_uint8: (0x20015170): >> val:00 cur:0x2001c12b, end:0x2001c91f<ESC>
    [00:00:04.814,727] <ESC><dbg> net_mqtt_enc.connect_request_encode: (0x20015170): Encoding Keep Alive Time 0005.<ESC>
    [00:00:04.825,836] <ESC><dbg> net_mqtt_enc.pack_uint16: (0x20015170): >> val:0005 cur:0x2001c12c, end:0x2001c91f<ESC>
    [00:00:04.836,944] <ESC><dbg> net_mqtt_enc.Encoding Client Id.
                                          64 65 76 69 63 65 73 3a  36 30 64 65 30 63 65 30 |devices: 60de0ce0
                                          65 64 39 61 33 34 34 39  36 39 65 37 30 36 33 63 |ed9a3449 69e7063c
                                          3a 35 64 65 61 37 32 39  64 62 33 30 37 39 38 32 |:5dea729 db307982
                                          61 30 31 65 62 35 62 34  37 3a 70 3a 74 4a 48    |a01eb5b4 7:p:tJH <ESC>
    [00:00:04.884,552] <ESC><dbg> net_mqtt_enc.pack_utf8_str: (0x20015170): >> str_size:00000041 cur:0x2001c12e, end:0x2001c91f<ESC>
    [00:00:04.896,728] <ESC><dbg> net_mqtt_enc.pack_uint16: (0x20015170): >> val:003f cur:0x2001c12e, end:0x2001c91f<ESC>
    [00:00:04.907,928] <ESC><dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015170): << msg type:0x10 length:0x0000004b<ESC>
    [00:00:04.919,525] <ESC><dbg> net_mqtt_enc.packet_length_encode: (0x20015170): >> length:0x0000004b cur:(nil), end:(nil)<ESC>
    [00:00:04.931,396] <ESC><dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20015170): Fixed header length = 02<ESC>
    [00:00:04.942,016] <ESC><dbg> net_mqtt_enc.pack_uint8: (0x20015170): >> val:10 cur:0x2001c122, end:0x2001c91f<ESC>
    [00:00:04.952,850] <ESC><dbg> net_mqtt_enc.packet_length_encode: (0x20015170): >> length:0x0000004b cur:0x2001c123, end:0x2001c91f<ESC>
    [00:00:04.965,667] <ESC><dbg> net_websocket.websocket_send_msg: (0x20015170): [0x20014f10] Len 77 BIN/1/final<ESC>
    [00:00:04.976,806] <ESC><dbg> net_websocket.Header
                                           82 cd 88 5b 21 9a                                |...[!.           <ESC>
    [00:00:04.992,370] <ESC><dbg> net_websocket.Payload
                                           98 10 21 9e c5 0a 75 ce  8c 59 21 9f 88 64 45 ff |..!...u. .Y!..dE.
                                           fe 32 42 ff fb 61 17 aa  ec 3e 11 f9 ed 6b 44 fe |.2B..a.. .>...kD.
                                           b1 3a 12 ae bc 62 17 a3  ed 6c 11 ac bb 38 1b af |.:...b.. .l...8..
                                           ec 3e 40 ad ba 62 45 f8  bb 6b 16 a3 b0 69 40 aa |.>@..bE. .k...i@.
                                           b9 3e 43 af ea 6f 16 a0  f8 61 55 d0 c0          |.>C..o.. .aU..   <ESC>
    
    8/20/2021 08:22:58.555 [RX] - +CSCON: 0

    Also I made another test, and I changed the timeout to 5000ms

    k_timeout_t tout = K_MSEC(5000);

    But same result. 

    Can you help me with this issue?

    Thanks in advance!

  • Jose Cano said:
    Where I should add the other part of the broker url after the /mqtt (?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA5LIR3OD4PNZVUF73%2F20210818%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20210818...) because if I add it on the client->transport.websocket.config.url, I got an error when doing the WS handshake.

     I would expect it to go in client->transport.websocket.config.url, as you tried. What error did you get?

    Also, a modem trace might be helpful to understand what is going on.

    We have also released a preview of our next version of the Trace Collector application, which will let you decode traces yourself.

Related