The fragment loop only wrote a full fragment while more data followed
it, and only wrote a partial one when there was a remainder. When the
photo length was an exact multiple of PHOTO_FRAGMENT_SIZE the final
fragment was never sent, the length check failed and the upload was
reported as incomplete.
Replace it with a loop that sends what is left, up to one fragment at a
time. Checked on the host for every length from 0 to 299999 and on a
XIAO ESP32-S3 Sense (uploads return 200 OK).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The camera driver runs with a single frame buffer, but the firmware kept
the last photo in it and returned it to the driver repeatedly (on every
stream frame, on stream start and on stream close). A failed grab also
left the frame-buffer mutex held and streamed a stale buffer.
Photos and stream frames are now copied into PSRAM and the driver buffer
is returned immediately. The stream, the Prusa Connect upload and
/saved-photo.jpg each own their copy, so none can free a frame another
is still sending. Stream clients are counted, a failed capture ends the
stream cleanly, and web-side waits on the camera lock time out after 3 s
instead of blocking the async_tcp task.
Tested on a XIAO ESP32-S3 Sense: two overlapping streams for 75 s while
Prusa Connect uploads ran, no reboot, all uploads 200 OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>