Hi !
Still learning with the ESP32 CAM board.
In today’s post the scenario is simple:
- Connect the device to a WiFi network
- Run a webserver on the device and create an endpoint [/flash]
- Turn on the Flash for 1 second when the endpoint receives a request.
As the previous sample, I’ll write this using Visual Studio Code and PlatformIO project, using the AI Thinker ESP-32CAM board.
Full project working demo

Let’s review some noted from the code:
As usual, we need to define the WiFi credentials in the main.cpp file.
// Replace with your network credentials
const char *ssid = "IoTLabs2";
const char *password = "12345678";
The function [flashOnForNSeconds] turns the Flash ON for N seconds.
// ledPin refers to ESP32-CAM GPIO 4 (flashlight)
#define FLASH_GPIO_NUM 4
void flashOnForNSeconds(int seconds)
{
digitalWrite(FLASH_GPIO_NUM, HIGH);
delay(seconds * 1000);
digitalWrite(FLASH_GPIO_NUM, LOW);
}
Once the device is connected, a new endpoint [/flash] is created and it will trigger the Flash for 1 second.
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
// Route for trigger flash
server.on("/flash", HTTP_GET, [](AsyncWebServerRequest *request)
{
flashOnForNSeconds(1);
request->send_P(200, "text/plain", "Flash Triggered"); });
// Start server
server.begin();
And tha’t basically it ! Once we know the IP for our device, we can make the HTTP call.

Full code available in my ESP32 Cam Demo repository.