Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the max size for publish in esp8266 #109

Closed
myie9 opened this issue Feb 4, 2018 · 2 comments · Fixed by #166
Closed

What's the max size for publish in esp8266 #109

myie9 opened this issue Feb 4, 2018 · 2 comments · Fixed by #166

Comments

@myie9
Copy link

myie9 commented Feb 4, 2018

When publish long message as below. It would crash after receive some subscribe.
But it' ok if publish short message. What's the max size for publish in esp8266?

String strConfig = "{"iQiTiYuZhi":" + String(g_iQiTiYuZhi) + ", "iKeepAlertTime":" + String(g_iKeepAlertTime) + ", "iAlertWhenYouRen":" + String(g_iAlertWhenYouRen)
+ ", "YouRenJudgeInterval":" + String(g_YouRenJudgeInterval) + ", "qiTiAlertInterval":" + String(g_qiTiAlertInterval) + ", "iGapAlertPubUpdate":" + String(g_iGapAlertPubUpdate)
+ ", "strPhone":" + g_strPhone + ", "iHideUrl":" + String(g_iHideUrl) + ", "strQQ":" + g_strQQ + ", "iVer":" + String(g_iVer)

@flavio-fernandes
Copy link
Contributor

flavio-fernandes commented Dec 24, 2019

The max size is:

// Largest full packet we're able to send.
// Need to be able to store at least ~90 chars for a connect packet with full
// 23 char client ID.
#define MAXBUFFERSIZE (150)

After spending a long time pulling my hair to understand why I was
hitting a panic when attempting to read from my registered
subscriptions, I found out that the subscriptions member of the
Adafruit_MQTT instance was corrupted. :(

Turns out the memory corruption was caused by my publish
call, where the payload I was providing was bigger than the
allocated space in the buffer for construction of the packet.

flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 24, 2019
Fixes adafruit#109

After spending a long time pulling my hair to understand why I was
hitting a panic when attempting to read from my registered
subscriptions, I found out that the subscriptions member of the
Adafruit_MQTT instance was corrupted. :(

Turns out the memory corruption was caused by my publish
call, where the payload I was providing was bigger than the
allocated space in the buffer for construction of the packet
(see buffer[MAXBUFFERSIZE]).

To protect myself from ever making this mistake again, I am
proposing a simple logic in publishPacket where instead of
silently corrupting memory, the code uses as much payload
as it can fit in the available space. By seeing the
truncated payload, user can decide whether he/she should
1)break it up into different topics, 2) put the payload on
a diet, or 3) increase MAXBUFFERSIZE.
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 24, 2019
Fixes adafruit#109
Fixes adafruit#122

After spending a long time pulling my hair to understand why I was
hitting a panic when attempting to read from my registered
subscriptions, I found out that the subscriptions member of the
Adafruit_MQTT instance was corrupted. :(

Turns out the memory corruption was caused by my publish
call, where the payload I was providing was bigger than the
allocated space in the buffer for construction of the packet
(see buffer[MAXBUFFERSIZE]).

To protect myself from ever making this mistake again, I am
proposing a simple logic in publishPacket where instead of
silently corrupting memory, the code uses as much payload
as it can fit in the available space. By seeing the
truncated payload, user can decide whether he/she should
1)break it up into different topics, 2) put the payload on
a diet, or 3) increase MAXBUFFERSIZE.
@flavio-fernandes
Copy link
Contributor

@myie9 : Please take a look at #166 and see if that addresses your issue.

flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 25, 2019
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 25, 2019
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 25, 2019
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Dec 25, 2019
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Aug 29, 2020
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Aug 29, 2020
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Aug 29, 2020
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Apr 2, 2021
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Apr 2, 2021
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
flavio-fernandes added a commit to flavio-fernandes/Adafruit_MQTT_Library that referenced this issue Apr 2, 2021
Avoid memory corruption from happening when data payload provided
in Adafruit_MQTT::publishPacket is greater than MAXBUFFERSIZE.

In order to do that, a helper function is being added to calculate
how much space is available for the payload after subtracting what
is used as the header.

Pull request adafruit#166
Fixes adafruit#109
Fixes adafruit#122

Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants