#ESP32CAM – WebServer taking photos 📸 every N seconds #Arduino

elbruno

El Bruno

Posted on March 21, 2022

#ESP32CAM – WebServer taking photos 📸 every N seconds #Arduino

Hi !

Still learning with the ESP32 CAM board.

In today’s post the scenario is simple:

  • Init the camera
  • Init the local File System
  • Take a photo every 5 seconds and store it in memory
  • Creates an endpoint named [/photo] to return the last saved photo

As the previous sample, I’ll write this using Visual Studio Code and PlatformIO project, using the AI Thinker ESP-32CAM board.

Demo here is tricky, but hey, a selfie is always a good excuse.

selfie with the esp32 cam

As usual, the full sample code is in the demo repository.

Let’s review some noted from the code:

  • The setup and loop are the key codes for this demo.
  • In the setup, init wifi, fs, and camera
  • As a visual clue, I turn on the flash 1 second after each one
  • In the loop, the camera takes a photo every 5 seconds

void setup()
{
  // Serial port for debugging purposes
  Serial.begin(9600);

  // initialize digital pin ledPin as an output
  pinMode(FLASH_GPIO_NUM, OUTPUT);

  // connect to wifi
  initAndConnectWifi();
  flashOnForNSeconds(1);

  // init fs and camera
  initFS();
  initCamera();
  flashOnForNSeconds(1);

  // init and start server
  server.on("/photo", HTTP_GET, [](AsyncWebServerRequest *request)
            { request->send(SPIFFS, FILE_PHOTO, "image/jpg", false); });
  server.begin();
}

void loop()
{
  capturePhotoSaveSpiffs();
  delay(5000);
}

Enter fullscreen mode Exit fullscreen mode

Next steps will include learning Edge Impulse and Computer Vision in this device !

Full code available in my ESP32 Cam Demo repository.

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.


💖 💪 🙅 🚩
elbruno
El Bruno

Posted on March 21, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related