-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Function to change the MQTT packet size outside of the library #110
Comments
+1, I'm using PlatformIO which keeps a common cache for all libraries and this is presenting a big problem for me. An easier way to configure this would be great. |
I need this too... 128 seems far too low. We are using DeviceHub. Based on the long API key and Devic ID length you easily exceed 128. Thanks :-) |
So the reason it's fixed is because we preallocate the memory at compile time. Given the limited memory of the original devices this targeted, I felt it was import to do this so potential memory issues could be caught then, and not at runtime (which are so much harder to debug). I also didn't want to set a default value that meant a lot of memory was pegged but went unused if you were only sending/receiving simple messages. Any default value will have pros and cons. Perhaps the answer is to move to fully dynamic memory allocation, but isn't a straight forward choice. |
Could it be made optional with an ifdef so it can be defined at the preprocessor level perhaps, at least? |
I never found a way to allow an arduino sketch to ifdef its own value to override the library - all to do with how the Arduino tool chain preprocesses the app's files. |
I use PlatformIO, which can do that (or, if not, I'm sure @ivankravets will approve a PR from me for it). |
@knolleary what is problem with #ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
#endif PlatformIO users have full control of build process and can pass own build_flags. For example, [env:myboard]
platform = espressif
framework = arduino
board = nodemcu
build_flags = -DMQTT_MAX_PACKET_SIZE=256 |
@ivankravets because the last two times I've tried that approach it hasn't worked. The arduino tool chain includes library headers before it includes your sketch. So you cannot #define something in a sketch and have it picked up in the library. |
The above would be ideal, and preserve backwards-compatibility. |
@knolleary The build flags are included in the compiler command line, so they would take precedence. They aren't defined in the sketch. |
Ahh - sorry, read the rest of your comment.... so in the PlatformIO environment I can see how that would help. Doesn't address it for everyone else... but would be useful applied to all the customizable #defines. |
@knolleary I think that's a good compromise, since it doesn't hurt Arduino IDE users but benefits PlatformIO users. |
I would certainly accept a PR that added that - as long as it applies to the other #defines and not just the packet size one. |
@knolleary Please don't mix Arduino IDE and it's builder with PlatformIO. PlatformIO uses only source code of Arduino framework core for AVR/SAM. |
Should I make it? |
@ivankravets Too late! #119. |
Thanks @skorokithakis - will get it merged later today. |
@skorokithakis I'm not sure that need to redefine |
@ivankravets That's the supported version for the client, the actual versions are defined a few lines above that. |
@knolleary thanks you too. Could you merge my PR with |
+1 on that as well, so we also get this PR autoupdated in PlatformIO. |
@knolleary Any news on this? |
Sorry, been flat out with work and have been at a conference yesterday/today. Will try to get to it all this weekend. |
Sounds great, thank you! |
I think that one is solved - at least i can see it in the code :) |
It's solved for platorms that allow you to provide #defines outside of the sketch. That doesn't solve it for the Arduino environment. Still need to decide if we want to provide a programmatic wy for a sketch to set the packet size. |
@knolleary thanks - you are right, i just looked through my platformio glasses ;) Sorry! |
I would indeed go for the programmatic way to define the packet size - would be really useful for other libraries that uses this one :) |
Hello, any news on this issue? We'd really need it for our aREST library. Thanks! |
Use a template parameter for the buffer size, and then provide a default instantiation that uses the pre-existing |
I could not find a way which wasn't completely ugly using template parameter. Issue is that each and every method needs to become a template on the buffer size, which is a lot of distraction and complication. And one needs to the templated class, and then typedef an explicit instantiation for compatibility with existing code... Probably not worth it for saving 128 bytes in a cornercase. So I reviewed #110 a bit instead |
hi, I'd rather not have to include instructions in my code (which uses this library) on how to manually download and modify MQTT_MAX_PACKET_SIZE. So, solutions: Option 1: Option 2:
Option 3:
If it were up to me, i'd probably go with Option 3. Let me know your thoughts. I am prepared to work on any of these options if they are likely to be committed. |
Anyone have thoughts on pr #282 ? |
I'm afraid I'm not knowledgeable enough to opine, but what you've done seems very reasonable to me, and without any downsides (it works the same as before unless the user elects to resize, no?). |
Thanks for the feedback.
Yes exactly. Existing users will not need to change code in any way. @knolleary has commented on pr #282 . |
@knolleary Any update to modifying the maximum packet size in Arduino IDE?. Are we anywhere near to closing this issue?. |
is it possible to confige buffer using psram? |
I resolved this by switching to another library:
|
This is because the defaul maxium length is 128b. So just go to PubSubClient.h and change #define MQTT_MAX_PACKET_SIZE 128 to #define MQTT_MAX_PACKET_SIZE 1024 |
Since this issue is dead for so long, I wonder if the library is even still being maintained. MQTT_MAX_PACKET_SIZE should be an optional parameter to init the library with. I personally got around this in my project by adding a compiler error so that users at least know what's wrong and how to fix it:
|
Hi @mcer12 it is maintained... but that doesn't mean I add every single feature users ask for, particularly ones that have been discussed many times before. |
Seeing how many people struggle with this, one would think this should be a priority. It's absolutely your call what to prioritize in your own library, I am not refuting that. |
I believe this is fixed. There is now a |
Yup - all fixed. Just not done a trawl of the 300+ issues to spot which ones that feature closes ;) |
Hello, great library! For several of my projects I'd need to change the MQTT packet size, but I need to do it from outside of your library.
Indeed, now I'd need to change MQTT_MAX_PACKET_SIZE inside your library, which is not very convenient. A function or a way to do that without changing your library would be great! Thanks.
The text was updated successfully, but these errors were encountered: