How to control start and stop video streaming from ESP32-CAM?

35 Views Asked by At

I'm using ther ESP32-Cam and have started to play around with the ESP32-CAM Example 2 : Live Video Streaming Server application which works great.

I'm interested in starting and stopping the stream not by command from the client (via Start Stream/Stop Stream button in browser) but I want to control the Start/Stop option from the ESP32 directly.

I could just call WiFi.disconnect(false, false); to stop the stream but it's not great (if there was other data transmission going on as well) and a call to WiFi.reconnect(); won't automatically resume the stream either. How can this be done?

1

There are 1 best solutions below

0
thepirat000 On

Append the following code to the end of app_httpd.cpp:

void stopCameraServer(){
  if (camera_httpd != NULL) {
    httpd_stop(camera_httpd);
  }

  if (stream_httpd != NULL) {
    httpd_stop(stream_httpd);
  }
}

And add this at the top of CameraWebServer.ino:

void stopCameraServer();

Then you could stop the HTTP server by calling stopCameraServer()