Closed Abhay-2412 closed 1 year ago
The problem is that you are trying to init the camera every request. It should be inited once in setup.
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include "esp_camera.h"
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
// Replace with your network credentials
const char* ssid = "Abhay iphone13";
const char* password = "12345678";
// Create an instance of the web server
WebServer server(80);
// Camera configuration
const int cameraWidth = 320;
const int cameraHeight = 240;
void handleRoot() {
camera_fb_t* frameBuffer = NULL;
// Capture a new frame from the camera
frameBuffer = esp_camera_fb_get();
// Send the frame as a response
if (frameBuffer) {
// Set the content type to multipart/x-mixed-replace
server.sendHeader("Content-Type", "multipart/x-mixed-replace; boundary=ESP32CAM");
server.sendHeader("Content-Type", "image/jpeg");
server.sendHeader("Content-Disposition", "inline; filename=capture.jpg");
server.sendContent_P(reinterpret_cast<const char*>(frameBuffer->buf), frameBuffer->len);
esp_camera_fb_return(frameBuffer);
} else {
server.send(500);
}
}
void setup() {
// Start the serial communication
Serial.begin(115200);
// Start the camera
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// Initialize the camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera initialization failed with error 0x%x", err);
return;
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Start the web server and handle the root request
server.on("/", handleRoot);
server.begin();
Serial.println("Web server started");
Serial.println(WiFi.localIP());
}
void loop() {
// Handle incoming client requests
server.handleClient();
}
also not clear to me which camera board you are using?
also not clear to me which camera board you are using?
Greetings! I am currently utilizing the OV5640 camera module, which is labeled as "0465-HZF" on the physical camera itself.
Board
AI Thinker Esp32-cam
Device Description
just attached with eso32-cam-mb
Hardware Configuration
OV5640 camera
Version
v2.0.3
IDE Name
Arduino IDE
Operating System
windows 11
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
Actually I'm searching for a simple code to test my camera which can be ported to ESP-IDF later (Arduino as component) came across a code but whenever i try to access it through my ip address i get below error constantly
i tried traditional esp32 cam web server code its working fine but iam unable to port it to ESP-IDF since it showing some files are missing related to
app_httpd.cpp
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide