# Support bei ESP32-CAM Projekt

**URL:** <https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086>\
**Category:** Deutsch\
**Created:** [September 19, 2024, 8:38am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086 "2024-09-19T08:38:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 19, 2024, 8:38am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/1 "2024-09-19T08:38:19Z")

</div>

Hallo zusammen,  
ich habe mir mit einem ESP32-CAM Modul eine Briefkastenüberwachung gebaut, mit der ich in Telegram ein Foto meines Briefkastens machen kann.  
Allerdings hat die Powerbank nie wirklich lange gehalten und deswegen muss jetzt etwas neues her. Ich habe mir (bitte nicht steinigen 😃 ) mit GPT und ein paar Tutorials aus dem Netz folgenden Code zusammengebaut:

```arduino
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "esp_camera.h"
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

const char* ssid = " ************"; // Replace with your Wi-Fi SSID
const char* password = " *********"; // Replace with your Wi-Fi password
String BOTtoken = " ************"; // Replace with your Telegram Bot Token
String CHAT_ID = " ***********"; // Replace with your Telegram Chat ID

WiFiClientSecure clientTCP;
UniversalTelegramBot bot(BOTtoken, clientTCP);

//LED PIN
#define FLASH_LED_PIN 4
bool flashState = HIGH;

void configInitCamera() {
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = 5;
  config.pin_d1 = 18;
  config.pin_d2 = 19;
  config.pin_d3 = 21;
  config.pin_d4 = 36;
  config.pin_d5 = 39;
  config.pin_d6 = 34;
  config.pin_d7 = 35;
  config.pin_xclk = 0;
  config.pin_pclk = 22;
  config.pin_vsync = 25;
  config.pin_href = 23;
  config.pin_sscb_sda = 26;
  config.pin_sscb_scl = 27;
  config.pin_pwdn = 32;
  config.pin_reset = -1;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  config.grab_mode = CAMERA_GRAB_LATEST;

  if (psramFound()) {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 1;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);

    return;
  }
}

String sendPhotoTelegram(camera_fb_t *fb) {
  const char* myDomain = "api.telegram.org";
  String getAll = "";
  String getBody = "";

  if (clientTCP.connect(myDomain, 443)) {
    Serial.println("Connection successful");

    String head = "--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"chat_id\"; \r\n\r\n" + CHAT_ID + "\r\n--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"esp32-cam.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
    String tail = "\r\n--RandomNerdTutorials--\r\n";

    size_t imageLen = fb->len;
    size_t extraLen = head.length() + tail.length();
    size_t totalLen = imageLen + extraLen;
  
    clientTCP.println("POST /bot" + BOTtoken + "/sendPhoto HTTP/1.1");
    clientTCP.println("Host: " + String(myDomain));
    clientTCP.println("Content-Length: " + String(totalLen));
    clientTCP.println("Content-Type: multipart/form-data; boundary=RandomNerdTutorials");
    clientTCP.println();
    clientTCP.print(head);
  
    uint8_t *fbBuf = fb->buf;
    size_t fbLen = fb->len;
    for (size_t n = 0; n < fbLen; n += 1024) {
      if (n + 1024 < fbLen) {
        clientTCP.write(fbBuf, 1024);
        fbBuf += 1024;
      } else if (fbLen % 1024 > 0) {
        size_t remainder = fbLen % 1024;
        clientTCP.write(fbBuf, remainder);
      }
    }
  
    clientTCP.print(tail);
    esp_camera_fb_return(fb);

    int waitTime = 10000; // timeout 10 seconds
    long startTimer = millis();
    boolean state = false;

    while ((startTimer + waitTime) > millis()) {
      while (clientTCP.available()) {
        char c = clientTCP.read();
        if (c == '\n') {
          if (getAll.length() == 0) {
            state = true;
          } else {
            break;
          }
        }
        if (state) {
          getBody += c;
        }
      }
    }

    clientTCP.stop();
    return getBody;
  } else {
    Serial.println("Connection failed");
    return "";
  }
}

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  pinMode(FLASH_LED_PIN, OUTPUT);
  
  // Connect to Wi-Fi
  Serial.print("Connecting to Wi-Fi...");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected!");

  // Configure client with the root certificate
  clientTCP.setCACert(TELEGRAM_CERTIFICATE_ROOT);

  // Initialize camera
  configInitCamera();
  
  // Turn on LED using flashState
  flashState = HIGH;
  digitalWrite(FLASH_LED_PIN, flashState);
  Serial.println("LED turned ON");
  
  // Wait 5 seconds
  delay(5000);
  
  // Take picture
  camera_fb_t *fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("Camera capture failed");
    return;
  }
  
  Serial.println("Taking picture...");
  
  // Turn off LED using flashState
  flashState = LOW;
  digitalWrite(FLASH_LED_PIN, flashState);
  Serial.println("LED turned OFF");
  
  // Send the picture to Telegram
  Serial.println("Sending picture to Telegram...");
  String response = sendPhotoTelegram(fb);
  
  if (response.indexOf("ok") >= 0) {
    Serial.println("Picture sent successfully.");
  } else {
    Serial.println("Failed to send picture.");
  }

  // Deep sleep for 20 seconds
  Serial.println("Going to sleep for 20 seconds...");
  esp_deep_sleep(43200000); // Sleep for 20 seconds
}

void loop() {
  // Do nothing in loop
}

```

Soweit so funktionabel.  
Allerdings bin ich auf folgende Probleme gestoßen:

- Die 43200000 sind keine 12 Stunden... Er macht nach gefühlt 20-30 Sekunden nochmal ein Foto.
- Die LED wird nicht abgeschaltet sondern offenbar nur auf LOW gestellt. Um Batterie zu sparen sollte sie aber eigentlich aus gehen. Kann man das irgendwie erreichen ?

Leider kann ich von der Arduino-Code-Sprache nicht sonderlich viel verstehen (Grundkenntnisse programmieren sind vorhanden) Bitte habt nachsicht 🙂 Danke für eure Hilfe

---

<div class="post-metadata">

**Author:** ![hawe07546](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hawe07546/32/1013044_2.png) [@hawe07546](https://forum.arduino.cc/u/hawe07546)\
**Post date:** [September 19, 2024, 9:54am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/2 "2024-09-19T09:54:30Z")

</div>

> [@schimicho](#):
>
> Die 43200000 sind keine 12 Stunden... Er macht nach gefühlt 20-30 Sekunden

Naja, 43.200.000 in Millisekunden schon, die _sleeptime_ wird aber in Mikrosekunden erwartet, d.h. gemessen sollte er alle 43,2 Sekunden ein Bild machen.

> [@schimicho](#):
>
> Die LED wird nicht abgeschaltet sondern offenbar nur auf LOW gestellt.

Verstehe ich nicht, beide Seite auf GND und trotzdem nicht aus?

cu

---

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 19, 2024, 10:06am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/3 "2024-09-19T10:06:58Z")

</div>

Ah okay. Dann muss ich das nochmal umrechnen 😃 Danke. 1 Problem weniger.  
Ich hab mal ein Video vom Verhalten des ESP gemacht 🙂 [https://www.youtube.com/shorts/N\_oT7M0KZDQ](https://www.youtube.com/shorts/N_oT7M0KZDQ)  
Erst auf HIGH, dann OFF, kurze Zeit später kam das Bild bei Telegram und dann ging das licht wieder an... sehr merkwürdig

---

<div class="post-metadata">

**Author:** ![HotSystems](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hotsystems/32/219785_2.png) [@HotSystems](https://forum.arduino.cc/u/HotSystems)\
**Post date:** [September 19, 2024, 11:23am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/4 "2024-09-19T11:23:39Z")

</div>

Keine Ahnung, welche CAM du verwendest, aber die, die ich kenne (ESP32-CAM Al\_thinker) , braucht am GPIO4 HIGH zum Leuchten und LOW, damit diese aus ist.  
Und das funktioniert prima.

---

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 19, 2024, 12:02pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/5 "2024-09-19T12:02:16Z")

</div>

> **[Entwicklungsboard für ESP32 CAM,WiFi Bluetooth Entwicklungsboard,DC 5V Dual-Core...](https://www.amazon.de/Entwicklungsboard-Bluetooth-Dual-Core-Modulen-Kompatibel/dp/B0D7D43ZJ2)**
>
> Entwicklungsboard für ESP32 CAM unterstützt Bild WiFi-Upload, unterstützt TF-Karte, unterstützt mehrere Sleep-Modi, Dual-Core 32-Bit-CPU, niedriger Stromverbrauch, geeignet für Anwendungsprozessoren, einfach zu programmieren, können interessante...

Das ist das board das ich habe.  
Bei dem anderen Code den ich habe funktioniert das auch. Es schaltet die Lampe ja auch aus aber wenn es in den deepsleep geht geht sie wieder an. Sehr merkwürdig

---

<div class="post-metadata">

**Author:** ![HotSystems](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hotsystems/32/219785_2.png) [@HotSystems](https://forum.arduino.cc/u/HotSystems)\
**Post date:** [September 19, 2024, 7:49pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/6 "2024-09-19T19:49:58Z")

</div>

> [@schimicho](#):
>
> aber wenn es in den deepsleep geht geht sie wieder an

Da ich den ESP32 noch nicht im deep sleep betrieben habe, kann ich zu dem Problem leider nichts sagen. Und wenn dein "anderer Code" funktioniert, dann verwende den und erweitere ihn um fehlende Funktionen.

---

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 20, 2024, 9:06am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/7 "2024-09-20T09:06:31Z")

</div>

Das hab ich schon gemacht. Funktioniert auch soweit außer wenn das Gerät in den Deepsleep geht.. 🤔

---

<div class="post-metadata">

**Author:** ![hawe07546](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hawe07546/32/1013044_2.png) [@hawe07546](https://forum.arduino.cc/u/hawe07546)\
**Post date:** [September 20, 2024, 9:18am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/8 "2024-09-20T09:18:09Z")

</div>

> [@schimicho](#):
>
> Dann muss ich das nochmal umrechnen

Nein, drei Nullen dran.

Mit den GPIO im _deep sleep_ ist es anscheinend nicht so einfach, google mal.  
Man sieht ja auch, das die LED wesentlich dunkler ist.

cu

---

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 20, 2024, 3:11pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/9 "2024-09-20T15:11:14Z")

</div>

Das stimmt natürlich. Aber dunkel heißt leider trotzdem das sie weiterhin Strom zieht (was ja möglichst vermieden werden soll)  
Ich hab leider nicht das krasse Know How in Programmierung mit dem ESP... Irgendwelche Ideen wie ich die LED komplett abschalten kann im DeepSleep?

---

<div class="post-metadata">

**Author:** ![HotSystems](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hotsystems/32/219785_2.png) [@HotSystems](https://forum.arduino.cc/u/HotSystems)\
**Post date:** [September 20, 2024, 3:39pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/10 "2024-09-20T15:39:02Z")

</div>

Kannst du denn am Steuertransistor der Led Spannung messen ?  
Ich vermute, an der Basis liegt Spannung an, so das der Transistor etwas durchsteuert. Dann liegt es wohl am ESP32, der den Ausgang auf HIGH legt.  
Warum, müsste man im Datenblatt finden.

---

<div class="post-metadata">

**Author:** ![hawe07546](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hawe07546/32/1013044_2.png) [@hawe07546](https://forum.arduino.cc/u/hawe07546)\
**Post date:** [September 21, 2024, 8:47am UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/11 "2024-09-21T08:47:14Z")

</div>

> [@schimicho](#):
>
> Irgendwelche Ideen wie ich die LED komplett abschalten kann im DeepSleep?

Ja, googeln, das Problem ist nicht neu.  
Z.B.:

> [@ESP32 in deepsleep mode not holding the pin state](https://forum.arduino.cc/t/esp32-in-deepsleep-mode-not-holding-the-pin-state/961435):
>
> Hi, i am trying to turn of the display when esp32 goes to sleep. but it's not doing it. Not sure what's the issue. i am reading the pin sate before going to sleep and it shows it's 0. here is the code #include \<WiFi.h\> #include "time.h" #define sleepPeriod 10000000ul // 10 seconds sleep #define OFFSET 0 // us (tient compte du temps d'exécution de updateTime) #include \<ESP32Time.h\> unsigned long DELAY\_TIME = 10000; // 6 sec unsigned long delayStart = 0; // the time the delay started ESP32T…

[https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html)  
_When a GPIO is set to hold, its state is latched at that moment and will not change when the internal signal or the IO MUX/GPIO configuration is modified (including input enable, output enable, output value, function, and drive strength values). **This function can be used to retain the state of GPIOs when the power domain of where GPIO/IOMUX belongs to becomes off.**  **For example,** chip or system is reset (e.g. watchdog time-out, **deep-sleep events are triggered** ), or peripheral power-down in light-sleep._

cu

---

<div class="post-metadata">

**Author:** ![uwefed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uwefed/32/213736_2.png) [@uwefed](https://forum.arduino.cc/u/uwefed)\
**Post date:** [September 21, 2024, 7:39pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/12 "2024-09-21T19:39:25Z")

</div>

> [@schimicho](#):
>
> Allerdings hat die Powerbank nie wirklich lange gehalten

Eine Powebank schaltet nach ca 30 Sekunden ab, wenn nicht ein gewisser Mindeststrom ( ca 50mA) fließt. (EU-Vorgeben zur Energiesparen)

Also kann man keine Elektronik in Sleepmodus an einer regulären Powerband betreiben weil diese zur Energieersparnis abschalet.

Grüße Uwe

---

<div class="post-metadata">

**Author:** ![schimicho](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/schimicho/32/1105384_2.png) [@schimicho](https://forum.arduino.cc/u/schimicho)\
**Post date:** [September 21, 2024, 7:50pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/13 "2024-09-21T19:50:23Z")

</div>

Hab ich heute auch gemerkt... Sehr blöd wenn man will das die Bank möglichst lange hält 😕

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [September 21, 2024, 8:10pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/14 "2024-09-21T20:10:07Z")

</div>

Man kann die Powerbank in Intervallen über Transistor und Lastwiderstand belasten, damit sie nicht abschaltet. Die Intervalle und den Strom muss man wohl experimentell ermitteln und bei Sleep dann extern, z.B. über einen NE555 steuern.

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![uwefed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uwefed/32/213736_2.png) [@uwefed](https://forum.arduino.cc/u/uwefed)\
**Post date:** [September 21, 2024, 9:26pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/15 "2024-09-21T21:26:46Z")

</div>

> [@Tommy56](#):
>
> Man kann die Powerbank in Intervallen über Transistor und Lastwiderstand belasten

Dann nimmt man aber bessere statt der Powerbank eine Lipo Batterie und einen Ladeschaltung und betreibt alles mit der Batteriespannung.

Grüße Uwe

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2025, 9:27pm UTC](https://forum.arduino.cc/t/support-bei-esp32-cam-projekt/1303086/16 "2025-03-20T21:27:37Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
