MQTT can't get the full data for subscribed topics

Hi, 

I'm using nRF9160, NCS2.2.0, and using serial_lte_modem sample.

Recently, I have developed a program for MQTT, and I encountered the following phenomenon.

1. nRF9160 subscribed to a topic.

2. I send some data to the topic.

3. When the size of this data exceeds 670 Bytes, nRF9160 only read a part of this data, and the rest of this data is unreadable.

I debug the code to locate the following problem:

In file slm_at_mqtt.c, path: ${NCS_ROOT}/nrf/applications/serial_lte_modem/src/mqtt_c/slm_at_mqtt.c:92

do {
		ret = mqtt_read_publish_payload(c, rsp_buf, sizeof(rsp_buf));
		if (ret > 0) {
			data_send(rsp_buf, ret);
			size_read += ret;
		}
	} while (ret >= 0 && size_read < evt->param.publish.message.payload.len);

Firstly, I calll mqtt_read_publish_payload() to get this data, the 'ret' return 570, it is means i get 570Bytes from MQTT, but I send size is 670 Bytes.

Then, continue reading data, but the 'ret' return a negative error code(-11).

Finally, the MQTT disconnect.

How do I get the rest of this data?

Best Regards,

Yang Hu

Parents Reply Children
  • Harvey Zheng said:
    If you are sending more than 256 bytes of data to the slm via the serial port, you need to enter data mode first and then exit data mode after sending the data.

    Are you sure that you need to manually set it to data mode when using AT#XMQTTPUB? It says in the documentation that it will be set to data mode automatically when using MQTT publish.

  • When AT#XMQTTPUB does not carry a message, slm will automatically enter data mode.

    Maybe my description here is misleading. When the device subscribes to the /cgw/cmd-request/cgw/351358811068466/cmd-request topic, I used MQTTX to post data to this topic and the device is having this problem when receiving it.

    Topic: cgw/cmd-request/cgw/351358811068466/cmd-request

    Data(Hex): 24000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f000300000000000324000000090000003f0003000000000003

  • Okay, now it makes more sense. I will try to reproduce it then.

  • I tried to reproduce it now the way you described it. First I tried sending ~400 bytes, and then received the data successfully in the terminal. Then when I tried with 800, I get this response

    Then it gets disconnected from the broker it seems. Is this the response you got as well?

  • Yes, my test also disconnects here. Here is my complete test log

    # SEGGER J-Link RTT Viewer V7.54c Terminal Log File
    # Compiled: 14:02:36 on Sep 20 2021
    # Logging started @ 06 Feb 2023 09:59:41
    00> [00:00:00.485,839] <inf> nrf_modem_lib_trace: Trace thread ready
    00> [00:00:00.487,243] <inf> nrf_modem_lib_trace: Trace level override: 2
    00> *** Booting Zephyr OS build v3.2.99-ncs1 ***
    00> [00:00:00.487,365] <dbg> slm: main: RR: 0x00000001
    00> [00:00:00.491,699] <inf> slm: Serial LTE Modem
    00> [00:00:00.493,957] <dbg> slm_at_host: slm_at_host_init: UART baud: 115200 d/p/s-bits: 3/0/1 HWFC: 0
    00> [00:00:00.493,957] <dbg> slm_at_host: slm_uart_configure: Set uart baudrate to: 115200, hw flow control 0
    00> [00:00:00.591,613] <dbg> slm_fdl: slm_at_fdl_init: FDL init...
    00> [00:00:00.591,705] <dbg> slm_at_host: rsp_send: TX
    00>                                       52 65 61 64 79 0d 0a                             |Ready..          
    00> [00:00:00.591,766] <dbg> slm_fota: slm_fota_post_process: FOTA result 0,0,0
    00> [00:00:00.594,665] <inf> slm_at_host: at_host init done
    00> [00:00:13.889,953] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54                                            |AT               
    00> [00:00:13.896,514] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:13.896,606] <dbg> slm_at_host: rsp_send: TX
    00>                                       4f 4b 0d 0a                                      |OK..             
    00> [00:00:17.651,977] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 25 58 53 59 53 54  45 4d 4d 4f 44 45 3d 30 |AT%XSYST EMMODE=0
    00>                                       2c 31 2c 30 2c 30                                |,1,0,0           
    00> [00:00:17.652,465] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:00:17.660,430] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:17.660,522] <dbg> slm_at_host: rsp_send: TX
    00>                                       4f 4b 0d 0a                                      |OK..             
    00> [00:00:19.123,718] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 2b 43 45 52 45 47  3d 35                   |AT+CEREG =5      
    00> [00:00:19.124,206] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:00:19.130,371] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:19.130,462] <dbg> slm_at_host: rsp_send: TX
    00>                                       4f 4b 0d 0a                                      |OK..             
    00> [00:00:20.427,429] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 2b 43 53 43 4f 4e  3d 31                   |AT+CSCON =1      
    00> [00:00:20.427,917] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:00:20.434,112] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:20.434,173] <dbg> slm_at_host: rsp_send: TX
    00>                                       4f 4b 0d 0a                                      |OK..             
    00> [00:00:26.571,441] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 2b 43 46 55 4e 3d  31                      |AT+CFUN= 1       
    00> [00:00:26.571,929] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:00:26.603,973] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:26.604,034] <dbg> slm_at_host: rsp_send: TX
    00>                                       4f 4b 0d 0a                                      |OK..             
    00> [00:00:42.305,084] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:42.305,206] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 45 52 45 47 3a 20  32 2c 22 31 44 32 39 22 |+CEREG:  2,"1D29"
    00>                                       2c 22 30 44 31 43 43 32  34 31 22 2c 39 0d 0a    |,"0D1CC2 41",9.. 
    00> [00:00:44.285,369] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:44.285,461] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  31 0d 0a                |+CSCON:  1..     
    00> [00:00:46.452,697] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:00:46.452,758] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 45 52 45 47 3a 20  31 2c 22 31 44 32 39 22 |+CEREG:  1,"1D29"
    00>                                       2c 22 30 44 31 43 43 32  34 31 22 2c 39 2c 2c 2c |,"0D1CC2 41",9,,,
    00>                                       22 31 31 31 30 30 30 30  30 22 2c 22 31 31 31 30 |"1110000 0","1110
    00>                                       30 30 30 30 22 0d 0a                             |0000"..          
    00> [00:01:02.253,356] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 23 58 4d 51 54 54  43 4f 4e 3d 31 2c 22 4d |AT#XMQTT CON=1,"M
    00>                                       79 4d 51 54 54 2d 43 6c  69 65 6e 74 2d 49 44 22 |yMQTT-Cl ient-ID"
    00>                                       2c 22 6d 69 6e 65 77 22  2c 22 6d 69 6e 65 77 31 |,"minew" ,"minew1
    00>                                       32 33 22 2c 22 34 37 2e  31 31 35 2e 35 38 2e 39 |23","47. 115.58.9
    00>                                       30 22 2c 32 38 38 33                             |0",2883          
    00> [00:01:02.253,845] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:01:04.620,483] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 4f 4b 0d 0a                                |..OK..           
    00> [00:01:05.070,953] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 30 2c 30 |..#XMQTT EVT: 0,0
    00>                                       0d 0a                                            |..               
    00> [00:01:08.418,884] <dbg> slm_at_host: cmd_send: RX
    00>                                       41 54 23 58 4d 51 54 54  53 55 42 3d 22 2f 63 67 |AT#XMQTT SUB="/cg
    00>                                       77 2f 63 6d 64 2d 72 65  71 75 65 73 74 2f 63 67 |w/cmd-re quest/cg
    00>                                       77 2f 33 35 31 33 35 38  38 31 31 30 36 38 34 36 |w/351358 81106846
    00>                                       36 2f 63 6d 64 2d 72 65  71 75 65 73 74 22 2c 31 |6/cmd-re quest",1
    00> [00:01:08.419,372] <dbg> slm_at_host: uart_callback: RX_DISABLED
    00> [00:01:08.420,288] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 4f 4b 0d 0a                                |..OK..           
    00> [00:01:09.673,187] <dbg> slm_mqtt: mqtt_evt_handler: SUBACK packet id: 1
    00> [00:01:09.673,278] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 37 2c 30 |..#XMQTT EVT: 7,0
    00>                                       0d 0a                                            |..               
    00> [00:01:45.346,252] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:01:45.346,313] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  30 0d 0a                |+CSCON:  0..     
    00> [00:02:10.819,824] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:02:10.819,885] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  31 0d 0a                |+CSCON:  1..     
    00> [00:02:11.153,106] <dbg> slm_mqtt: mqtt_evt_handler: PINGRESP packet
    00> [00:02:11.153,167] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 39 2c 30 |..#XMQTT EVT: 9,0
    00>                                       0d 0a                                            |..               
    00> [00:02:28.644,134] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  4d 53 47 3a 20 34 38 2c |..#XMQTT MSG: 48,
    00>                                       31 0d 0a                                         |1..              
    00> [00:02:28.644,226] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       2f 63 67 77 2f 63 6d 64  2d 72 65 71 75 65 73 74 |/cgw/cmd -request
    00> [00:02:28.645,904] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:02:28.650,177] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       24                                               |$                
    00> [00:02:28.650,390] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:02:28.651,245] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 32 2c 30 |..#XMQTT EVT: 2,0
    00>                                       0d 0a                                            |..               
    00> [00:02:49.882,476] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:02:49.882,537] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  30 0d 0a                |+CSCON:  0..     
    00> [00:03:08.932,800] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:03:08.932,861] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  31 0d 0a                |+CSCON:  1..     
    00> [00:03:09.222,106] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  4d 53 47 3a 20 34 38 2c |..#XMQTT MSG: 48,
    00>                                       33 33 35 0d 0a                                   |335..            
    00> [00:03:09.222,198] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       2f 63 67 77 2f 63 6d 64  2d 72 65 71 75 65 73 74 |/cgw/cmd -request
    00> [00:03:09.224,060] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:03:09.228,363] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       20 05 c8 00 4d a3 01 00  24 34 6c 0c 05 00 9d 9e | ...M... $4l.....
    00> [00:03:09.228,576] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:03:09.258,453] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 32 2c 30 |..#XMQTT EVT: 2,0
    00>                                       0d 0a                                            |..               
    00> [00:03:26.777,374] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  4d 53 47 3a 20 34 38 2c |..#XMQTT MSG: 48,
    00>                                       36 37 31 0d 0a                                   |671..            
    00> [00:03:26.777,435] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       2f 63 67 77 2f 63 6d 64  2d 72 65 71 75 65 73 74 |/cgw/cmd -request
    00> [00:03:26.779,357] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:03:26.783,721] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       20 05 c8 00 4d a3 01 00  24 34 6c 0c 05 00 9d 9e | ...M... $4l.....
    00> [00:03:26.783,905] <err> slm_mqtt: mqtt_read_publish_payload ret: -11
    00> [00:03:26.783,935] <dbg> slm_at_host: data_send: TX-DATA
    00>                                       0d 0a                                            |..               
    00> [00:03:26.841,400] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 32 2c 30 |..#XMQTT EVT: 2,0
    00>                                       0d 0a                                            |..               
    00> [00:03:26.841,491] <err> slm_mqtt: ERROR: mqtt_input -16
    00> [00:03:26.842,163] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a 23 58 4d 51 54 54  45 56 54 3a 20 31 2c 2d |..#XMQTT EVT: 1,-
    00>                                       31 31 33 0d 0a                                   |113..            
    00> [00:03:26.843,078] <inf> slm_mqtt: MQTT thread terminated
    00> [00:03:48.180,419] <dbg> slm_at_host: rsp_send: TX
    00>                                       0d 0a                                            |..               
    00> [00:03:48.180,541] <dbg> slm_at_host: rsp_send: TX
    00>                                       2b 43 53 43 4f 4e 3a 20  30 0d 0a                |+CSCON:  0..     
    
    # Logging stopped @ 06 Feb 2023 10:03:37
    

Related