ESP32 - CAM OV2640. Module. WebServer

sir if i used the activity starter i just want like when we acces the link through web in case of wifi or activity starter
there is connection done through entering ip addres in text box is same for activity starter.?

1 Like

in this sam,e as led on off is working witj entering ip addres in text box ..
but for video streaming throught activity starter is coonectivity do like this for wifi is working or not or just we have to acces only not need of wifi connectivity in textbox by entering ip addres!!


or like this only i have to do ( blocks)

1 Like

I have not tested it, but you can have the same web server for video transmission and to turn on / off the LED.
Example: TextBox1.Text: http://192.168.9.21
It depends on the code of the ESP32

OK thanks for ur guidence !

- Turn on/off LED4 of the ESP32-CAM.

p247i_ESP32_Cam.aia (2.3 KB)

  • The ESP32-CAM module has a high luminosity LED, we are going to turn it on/off from an application.

  • We are going to use the library that we saw in one of the previous post:
    https://github.com/yoursunny/esp32cam

  • The Clock has an Interval of 800 ms, every that time a CAPTURE will be made.

  • Through the Buttons we send an on/off order to LED4.

  • We can also see the video in Stream, to turn it off we must wait about 35 seconds.


#include <esp32cam.h>
#include <WebServer.h>
#include <WiFi.h>

const char* WIFI_SSID = "my-ssid";
const char* WIFI_PASS = "my-pass";

WebServer server(80);

static auto loRes = esp32cam::Resolution::find(320, 240);
static auto hiRes = esp32cam::Resolution::find(800, 600);

