yoursunny / esp32cam

OV2640 camera on ESP32-CAM, Arduino library
https://esp32cam.yoursunny.dev
ISC License
473 stars 168 forks source link

start,stop stream by button #20

Closed 41linea45 closed 5 days ago

41linea45 commented 2 years ago

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.

eddyvazimou commented 2 years ago

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();});
yoursunny commented 2 years ago

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 commented 2 years ago

@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.