I’m building a city project using the AMB82 Mini. The camera settings are normal, but there’s a problem with streaming MJPG:
When the web client is closed, the stream doesn’t exit but continues running indefinitely, resulting in the inability to stream when accessing the web client a second time.
I discovered that the client.write() function always succeeds, meaning that even when the client loses connection, the loop sending images continues to run.
while (client.connected()) {
uint32_t addr = 0, len = 0;
Camera.getImage(CHANNEL, &addr, &len);
if (!addr || !len) {
vTaskDelay(1 / portTICK_PERIOD_MS);
continue;
}
snprintf(headerBuf, sizeof(headerBuf), "Content-Type: image/jpeg\r\nContent-Length: %lu\r\n\r\n", len);
if (client.write((uint8_t *)headerBuf, strlen(headerBuf)) == 0) {
break;
}
if (client.write((uint8_t *)addr, len) == 0) {
break;
}
if (client.write((uint8_t *)"\r\n--" PART_BOUNDARY "\r\n", strlen("\r\n--" PART_BOUNDARY "\r\n")) == 0) {
break;
}
vTaskDelay(FRAME_INTERVAL);
}
How can I stream an mjpg file and actively start and stop it ?