void handleBmp()
{
  if (!esp32cam::Camera.changeResolution(loRes)) {
    Serial.println("SET-LO-RES FAIL");
  }

  auto frame = esp32cam::capture();
  if (frame == nullptr) {
    Serial.println("CAPTURE FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),static_cast<int>(frame->size()));

  if (!frame->toBmp()) {
    Serial.println("CONVERT FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CONVERT OK %dx%d %db\n", frame->getWidth(), frame->getHeight(), static_cast<int>(frame->size()));

  server.setContentLength(frame->size());
  server.send(200, "image/bmp");
  WiFiClient client = server.client();
  frame->writeTo(client);
}

void serveJpg()
{
  auto frame = esp32cam::capture();
  if (frame == nullptr) {
    Serial.println("CAPTURE FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(), static_cast<int>(frame->size()));

  server.setContentLength(frame->size());
  server.send(200, "image/jpeg");
  WiFiClient client = server.client();
  frame->writeTo(client);
}

void handleJpgLo()
{
  if (!esp32cam::Camera.changeResolution(loRes)) {
    Serial.println("SET-LO-RES FAIL");
  }
  serveJpg();
}

void handleJpgHi()
{
  if (!esp32cam::Camera.changeResolution(hiRes)) {
    Serial.println("SET-HI-RES FAIL");
  }
  serveJpg();
}

void handleJpg()
{
  server.sendHeader("Location", "/cam-hi.jpg");
  server.send(302, "", "");
}

void handleMjpeg()
{
  if (!esp32cam::Camera.changeResolution(hiRes)) {
    Serial.println("SET-HI-RES FAIL");
  }

  Serial.println("STREAM BEGIN");
  WiFiClient client = server.client();
  auto startTime = millis();
  int res = esp32cam::Camera.streamMjpeg(client);
  if (res <= 0) {
    Serial.printf("STREAM ERROR %d\n", res);
    return;
  }
  auto duration = millis() - startTime;
  Serial.printf("STREAM END %dfrm %0.2ffps\n", res, 1000.0 * res / duration);
}

void setup()
{
  Serial.begin(115200);
  Serial.println();

  {
    using namespace esp32cam;
    Config cfg;
    cfg.setPins(pins::AiThinker);
    cfg.setResolution(hiRes);
    cfg.setBufferCount(2);
    cfg.setJpeg(80);

    bool ok = Camera.begin(cfg);
    Serial.println(ok ? "CAMERA OK" : "CAMERA FAIL");
  }

  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  Serial.print("http://");
  Serial.println(WiFi.localIP());
  Serial.println("  /cam.bmp");
  Serial.println("  /cam-lo.jpg");
  Serial.println("  /cam-hi.jpg");
  Serial.println("  /cam.mjpeg");

  server.on("/cam.bmp", handleBmp);
  server.on("/cam-lo.jpg", handleJpgLo);
  server.on("/cam-hi.jpg", handleJpgHi);
  server.on("/cam.jpg", handleJpg);
  server.on("/cam.mjpeg", handleMjpeg);

  server.begin();
}

void loop()
{
  server.handleClient();
}
  • We can change the resolution of the capture:
    static auto loRes = esp32cam::Resolution::find(160, 120);

esp32_cam16

- ESP32-CAM captures images and uploads them to Google Drive. (I)

Previously, it is interesting to carry out this example of @TIMAI2 to upload and update files in Google Drive:

This tutorial in Spanish:
http://kio4.com/arduino/247_Wemos_WebCam.htm#drive

- ESP32-CAM capture image and update that image in Google Drive (II).

We are going to change the Script code, we will use part of the @TIMAI2 code to update the image that we will call capture.jpg
esp32_cam23

function doPost(e) {
  var data = Utilities.base64Decode(e.parameters.data);
// var nombreArchivo = Utilities.formatDate(new Date(), "GMT-3", "yyyyMMdd_HHmmss")+".jpg";
  var filename = "capture.jpg";
  var blob = Utilities.newBlob(data, e.parameters.mimetype, filename);
  
  var folder, folders = DriveApp.getFoldersByName("ESP32-CAM");
  if (folders.hasNext()) {
    folder = folders.next();
  } else {
    folder = DriveApp.createFolder("ESP32-CAM");
  }
  
  var existing = folder.getFilesByName(filename);
    if (existing.hasNext()) {
      var file = existing.next();
      if (file.getName() == filename) {
          fileID = file.getId();
         // Drive.Files.update({title: filename, mimeType: mimetype}, fileID, blob); 
          Drive.Files.update({title: filename,  mimeType: file.getMimeType()}, fileID, blob); 
      }
    } else {
    blob = Utilities.newBlob(data, e.parameters.mimetype, filename);
    fileID = folder.createFile(blob).getId(); 
    }
  
 // var file = folder.createFile(blob); 
  
  return ContentService.createTextOutput("Completo.")
}
  • We can locate the key of the file and put it in an Image component within a Clock, every certain interval the image will be updated on the screen.

hello sir,
my quation was by using esp 32 cam module can i controlled other 6 leds through mit app through wifi connecetivity and configuring esp32 cam as web server meanse in local area network ..... beacuse esp32 cam having 10 gpios but some are used for the camera in bulid module so can u help me in this?

In this tutorial you can see the ESP32-CAM pinout:

The following pins are internally connected to the microSD card reader:

  • GPIO 14: CLK
  • GPIO 15: CMD
  • GPIO 2: Data 0
  • GPIO 4: Data 1 (also connected to the on-board LED)
  • GPIO 12: Data 2
  • GPIO 13: Data 3

but if you don't have SdCard, maybe you can use it, I haven't tried it.

These pins can be connected to a 16-Channel CD74HC4067 multiplexer module and get 16 outputs.
https://www.google.com/search?q=CD74HC4067+16-Canal&sxsrf=ALeKk02nyZymtm4jNuuL9XKUVE1jdBLBeQ:1623309859467&source=lnms&tbm=isch&sa=X&ved=2ahUKEwibo6K8xIzxAhWrzoUKHRQYATYQ_AUoAXoECAEQAw&biw=1280&bih=611

- Loading the Sketch using an Arduino UNO.

- Add a button to the web page to turn on/off LED4, flash led.

esp32_cam37

We consult the following tutorial:

- Another Video Streamer with the WebViewer component.

esp32_cam38

It can transmit with HTTP and RTSP.

#ifdef ENABLE_WEBSERVER
WebServer server(80);
#endif

#ifdef ENABLE_RTSPSERVER
WiFiServer rtspServer(8554);
#endif

hi there, i had some question, in your esp code there is no led, and if i add a led 4 from http://kio4.com/arduino/247_Wemos_WebCam.htm#led4, when streaming the led button doesnt work, how to make the led button work when streaming?, thanks...

Try with this code:

#include <esp32cam.h>
#include <WebServer.h>
#include <WiFi.h>

const char* WIFI_SSID = "my-ssid";
const char* WIFI_PASS = "my-pass";

#define LED4  4 // LED4 is a Built-in Flash LED.

WebServer server(80);

static auto loRes = esp32cam::Resolution::find(160, 120); // Cambio resolución.
static auto hiRes = esp32cam::Resolution::find(800, 600);

void handleBmp()
{
  if (!esp32cam::Camera.changeResolution(loRes)) {
    Serial.println("SET-LO-RES FAIL");
  }

  auto frame = esp32cam::capture();
  if (frame == nullptr) {
    Serial.println("CAPTURE FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(), static_cast<int>(frame->size()));

  if (!frame->toBmp()) {
    Serial.println("CONVERT FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CONVERT OK %dx%d %db\n", frame->getWidth(), frame->getHeight(), static_cast<int>(frame->size()));

  server.setContentLength(frame->size());
  server.send(200, "image/bmp");
  WiFiClient client = server.client();
  frame->writeTo(client);
}

void serveJpg()
{
  auto frame = esp32cam::capture();
  if (frame == nullptr) {
    Serial.println("CAPTURE FAIL");
    server.send(503, "", "");
    return;
  }
  Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(), static_cast<int>(frame->size()));

  server.setContentLength(frame->size());
  server.send(200, "image/jpeg");
  WiFiClient client = server.client();
  frame->writeTo(client);
}

void handleJpgLo()
{
  if (!esp32cam::Camera.changeResolution(loRes)) {
    Serial.println("SET-LO-RES FAIL");
  }
  serveJpg();
}

void handleJpgHi()
{
  if (!esp32cam::Camera.changeResolution(hiRes)) {
    Serial.println("SET-HI-RES FAIL");
  }
  serveJpg();
}
////////////////// Modified. KIO4.COM
void handleJpg_on()
{
  Serial.println("LED ON");
  digitalWrite(LED4,HIGH); 
  serveJpg();
}
void handleJpg_off()
{
  Serial.println("LED OFF");
  digitalWrite(LED4,LOW); 
  serveJpg();
}
void handleMjpeg_off()
{
  handleMjpeg();
}
///////////////////////////

void handleMjpeg()
{
  if (!esp32cam::Camera.changeResolution(hiRes)) {
    Serial.println("SET-HI-RES FAIL");
  }

  Serial.println("STREAM BEGIN");
  WiFiClient client = server.client();
  auto startTime = millis();
  int res = esp32cam::Camera.streamMjpeg(client);
  if (res <= 0) {
    Serial.printf("STREAM ERROR %d\n", res);
    return;
  }
  auto duration = millis() - startTime;
  Serial.printf("STREAM END %dfrm %0.2ffps\n", res, 1000.0 * res / duration);
}

void setup()
{
  Serial.begin(115200);
  Serial.println();
  pinMode(LED4, OUTPUT);

  {
    using namespace esp32cam;
    Config cfg;
    cfg.setPins(pins::AiThinker);
    cfg.setResolution(hiRes);
    cfg.setBufferCount(2);
    cfg.setJpeg(80);

    bool ok = Camera.begin(cfg);
    Serial.println(ok ? "CAMERA OK" : "CAMERA FAIL");
  }

  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  Serial.print("http://");
  Serial.println(WiFi.localIP());
  Serial.println("  /cam.bmp");
  Serial.println("  /cam-lo.jpg");
  Serial.println("  /cam-hi.jpg");
  Serial.println("  /cam.mjpeg");

  server.on("/cam.bmp", handleBmp);
  server.on("/cam-lo.jpg", handleJpgLo);
  server.on("/cam-hi.jpg", handleJpgHi);
  server.on("/cam.mjpeg", handleMjpeg);
  server.on("/cam.mjpeg_off", handleMjpeg_off); // KIO4
  server.on("/LED_on", handleJpg_on); // KIO4
  server.on("/LED_off", handleJpg_off); // KIO4
  
  server.begin();
}

void loop()
{
  server.handleClient(); 
}
1 Like

when streaming, the led button is not working, how to make it work while streaming?

While it is streaming it cannot be changed.

Hi,
firstly thanks for the great job.

I tested the .aia and .ino at #18, that doesn't show any, the code serial monite output OK with:
CAMERA OK
http://192.168.100.176
/cam.bmp
/cam-lo.jpg
/cam-hi.jpg
/cam.mjpeg

and my PC shown well of image, but my phone with: p247_ESP32_Cam MIT APP shown nothing but error:
net:: ERR_CONNECTION_TIMED_OUT. (I've modified the IP)
what can be?
Thanks
Adam

Hello Juan Antonio.

I want to make a project with ESP32CAM, but i never use it.
It's for farming purposes.
My question is, i look for info about from when to when the camera record in the wave spectrum range. (i need take a photo from Visible to NIR - Near InfraRed). With 1 camera, take a capture with the visible and then, with another NIR. (i have the idea of removing the polarizing filter of the camera, i already read about it).
I will do this for a educational project in Geology.
I think to use a slider because the photo must be of the same place and in need to MERGE the 2 captures in 1. I need to rich the VISIBLE photo with NIR info, that's the idea.
But from all i searched i didn't find info about the spectrum (from 450nm to 750nm from visible, and later for the NIR , the close IR in the spectrum).
I will follower all i read in your post to make part of this project.
BUT
Do you know where to find this info (ESP32CAM spectrum of light info)?.

@illias28

Does the " 3.- App Inventor. VisorWeb. Utilizamos otra librería para evitar el error" example on the "http://kio4.com/arduino/247_Wemos_WebCam.htm" page work for you?

@German_Skena

The OV3660 camera is slow and low resolution, I don't think you will get quality images. You can see some examples of images on Youtube https://www.youtube.com/watch?v=KTOlRj-VKlg

You can get its characteristics in...
https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/unit/OV3660_CSP3_DS_1.3_sida.pdf

ov3660

Perhaps a better option would be to use a Raspberry Pi and a USB WebCam.
http://kio4.com/raspberry/24_webcam_usb.htm