nRF5340: MQTT subscribe failed

Hi Support team,

The communication of my net-core of nRF5340 is working well, and I want to try mqtt subscription, but it always fails, could you help give me some hints?

I try to do the subscription in the  event handler of MQTT_EVT_CONNACK:

#define SPARKPLUGB_NCMD         "spBv1.0/BDS/NCMD/Node1/#"
#define SPARKPLUGB_DCMD         "spBv1.0/BDS/DCMD/Node1/#"

int sparkb_sub_cmd(struct mqtt_client *const client)
{
    struct mqtt_topic cmdTopic[2];
	cmdTopic[0].topic.utf8 = (uint8_t *)SPARKPLUGB_NCMD;
	cmdTopic[0].topic.size = strlen(SPARKPLUGB_NCMD);
	cmdTopic[0].qos = MQTT_QOS_0_AT_MOST_ONCE;
	cmdTopic[1].topic.utf8 = (uint8_t *)SPARKPLUGB_DCMD;
	cmdTopic[1].topic.size = strlen(SPARKPLUGB_DCMD);
	cmdTopic[1].qos = MQTT_QOS_0_AT_MOST_ONCE;

	struct mqtt_subscription_list sub_param = {
		.list = cmdTopic,
		.list_count = 2,
		.message_id = 0U
	};

	return mqtt_subscribe(client, &sub_param);
}

