#ESP32CAM β Running a WebServer to Flash On π¦π¦π¦ in the #Arduino board
El Bruno
Posted on March 7, 2022
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.
Happy coding!
Greetings
El Bruno
Read my original posts in my blog ElBruno.com
Posted on March 7, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
March 8, 2022
March 7, 2022