corbanmailloux / esp-mqtt-rgb-led

MQTT RGB LEDs Using JSON for Home Assistant
MIT License
270 stars 74 forks source link

MQTT packet size #60

Open jaffons opened 4 years ago

jaffons commented 4 years ago

Hello. I have implemented this to ESP32 with simple cp-paste from example sketches. Basically I changed:

include to #include

analog.Writes to corresponding ledc library.

JSON library is intact as it should be.

However for some reason callback() function isn't called if JSON message is too long. 6 lines/objects is fine, 7 or more isn't.

I did found that message goes nicely to thru MQTT broker and that it doesn't matter which objects are in the payload. Other than that I'm out of ideas.

corbanmailloux commented 4 years ago

I haven't seen this behavior, but I also haven't tested this code on an ESP32.

Have you tried increasing the JSON buffer size by increasing the value here?: https://github.com/corbanmailloux/esp-mqtt-rgb-led/blob/master/mqtt_esp8266_light/mqtt_esp8266_light.ino#L27

jaffons commented 4 years ago

Yeah I tried to increase JSON buffer also. Even if the JSON buffer is too short this shouldn't have effect on callback(), I think.

MQTT default message size is 128 bytes which might be an issue, and you can't define it in sketch.

I'll give this a try: https://github.com/knolleary/pubsubclient/issues/110#issuecomment-460065858 e. I wasn't able to make this work tonight :(

jaffons commented 4 years ago

So indeed I made local change to PubSubClient.h line 29

define MQTT_MAX_PACKET_SIZE 512

...And now it works as intented. This problems seems to be known for long.

I wonder how you've not seen this before because this is not ESPxxx relevant issue and mqtt packet is almost always >126 bytes long..