arduino-mqtt icon indicating copy to clipboard operation
arduino-mqtt copied to clipboard

Added explicit settings to control segmented write length and delay

Open ehong-tl opened this issue 1 year ago • 3 comments

Added a method to set the maximum data length to be written into the network buffer in segments, as well as a method to set the delay between each successive write.

This helps prevent network overloading and network buffer overflow, particularly when using an external GSM/LTE module like the u-blox LARA R280, which I'm using for my project.

ehong-tl avatar Sep 13 '24 09:09 ehong-tl

Thanks for taking the time to compose this PR! Unfortunately, I cannot merge this right away. The changes to lwmqtt, would need to be submitted to its repository first. But I generally think that for such a problem there would be a better approach:

The library already uses the Arduino Client interface to interact with the network layer. A class that wraps a Client and also implements the Client interface, could efficiently impose the max. write buffer restriction and add the required delays. We could add the class as part of an example for the board you're using. This would be a much better separation of concern. WDYT?

256dpi avatar Sep 13 '24 10:09 256dpi

How about adding the maxPartialWriteLength and partialWriteDelayms variables into lwmqtt_arduino_network_t structure and they can be accessed via ref pointer in the inline lwmqtt_arduino_network_write function?

This will not modify the lwmqtt library.

I try not to touch the Client interface as I believe some of the network libraries have their own implementation of Client wrapper for their device.

I'll try this on Monday.

ehong-tl avatar Sep 13 '24 11:09 ehong-tl

Hey @256dpi

I tested the latest code changes, and everything is working perfectly. :)

ehong-tl avatar Sep 16 '24 04:09 ehong-tl