ESP32 MQTT Paket size

msawaftah
Posts: 5
Joined: Wed Oct 06, 2021 2:38 pm

ESP32 MQTT Paket size

Postby msawaftah » Wed Nov 17, 2021 1:21 pm

Hello all,

I have a mqtt applecation using esp32 board.

I have 2 questions:

1) In which document can I find information about the MTU WIFI size of an ESP32? I have googled that and in the other forums they say 1500 Byte but I cant find the Information in the datasheet or in a specific document.

2) The maximum mqtt message size is 256 MB that means we can send 256 MB messages with mqtt but at the same time we are limited by the MTU size so that we can max send 1500 Byte messages. Do I understand this correctly?


Thanks in advance

regards
msawaf

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 MQTT Paket size

Postby Sprite » Thu Nov 18, 2021 3:02 am

Yes. Note you can send packets larger than 1500 bytes, they'll simply get sent in chunks of 1500 bytes and reassembled automatically on the other side.

msawaftah
Posts: 5
Joined: Wed Oct 06, 2021 2:38 pm

Re: ESP32 MQTT Paket size

Postby msawaftah » Thu Nov 18, 2021 12:00 pm

Yes. Note you can send packets larger than 1500 bytes, they'll simply get sent in chunks of 1500 bytes and reassembled automatically on the other side.
so no data will be lost right?

But I think getting the data in chunks and reassembled the data will slow dow the speed connection is that right?

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 MQTT Paket size

Postby Sprite » Fri Nov 19, 2021 1:43 am

No data will be lost. Not sure what you compare the speed to when you say 'will slow down the speed'... there's no way to get a greater MTU as it's a property of the WiFi protocol, not specifically of the ESP32.

MichaelS
Posts: 46
Joined: Mon Jul 08, 2024 12:08 am

Re: ESP32 MQTT Paket size

Postby MichaelS » Mon May 26, 2025 7:16 am

I have not found this to be the case. If my MQTT packet size is larger than MTU, the transmission fails.
Am I missing something as this is what I really want?

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 MQTT Paket size

Postby Sprite » Mon May 26, 2025 5:19 pm

Could be that fragmenting and reassembly is somehow disabled in the LWIP config, you could check menuconfig to see if that is the case.

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 MQTT Paket size

Postby MicroController » Mon May 26, 2025 8:50 pm

If my MQTT packet size is larger than MTU, the transmission fails.
1. "fails" = what? Any error code/message?
2. What maximum acceptable MQTT packet size does the server announce?

leschge
Posts: 44
Joined: Fri May 06, 2022 1:38 pm

Re: ESP32 MQTT Paket size

Postby leschge » Tue Jan 27, 2026 3:13 pm

Yes. Note you can send packets larger than 1500 bytes, they'll simply get sent in chunks of 1500 bytes and reassembled automatically on the other side.
I am having a strange problem. From the doc:
MQTT_EVENT_DATA: The client has received a publish message. The event data contains: message ID, name of the topic it was published to, received data and its length. For data that exceeds the internal buffer, multiple MQTT_EVENT_DATA events are posted and current_data_offset and total_data_len from event data updated to keep track of the fragmented message.
For
esp_mqtt5_connection_property_config_t.maximum_packet_size I set 2 MB. Then why do I get:
mqtt5_client: Connect maximum_packet_size property is over buffer_size(4096), Please first change it
Because I thought esp_mqtt_client_config_t.buffer.size was the internal buffer (that I set to 4KB)


Edit: Created this issue ticket: https://github.com/espressif/esp-mqtt/issues/319

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 MQTT Paket size

Postby MicroController » Wed Jan 28, 2026 9:35 am

You can set the "buffer size" via esp_mqtt_client_init() (esp_mqtt_client_config_t::buffer::size).

leschge
Posts: 44
Joined: Fri May 06, 2022 1:38 pm

Re: ESP32 MQTT Paket size

Postby leschge » Wed Jan 28, 2026 12:23 pm

You can set the "buffer size" via esp_mqtt_client_init() (esp_mqtt_client_config_t::buffer::size).
Thats correct, but messages to be received can be larger than the buffer defined in esp_mqtt_client_init.

Who is online

Users browsing this forum: Google [Bot] and 6 guests