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

El Bruno - Mar 7 '22 - - Dev Community

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";

Enter fullscreen mode Exit fullscreen mode

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);
}

Enter fullscreen mode Exit fullscreen mode

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();

Enter fullscreen mode Exit fullscreen mode

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!

Greetings

El Bruno

Read my original posts in my blog ElBruno.com


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player