In void mqtt_evt_handler(struct mqtt_client *const client, const struct mqtt_evt *evt)
{
	int err;

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

			g_connected = true;
			LOG_INF("-----[MQTT_EVT_CONNACK] MQTT client connected!");
			
			//Upon connect successful, subscribe to sparkplug NCMD and DCMD msgs. A production should handle MQTT connect failures.
			err = sparkb_sub_cmd(client);
			if (err != 0) {
				LOG_ERR("-----[MQTT_EVT_CONNACK] Failed to subscribe sparkplug NCMD and DCMD: %d", err);
			}

			break;

The MQTT connection succeded, but the subscription is failed, the error code is -22 (#define  EINVAL 22   /* Invalid argument */), the trace as below:

[00:00:25.672,332] <inf> main: modem_test() successful!
[00:00:25.905,395] <inf> mqtttest: mqtt_connect OK, rc is 0
[00:00:26.146,850] <inf> mqtttest: do zsock_poll() 2s, ret = 1
[00:00:26.146,972] <inf> mqtttest: -----[MQTT_EVT_CONNACK] MQTT client connected!
[00:00:26.147,003] <err> mqtttest: -----[MQTT_EVT_CONNACK] Failed to subscribe sparkplug NCMD and DCMD: -22

The published two topics "spBv1.0/BDS/NCMD/Node1/#" and "spBv1.0/BDS/DCMD/Node1/#" by other mqtt clients, so these two topics have existed on the MQTT server.

Could you help have a look and give some hints as to why subscriptions always fail? Thank you very much.

Best regards,
Yanpeng Wu

Parents
  • Hi,

    The message ID is not permitted to be 0 by the specification.

    In addition, you might run into a problem where sub_param is used after it is deallocated, as it is currently just allocated on the stack.

    Best regards,

    Didrik

  • Hi Didrik,

    Thanks for your guidance. It's true, the subscription is successful when I set the .message_id = sys_rand32_get(). The sub_param created as a local variable and on the stack is no problem, and it can work well(I guess the mqtt API uses 'pass by value' or be called synchronously), I can publish success when the subscription fails.


    But a new problem occurred after the successful subscription, I received an MQTT_EVT_DISCONNEC and the evt->result is -105, the trace is:

    [00:00:49.091,186] <inf> mqtttest: -----[MQTT_EVT_DISCONNECT] MQTT client disconnected -105
               //#define ENOBUFS 105 /* No buffer space available */

    Why just subscribing to two topics will cause 'No buffer space available' and lose the MQTT connection? Looking forward to your comments.

    Best regards,
    Yanpeng Wu

  • Update: for the error code ENOBUFS 105 /* No buffer space available */, I tried to increase the mqtt client rx_buffer and tx_buffer big enough, but still with the same error.

    Should I increase the socket buffer CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE?
    The socket session was closed by receiving MQTT_EVT_DISCONNECT, is the session closed by mqtt server or local mqtt stack?

    Thank you very much.
Reply
  • Update: for the error code ENOBUFS 105 /* No buffer space available */, I tried to increase the mqtt client rx_buffer and tx_buffer big enough, but still with the same error.

    Should I increase the socket buffer CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE?
    The socket session was closed by receiving MQTT_EVT_DISCONNECT, is the session closed by mqtt server or local mqtt stack?

    Thank you very much.
Children
  • What happens before you get disconnected? E.g. are you sending data to or from the device?

    I can't find anywhere in the mqtt library that returns -ENOBUFS, so I think the error is coming from somewhere else, such as you rmodem driver.

    Can you enable logging further down in the IP stack to see if we can find where the error comes from?

  • Hi Didrik,

    Thank you for your reply. Before MQTT-Connection, I did some modem-test by sending UDP packets. Then init and connect MQTT, nothing MQTT data sent before MQTT-Connection.
    Maybe the error is from the socket or modem driver, just as you said. Could you tell me how to enable logging in IP stack? thank you very much.

    I tried three scenarios, and the results showed it was closely related to the modem(I used ublox SARA-R4 modem and the cellular modem driver, and communication works well), I summarized here:


    1. If not do the subscription, can connect and publish messages successfully forever.


    2. If do the subscription in the MQTT_EVT_CONNACK(just after connect success), it showed that the calling mqtt_subscribe() success, bu no MQTT_EVT_SUBACK received.
    and modem dropped one or two frames, then received a MQTT_EVT_DISCONNECT, trace as below:

    [00:00:26.106,201] <inf> mqtttest: mqtt_connect OK, rc is 0
    [00:00:26.410,339] <inf> mqtttest: do zsock_poll() 2s, ret = 1
    [00:00:26.410,491] <err> mqtttest: -----[mqtt_evt_handler]
    [00:00:26.410,522] <inf> mqtttest: -----[MQTT_EVT_CONNACK] MQTT client connected!
    [00:00:26.415,863] <err> mqtttest: -----[MQTT_EVT_CONNACK] Success to subscribe sparkplug NCMD and DCMD: 0  //------just call mqtt_subscribe() success, but no MQTT_EVT_SUBACK received
    [00:00:26.415,924] <wrn> sparkplugb: PUBLISH NODE BIRTH
    [00:00:26.431,457] <wrn> sparkplugb: PUBLISH DEVICE BIRTH
    [00:00:26.441,314] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:00:26.673,339] <wrn> modem_ppp: Dropped frame, no net_pkt available                         //------modem dropped frame
    [00:00:32.954,010] <wrn> modem_ppp: Dropped frame, no net_pkt available                         //------modem dropped frame
    [00:00:36.930,206] <err> mqtttest: -----[mqtt_evt_handler]
    [00:00:36.930,236] <inf> mqtttest: -----[MQTT_EVT_DISCONNECT] MQTT client disconnected -105     //------received MQTT_EVT_DISCONNECT, MQTT session was closed.
    [00:00:36.931,182] <wrn> main: NetworkCore - Hello 1                                            //------The error code is ENOBUFS 105	/* No buffer space available */
    [00:00:46.932,922] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:00:46.934,020] <wrn> main: NetworkCore - Hello 2

    3. If not do the subscription in the MQTT_EVT_CONNACK, after 20 successful publishing, then do the subscription, no MQTT_EVT_SUBACK received.
    and modem dropped some frames, then received an MQTT_EVT_DISCONNECT, trace as below:

    [00:03:17.068,511] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:03:17.075,256] <wrn> main: NetworkCore - Hello 18
    [00:03:27.077,026] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:03:27.083,374] <wrn> main: NetworkCore - Hello 19
    [00:03:37.085,113] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:03:37.090,270] <err> main: -----[MAIN] Success to subscribe sparkplug NCMD and DCMD: 0    //------just call mqtt_subscribe() success, but no MQTT_EVT_SUBACK received
    [00:03:37.090,301] <wrn> main: NetworkCore - Hello 20                                         //------these 20 publishing message can be received by other client.
    [00:03:37.817,718] <wrn> modem_ppp: Dropped frame, no net_pkt available                       //------modem start to drop some frames
    [00:03:47.092,071] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:03:47.100,219] <wrn> main: NetworkCore - Hello 21
    [00:03:47.534,118] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:47.534,393] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:48.049,682] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:48.691,741] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:49.570,770] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:50.929,687] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:52.939,666] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:55.969,879] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:03:57.102,020] <wrn> sparkplugb: PUBLISH DEVICE DATA                                      //------after that, the following publishing message can not be received by other client.
    [00:03:57.103,210] <wrn> main: NetworkCore - Hello 22                      
    [00:04:00.630,584] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:04:07.104,919] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:04:07.106,079] <wrn> main: NetworkCore - Hello 23
    [00:04:07.697,479] <wrn> modem_ppp: Dropped frame, no net_pkt available
    [00:04:17.107,818] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:04:17.108,123] <err> mqtttest: -----[mqtt_evt_handler]
    [00:04:17.108,154] <inf> mqtttest: -----[MQTT_EVT_DISCONNECT] MQTT client disconnected -128   //------received MQTT_EVT_DISCONNECT, MQTT session was closed.
    [00:04:17.109,161] <wrn> main: NetworkCore - Hello 24                                         //------BUT the error code is ENOTCONN 128  /* Socket is not connected */
    [00:04:27.110,900] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:04:27.111,999] <wrn> main: NetworkCore - Hello 25
    [00:04:37.113,830] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:04:37.114,929] <wrn> main: NetworkCore - Hello 26
    [00:04:47.116,668] <wrn> sparkplugb: PUBLISH DEVICE DATA

  • Update: I connected to test.mosquitto.org:1884 with the public username/password, no TLS.

    I attached the subscription and MQTT_event_handler code here, in case some errors were introduced here (The code is following the mqtt publisher sample). 

    #define SPARKPLUGB_NCMD         "spBv1.0/BDS/NCMD/Node1/#"
    #define SPARKPLUGB_DCMD         "spBv1.0/BDS/DCMD/Node1/#"
    
    int sparkb_sub_cmd(struct mqtt_client *const client)
    {
        struct mqtt_topic cmdTopic[2];
    	cmdTopic[0].topic.utf8 = (uint8_t *)SPARKPLUGB_NCMD;
    	cmdTopic[0].topic.size = strlen(SPARKPLUGB_NCMD);
    	cmdTopic[0].qos = MQTT_QOS_0_AT_MOST_ONCE;
    	cmdTopic[1].topic.utf8 = (uint8_t *)SPARKPLUGB_DCMD;
    	cmdTopic[1].topic.size = strlen(SPARKPLUGB_DCMD);
    	cmdTopic[1].qos = MQTT_QOS_0_AT_MOST_ONCE;
    
    	struct mqtt_subscription_list sub_param = {
    		.list = cmdTopic,
    		.list_count = 2,
    		.message_id = sys_rand32_get()
    	};
    
    	return mqtt_subscribe(client, &sub_param);
    }
    
    void mqtt_evt_handler(struct mqtt_client *const client, const struct mqtt_evt *evt)
    {
    	int err = -1;
    
    	LOG_ERR("-----[mqtt_evt_handler]");
    	switch (evt->type) {
    		case MQTT_EVT_PUBLISH:
    			LOG_INF("-----[MQTT_EVT_PUBLISH] Received NCMD or DCMD!");
    			sparkb_message_handler(client, evt);
    
    			break;
    		case MQTT_EVT_CONNACK:
    			if (evt->result != 0) {
    				LOG_ERR("-----[MQTT_EVT_CONNACK] MQTT connect failed %d", evt->result);
    				break;
    			}
    
    			g_connected = true;
    			LOG_INF("-----[MQTT_EVT_CONNACK] MQTT client connected!");
    
    			//Upon connect successful, subscribe to sparkplug NCMD and DCMD msgs. A production should handle MQTT connect failures.
    			//err = sparkb_sub_cmd(client);
    			if (err != 0) {
    				LOG_ERR("-----[MQTT_EVT_CONNACK] Failed to subscribe sparkplug NCMD and DCMD: %d", err);
    			} else {
    				LOG_ERR("-----[MQTT_EVT_CONNACK] Success to subscribe sparkplug NCMD and DCMD: %d", err);
    			}
    
    			break;
    		case MQTT_EVT_SUBACK:
    			LOG_ERR("-----[MQTT_EVT_SUBACK] received");
    
    			break;
    		case MQTT_EVT_DISCONNECT:
    			LOG_INF("-----[MQTT_EVT_DISCONNECT] MQTT client disconnected %d", evt->result);
    
    			g_connected = false;
    			clear_fds();
    
    			break;
    		case MQTT_EVT_PUBACK:
    			if (evt->result != 0) {
    				LOG_ERR("-----[MQTT_EVT_PUBACK] MQTT PUBACK error %d", evt->result);
    				break;
    			}
    
    			LOG_INF("-----[MQTT_EVT_PUBACK] PUBACK packet id: %u", evt->param.puback.message_id);
    			break;
    		case MQTT_EVT_PUBREC:
    			if (evt->result != 0) {
    				LOG_ERR("-----[MQTT_EVT_PUBREC] MQTT PUBREC error %d", evt->result);
    				break;
    			}
    
    			LOG_INF("-----[MQTT_EVT_PUBREC] PUBREC packet id: %u", evt->param.pubrec.message_id);
    			const struct mqtt_pubrel_param rel_param = {
    				.message_id = evt->param.pubrec.message_id
    			};
    
    			err = mqtt_publish_qos2_release(client, &rel_param);
    			if (err != 0) {
    				LOG_ERR("-----[MQTT_EVT_PUBREC] Failed to send MQTT PUBREL: %d", err);
    			}
    			break;
    		case MQTT_EVT_PUBCOMP:
    			if (evt->result != 0) {
    				LOG_ERR("-----[MQTT_EVT_PUBCOMP] MQTT PUBCOMP error %d", evt->result);
    				break;
    			}
    
    			LOG_INF("-----[MQTT_EVT_PUBCOMP] PUBCOMP packet id: %u", evt->param.pubcomp.message_id);
    			break;
    		case MQTT_EVT_PINGRESP:
    			LOG_INF("-----[MQTT_EVT_PINGRESP] PINGRESP packet");
    			break;
    		default:
    			break;
    	}
    }
    

  • Hi Support team,

    The latest update: After I set the CONFIG_NET_BUF_DATA_POOL_SIZE, CONFIG_NET_BUF_RX_COUNT, and CONFIG_NET_PKT_RX_COUNT big enough, there is no 'modem_ppp: Dropped frame, no net_pkt available' anymore.

    But for the MQTT sequences:
    1. the mqtt_connect() is ok and the MQTT_EVT_CONNACK can be received.
    2. and the mqtt_subscribe() can be called successfully, the return value is 0 which means the call is successful. But the subscription is with QoS1, no MQTT_EVT_SUBACK was received.
    3. When I used another MQTT client to publish data to the subscribed topic, nothing was received in mqtt_evt_handler().
    4. during the process, the mqtt_publish() is always successful, the published messages can be received from another client.

    During the above process, from the trace we can see the net_mqtt_rx() only be called once for the MQTT_PKT_TYPE_CONNACK.

    The trace is as below:

     

    *** Booting nRF Connect SDK v2.5.1 ***
    [00:00:00.003,021] <inf> mqtttest: Bring up network interface
    [00:00:00.003,112] <wrn> mqtttest: (1). Bring up network interface OK! ret = 0
    [00:00:00.003,112] <inf> mqtttest: Waiting for L4 connected
    [00:00:16.337,646] <dbg> net_mqtt_enc: connect_request_encode: Encoding Will Topic.
                                           73 70 42 76 31 2e 30 2f  42 44 53 2f 4e 44 45 41 |spBv1.0/ BDS/NDEA
                                           54 48 2f 4e 6f 64 65 31                          |TH/Node1         
    --- 14 messages dropped ---
    [00:00:16.337,677] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:0000001a cur:0x21003c99, end:0x21003d75
    [00:00:16.337,707] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0018 cur:0x21003c99, end:0x21003d75
    [00:00:16.337,738] <dbg> net_mqtt_enc: connect_request_encode: Encoding Will Message.
                                           54 68 65 20 77 69 6c 6c  20 70 61 79 6c 6f 61 64 |The will  payload
                                           20 6f 66 20 4e 44 45 41  54 48                   | of NDEA TH      
    [00:00:16.337,799] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:0000001c cur:0x21003cb3, end:0x21003d75
    [00:00:16.337,829] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001a cur:0x21003cb3, end:0x21003d75
    [00:00:16.337,860] <dbg> net_mqtt_enc: connect_request_encode: Encoding Username.
                                           72 77                                            |rw               
    [00:00:16.337,921] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000004 cur:0x21003ccf, end:0x21003d75
    [00:00:16.337,951] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0002 cur:0x21003ccf, end:0x21003d75
    [00:00:16.337,982] <dbg> net_mqtt_enc: connect_request_encode: Encoding Password.
                                           72 65 61 64 77 72 69 74  65                      |readwrit e       
    [00:00:16.338,043] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:0000000b cur:0x21003cd3, end:0x21003d75
    [00:00:16.338,073] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0009 cur:0x21003cd3, end:0x21003d75
    [00:00:16.338,165] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000064 cur:0, end:0
    --- 1 messages dropped ---
    [00:00:16.338,195] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:00:16.338,226] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:10 cur:0x21003c78, end:0x21003d75
    [00:00:16.338,287] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000064 cur:0x21003c79, end:0x21003d75
    [00:00:16.340,515] <inf> net_mqtt: Connect completed                             --------------------------------------------------MQTT connect OK
    [00:00:16.340,545] <inf> mqtttest: mqtt_connect OK, rc is 0
    [00:00:16.633,422] <inf> mqtttest: do zsock_poll() 2s, ret = 1
    [00:00:16.633,453] <dbg> net_mqtt: mqtt_input: (main): state:0x00000002
    [00:00:16.633,544] <dbg> net_mqtt_dec: unpack_uint8: (main): >> cur:0x21003d75, end:0x21003d77
    [00:00:16.633,575] <dbg> net_mqtt_dec: unpack_uint8: (main): << val:20
    [00:00:16.633,605] <dbg> net_mqtt_dec: packet_length_decode: (main): length:0x00000002
    [00:00:16.633,697] <dbg> net_mqtt_rx: mqtt_handle_packet: (main): [CID 0x21002f30]: Received MQTT_PKT_TYPE_CONNACK!
    [00:00:16.633,728] <dbg> net_mqtt_dec: unpack_uint8: (main): >> cur:0x21003d77, end:0x21003d79
    [00:00:16.633,789] <dbg> net_mqtt_dec: unpack_uint8: (main): << val:01
    [00:00:16.633,819] <dbg> net_mqtt_dec: unpack_uint8: (main): >> cur:0x21003d78, end:0x21003d79
    [00:00:16.633,850] <dbg> net_mqtt_dec: unpack_uint8: (main): << val:00
    [00:00:16.633,880] <dbg> net_mqtt_dec: connect_ack_decode: (main): [CID 0x21002f30]: session_present_flag: 1
    [00:00:16.633,911] <dbg> net_mqtt_rx: mqtt_handle_packet: (main): [CID 0x21002f30]: return_code: 0
    [00:00:16.633,911] <wrn> mqtttest: -----[mqtt_evt_handler]
    [00:00:16.633,941] <wrn> mqtttest: -----[MQTT_EVT_CONNACK] MQTT client connected!   -------------------------------------MQTT_EVT_CONNACK received
    [00:00:16.633,972] <wrn> main: -----[MAIN] Sleep 10s after mqtt connect, before publish birth
    [00:00:26.644,744] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x000002e5 cur:0, end:0
    --- 5 messages dropped ---
    [00:00:26.644,775] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 03
    [00:00:26.644,836] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c77, end:0x21003d75
    [00:00:26.644,866] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x000002e5 cur:0x21003c78, end:0x21003d75
    [00:00:26.644,897] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:00:26.704,803] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:00:26.704,833] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000
    [00:00:26.709,197] <wrn> sparkplugb: PUBLISH DEVICE BIRTH
    [00:00:26.714,782] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x00000020, Data size 0x00000196
    [00:00:26.714,843] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000022 cur:0x21003c7a, end:0x21003d75
    [00:00:26.714,904] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0020 cur:0x21003c7a, end:0x21003d75
    [00:00:26.714,935] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x000001b8
    [00:00:26.714,965] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x000001b8 cur:0, end:0
    [00:00:26.715,026] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 03
    [00:00:26.715,057] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c77, end:0x21003d75
    [00:00:26.715,118] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x000001b8 cur:0x21003c78, end:0x21003d75
    [00:00:26.715,179] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:00:26.715,393] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:00:26.715,423] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000-----------------------1st publish OK
    [00:00:26.717,712] <wrn> main: NetworkCore - Hello 1
    [00:00:36.717,803] <wrn> main: NetworkCore - Hello 2
    [00:00:46.717,895] <wrn> main: NetworkCore - Hello 3
    [00:00:56.717,987] <wrn> main: NetworkCore - Hello 4
    [00:01:06.718,109] <dbg> net_mqtt: mqtt_subscribe: (main): [CID 0x21002f30]:[State 0x06]: >> message id 0xe95b topic count 0x0002
    [00:01:06.718,200] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:e95b cur:0x21003c7a, end:0x21003d75
    [00:01:06.718,231] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000014 cur:0x21003c7c, end:0x21003d75
    [00:01:06.718,261] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0012 cur:0x21003c7c, end:0x21003d75
    [00:01:06.718,322] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:01 cur:0x21003c90, end:0x21003d75
    [00:01:06.718,353] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000014 cur:0x21003c91, end:0x21003d75
    [00:01:06.718,414] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:0012 cur:0x21003c91, end:0x21003d75
    [00:01:06.718,444] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:01 cur:0x21003ca5, end:0x21003d75
    [00:01:06.718,475] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x82 length:0x0000002c
    [00:01:06.718,536] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x0000002c cur:0, end:0
    [00:01:06.718,566] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:06.718,597] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:82 cur:0x21003c78, end:0x21003d75
    [00:01:06.718,627] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x0000002c cur:0x21003c79, end:0x21003d75
    [00:01:06.718,658] <dbg> net_mqtt: client_write: (main): [0x21002f30]: Transport writing 46 bytes.
    [00:01:06.720,275] <dbg> net_mqtt: client_write: (main): [0x21002f30]: Transport write complete.
    [00:01:06.720,306] <dbg> net_mqtt: mqtt_subscribe: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000----------------------subscribe() with QoS1 OK
    [00:01:06.720,336] <wrn> main: -----[MAIN] Success to subscribe sparkplug NCMD and DCMD: 0                   ------------------------But no Sub_ACK received
    [00:01:06.720,336] <wrn> main: NetworkCore - Hello 5
    [00:01:16.722,076] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:01:16.722,106] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x0000001f, Data size 0x00000054
    [00:01:16.722,167] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000021 cur:0x21003c7a, end:0x21003d75
    [00:01:16.722,229] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001f cur:0x21003c7a, end:0x21003d75
    [00:01:16.722,259] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x00000075
    [00:01:16.722,320] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0, end:0
    [00:01:16.722,351] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:16.722,412] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c78, end:0x21003d75
    [00:01:16.722,442] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0x21003c79, end:0x21003d75
    [00:01:16.722,473] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:01:16.725,067] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:01:16.725,097] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000  ----------------------The following publish is OK
    [00:01:16.725,982] <wrn> main: NetworkCore - Hello 6                                                          --------------------but can't receive the subscribed data
    [00:01:26.727,722] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:01:26.727,752] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x0000001f, Data size 0x00000054
    [00:01:26.727,844] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000021 cur:0x21003c7a, end:0x21003d75
    [00:01:26.727,874] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001f cur:0x21003c7a, end:0x21003d75
    [00:01:26.727,905] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x00000075
    [00:01:26.727,966] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0, end:0
    [00:01:26.727,996] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:26.728,027] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c78, end:0x21003d75
    [00:01:26.728,088] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0x21003c79, end:0x21003d75
    [00:01:26.728,118] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:01:26.730,682] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:01:26.730,743] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000
    [00:01:26.731,658] <wrn> main: NetworkCore - Hello 7
    [00:01:36.733,398] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:01:36.733,428] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x0000001f, Data size 0x00000054
    [00:01:36.733,520] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000021 cur:0x21003c7a, end:0x21003d75
    [00:01:36.733,551] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001f cur:0x21003c7a, end:0x21003d75
    [00:01:36.733,581] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x00000075
    [00:01:36.733,642] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0, end:0
    [00:01:36.733,673] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:36.733,703] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c78, end:0x21003d75
    [00:01:36.733,764] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0x21003c79, end:0x21003d75
    [00:01:36.733,795] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:01:36.736,389] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:01:36.736,419] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000
    [00:01:36.737,335] <wrn> main: NetworkCore - Hello 8
    [00:01:46.739,074] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:01:46.739,105] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x0000001f, Data size 0x00000054
    [00:01:46.739,196] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000021 cur:0x21003c7a, end:0x21003d75
    [00:01:46.739,227] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001f cur:0x21003c7a, end:0x21003d75
    [00:01:46.739,257] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x00000075
    [00:01:46.739,318] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0, end:0
    [00:01:46.739,349] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:46.739,410] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c78, end:0x21003d75
    [00:01:46.739,440] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0x21003c79, end:0x21003d75
    [00:01:46.739,471] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:01:46.741,973] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:01:46.742,004] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000
    [00:01:46.742,919] <wrn> main: NetworkCore - Hello 9
    [00:01:56.744,628] <wrn> sparkplugb: PUBLISH DEVICE DATA
    [00:01:56.744,659] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: >> Topic size 0x0000001f, Data size 0x00000054
    [00:01:56.744,750] <dbg> net_mqtt_enc: pack_utf8_str: (main): >> str_size:00000021 cur:0x21003c7a, end:0x21003d75
    [00:01:56.744,781] <dbg> net_mqtt_enc: pack_uint16: (main): >> val:001f cur:0x21003c7a, end:0x21003d75
    [00:01:56.744,812] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): << msg type:0x30 length:0x00000075
    [00:01:56.744,873] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0, end:0
    [00:01:56.744,903] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (main): Fixed header length = 02
    [00:01:56.744,934] <dbg> net_mqtt_enc: pack_uint8: (main): >> val:30 cur:0x21003c78, end:0x21003d75
    [00:01:56.744,995] <dbg> net_mqtt_enc: packet_length_encode: (main): >> length:0x00000075 cur:0x21003c79, end:0x21003d75
    [00:01:56.745,025] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport writing message.
    [00:01:56.747,619] <dbg> net_mqtt: client_write_msg: (main): [0x21002f30]: Transport write complete.
    [00:01:56.747,650] <dbg> net_mqtt: mqtt_publish: (main): [CID 0x21002f30]:[State 0x06]: << result 0x00000000

    Could you help give some hints? Thank you very much!

    Best regards,

    Yanpeng Wu

  • Hi, and sorry for the late reply.

    Have you tried to send data with QoS1 (or 2)?

    Are you calling mqtt_input in your application?

    Or otherwise checking for incoming packets other than the CONNACK?

Related