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

mqtt_publish in new SDK cannot handle large payloads.

I'd previously run into this problem with mqtt_publish not being able to handle large payloads, larger than approximately 2k.

At the time, the suggested workaround was to patch mqtt_client_tls_write in mqtt_transport_socket_tls.c.

The patched version of the function looks like:

int mqtt_client_tls_write(struct mqtt_client *client, const u8_t *data,
			  u32_t datalen)
{
	u32_t offset = 0U;
	int ret;

	while (offset < datalen) {
		ret = send(client->transport.tls.sock, data + offset,
            MIN(1024,(datalen - offset)), 0);
		if (ret < 0) {
			return -errno;
		}

		offset += ret;
	}

	return 0;
}

It looks like there's a new config option CONFIG_NRF91_SOCKET_SEND_SPLIT_LARGE_BLOCKS which might render this change unneeded.

However, there's also a change to mqtt_publish in mqtt.c, which now uses client_write_msg instead of client_write. I didn't dig all they way through it, but without CONFIG_NRF91_SOCKET_SEND_SPLIT_LARGE_BLOCKS set causes mqtt_publish to return -22. If you set CONFIG_NRF91_SOCKET_SEND_SPLIT_LARGE_BLOCKS then it appears to work, but never actually sends the data.

For time being, I've reverted the changes to mqtt_publish, but it would be better if mqtt_publish worked correctly.

Related