esp32cam icon indicating copy to clipboard operation
esp32cam copied to clipboard

start,stop stream by button

Open 41linea45 opened this issue 2 years ago • 3 comments

Hello,

Firstly, thanks to avesome library. I need to control stream start stop by button(digitalRead). Now, I can sart stream by a digitalRead: if(button_state== 1){ server.handleClient(); } But I cant stop stream by a button . when void handleMjpeg() starts stream , it doesnt works loop procedure. I am newbie and pls tell me how can i stop stream i press the button. Best regards.

41linea45 avatar Oct 24 '21 09:10 41linea45

try this in handles.cpp between server.on("/", HTTP_GET, [] { and server.on("/robots.txt", HTTP_GET,

server.on("/stop", HTTP_GET,
[] { server.send(200, "text/txt", "REBOOTING_ESP\n");
ESP.restart();});

eddyvazimou avatar Feb 08 '22 17:02 eddyvazimou

server.on("/stop"

That would not work. The HTTP server is single threaded. The thread is busy executing the MJPEG handler, so that it cannot process the stop request.

yoursunny avatar Feb 08 '22 23:02 yoursunny

@41linea45

I need to control stream start stop by button

The MJPEG stream is pull-based: it is the HTTP client who determines when to start and stop receiving the stream. The ESP32-CAM device is an HTTP server and thus it cannot control whether the stream is running.

yoursunny avatar Feb 22 '22 03:02 yoursunny