MQTT message max size?

I’m using the MQTT binding to read messages from a Sonoff ESP8285 device. This device runs Tasmota and reads out my P1 Smartmeter and Solaredge Inverter (through Modbus TCP). It sends out a JSON message to Mosquitto MQTT broker and the broker is connected to Openhab through the MQTT binding. Works flawless. Message is structured like:

{ 
    Time: "xx",
    P1: { item1: yy, Item2: zz, ...},
    SOLAR:{ item1: dd, item2: ff, ...} 
}

Yesterday I added some additional data items from the inverter to the datagram and suddenly the P1 meter stopped updating. With the debug logging set for the MQTT binding, it seemed the first part of the MQTT message was truncated. For now I fixed it using shorter ‘item’ names, but for codereadability this isn’t the best thing to do.

Is there a maximum MQTT message size for the binding? And if so, is it configurable?

The MQTT protocol sets a maximum of 256MB per payload, which seems waaaay more than your example! :wink:
My setup includes “massive” payloads of a few KBs, so I don’t see a limitation on both broker and openHAB side. Did you intercept the messages to make sure, they are not truncated at the source? Something like MQTT Explorer?
What I don’t know is, if Tasmota itself restricts the size of payloads due to limitations of the ESP8285 chip?

1 Like

Are you sure that the limitation isn’t on the ESP side? I’ve encountered a similar problem a while ago when coding on some Arduino-like boards and using a MQTT library (this one: GitHub - hirotakaster/MQTT: MQTT for Photon, Spark Core). There was a define in MQTT.h which set the maximum size of a MQTT package in bytes:

#define MQTT_MAX_PACKET_SIZE 255

1 Like

I do see the entire message, however it seems there is an hidden newline character or something like that, exactly at the spot where the message is truncated. I noticed it when copying the message to this reply…

{"Time":"2024-09-09T20:36:20","P1
":{"act_use":583,"act_ret":0,"curr_tar":2,"tot_use_h":19076.217,"tot_use_l":20216.922,"tot_use":39293.139,"tot_ret_h":53.374,"tot_ret_l":80.235,"tot_ret":133.609,"act_use_L1":385,"act_use_L2":61,"act_use_L3":125,"act_ret_L1":0,"act_ret_L2":0,"act_ret_L3":0,"act_volt_L1":235.2,"act_volt_L2":235.7,"act_volt_L2":236.1,"tot_gas":8881.165},"SOLAR":{"I_AC_Current":0,"I_AC_CurrentA":0,"I_AC_CurrentB":0,"I_AC_CurrentC":0,"I_AC_Current_SF":-2,"I_AC_VoltageAN":2355,"I_AC_VoltageBN":2363,"I_AC_VoltageCN":2364,"I_AC_Voltage_SF":-1,"I_AC_Power":0,"I_AC_Power_SF":0,"I_AC_Frequency":5001,"I_AC_Frequency_SF":-2,"I_AC_VA":0,"I_AC_VA_SF":0,"I_AC_VAR":0,"I_AC_VAR_SF":0,"I_AC_PF":0,"I_AC_PF_SF":0,"I_AC_Energy_WH":194966,"I_AC_Energy_WH_SF":0,"I_DC_Current":0,"I_DC_Current_SF":0,"I_DC_Voltage":5,"I_DC_Voltage_SF":-1,"I_DC_Power":0,"I_DC_Power_SF":0,"I_Temp_Sink":3081,"I_Temp_SF":-2,"I_Status":2,"I_Status_Vendor":0}}

Thanks for the advice, I’ll investigate where and how this happens!