#ESP32CAM – Running a WebServer to Flash On 🔦🔦🔦 in the #Arduino board

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

ESP32Cam Flash 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)
              request->send_P(200, "text/plain", "Flash Triggered"); });

  // Start server

And tha’t basically it ! Once we know the IP for our device, we can make the HTTP call.

http endpoint flash triggered response from browser

Full code available in my ESP32 Cam Demo repository.

Happy coding!


El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: