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

[mqtt - enhancement] setting up sock read() chunk size #959

Open
jonas-klein opened this issue Jan 6, 2025 · 1 comment
Open

[mqtt - enhancement] setting up sock read() chunk size #959

jonas-klein opened this issue Jan 6, 2025 · 1 comment

Comments

@jonas-klein
Copy link

Im encountering an issue, while transmitting large data (eg. files, ~50kb) over MQTT. The first transmission works flawlessly, but then the ESP has problems to allocate enough heap for further large transmissions in receiving. Blog posts depicts that the problem could be, that the heap is fragmentet after some allocations.

My solution here was to setting up a max chunk size for the read() command, e.g. 1024 byte (multiple of four, to retain the possibility to decode base64 encoded data).

max_size = 1024
left_size = sz
while left_size > 0:
    r = min(max_size, left_size)
    msg = self.sock.read(r)
    left_size -= r
    self.cb(topic, msg, (r<max_size))

The additional bool argument for the callback indicates the completeness of the transmission.

Peter Hinch already mentioned to me (in general) a better solution: send multiple short messages or use an device with SPIRAM. Im not entirely sure if this would fit in my situation, where i publish files via MQTT to update these in the filesystem. So at least I wanted to share my results here once again.

Inadvertent i've initially opened this issue under the mqtt repo of @peterhinch (whoops, that was probably a case of mental derangement, im sorry for that). Here was the intended place.

@peterhinch
Copy link
Contributor

Ah, all is clear now. I was rather puzzled as to how your code integrated into my driver...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants