Data dropped when sending large payload via AT#XMQTTPUB

I am attempting to stream data in chunks of 65535 bytes from the nRF9160 using data mode from the 2.6.1 version of serial_lte_modem sample code. The nRF9160 receives AT commands via UART. The following are the relevant configurations pertaining to UART and data mode reception

CONFIG_SLM_DATAMODE_URC=y
CONFIG_SLM_DATAMODE_BUF_SIZE=65536
CONFIG_SLM_UART_RX_BUF_SIZE=8192
CONFIG_SLM_UART_RX_BUF_COUNT=4
CONFIG_SLM_DATAMODE_TERMINATOR="+++"

I am sending the following messages to start data mode, send data, and terminate data mode. This occurs after connecting to the MQTT broker and setting the data mode timeout to 10,000 ms. These three UART transfers occur until all data is sent.

# Starts data mode at QoS0
const char * start_msg = "AT#XMQTTPUB="topic","",0,0";
nrf_status = nrf9160_interface.transmit((uint8_t *)start_msg, prefix_length);

# Sends binary data at chunks of 0xFFFF
nrf_status = nrf9160_interface.transmit((uint8_t *)data, CHUNK_SIZE_BYTES);

# Ends data mode w/ default terminator ("+++")
nrf_status = nrf9160_interface.transmit((uint8_t *)"+++", 3);

The following is the response fro the nRF9160 when sending the initial 2 chunks

*** Booting nRF Connect SDK 3758bcbfa5cd ***
I: Starting bootloader
I: Image index: 0, Swap type: none
I: Bootloader chainload address offset: 0x10000
[Sec Thread] Secure image initializing!
Booting TF-M v2.0.0
*** Booting nRF Connect SDK 3758bcbfa5cd ***
[00:00:00.500,183] <inf> slm: lib_modem init: 0
[00:00:00.512,481] <inf> mcuboot_util: Image index: 0, Swap type: none
[00:00:00.519,683] <inf> slm: Serial LTE Modem
[00:00:00.524,993] <inf> slm_uart_handler: UART baud: 460800 d/p/s-bits: 3/0/1 HWFC: 0
[00:00:00.533,691] <inf> slm_at_host: at_host init done
+CGEV: ME PDN ACT 0,0
+CNEC_ESM: 50,0
[00:00:11.256,439] <inf> net_mqtt: Connect completed
[00:00:12.304,016] <inf> slm_at_host: Enter datamode
[00:00:13.656,341] <inf> slm_at_host: Raw send: size_send: 65535, data 0x2002b630
[00:00:14.047,180] <wrn> slm_uart_handler: Disabling UART RX: No free buffers.
[00:00:14.137,084] <wrn> slm_uart_handler: Disabling UART RX: No free buffers.
[00:00:17.322,509] <inf> slm_mqtt: datamode send: 0
[00:00:17.328,338] <inf> slm_at_host: Raw send: size_send: 0, data 0x2002b630
[00:00:17.336,486] <inf> slm_at_host: Exit datamode
[00:00:17.342,651] <inf> slm_at_host: Enter datamode
[00:00:18.436,798] <inf> slm_at_host: Raw send: size_send: 65531, data 0x2002b630
[00:00:18.845,733] <wrn> slm_uart_handler: Disabling UART RX: No free buffers.
[00:00:18.935,607] <wrn> slm_uart_handler: Disabling UART RX: No free buffers.
[00:00:34.150,939] <inf> slm_mqtt: datamode send: 0
[00:00:34.156,738] <inf> slm_at_host: Raw send: size_send: 0, data 0x2003b62b
[00:00:34.164,794] <inf> slm_at_host: Exit datamode

The initial 65535 chunks are successfully sent, but once sent UARTs are disabled due to there being no free buffers (unable to perform rx_buf_alloc() from slm_uart_handler.c). Here is where I am suspecting that the next MQTT publish is losing 4 bytes as seen from the 65531 bytes sent in the second publish. I am also unsure why there is an additional raw_send() of size 0.

Is my suspicion that the MQTT publish is losing data due to the disabled RX UARTs correct? If so, what can I do to prevent this from occurring? Is the current data mode usage method correct? 

Related