Esp32-Cam WebServer - Esp8266 Http Get

Hi, I am using an esp32 camera to capture images and send it through an ftp connection. Everything is working fine, I even made a web server so each time I visit the URL with my chrome browser it takes a picture, however I can't make a request from my esp8266 to the same URL, the error is always HTTP Status Code -1. I've tried other API's and they all work except mine. I will share some code:


#include <WiFi.h>
#include <WebServer.h>
#include "ESP32_FTPClient.h"
#include "FS.h"
#include "SD_MMC.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "driver/rtc_io.h"
#include <EEPROM.h>
#include "esp_camera.h"

#define EEPROM_SIZE 1

#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

const char* ssid = "mywifi";
const char* password = "mywifi";

WebServer server(80);
ESP32_FTPClient ftpClient("192.168.1.188", 21, "marco", "marco");

IPAddress local_IP(192, 168, 1, 184);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
int pictureNumber = 1;
void setup() {
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector

  Serial.begin(115200);

  // Camera config
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG; 
  
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } 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;
  }

  // Inicializa SD card
  if (!SD_MMC.begin()) {
    Serial.println("Failed to mount SD card.");
    return;
  }
  if(!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }
  //Network config
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected!");

  // Http Server cofnig
  server.on("/capture_photo", HTTP_GET, []() {
    capturePhoto();
    server.send(200, "text/plain", "Photo captured!");
  });

  server.begin();
}

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

void capturePhoto() {
  camera_fb_t * fb = esp_camera_fb_get();  
  if(!fb) {
    Serial.println("Camera capture failed");
    return;
  }

  // NĂºmero da foto
  /*int pictureNumber = EEPROM.read(0) + 1;
  EEPROM.write(0, pictureNumber);
  EEPROM.commit();
  */
  

  if(pictureNumber == 254){
    pictureNumber =1;
  }
  

  // Picture path
  String path = "/picture" + String(pictureNumber) +".jpg";

  pictureNumber++;
  
  // File open to write
  File file = SD_MMC.open(path.c_str(), FILE_WRITE);
  if(!file) {
    Serial.println("Failed to open file in writing mode");
    esp_camera_fb_return(fb);
    return;
  } 
  
  // Write image data to file
  file.write(fb->buf, fb->len);
  file.close();
  esp_camera_fb_return(fb); 

  // Send image through FTP
  ftpClient.OpenConnection();
  ftpClient.InitFile("Type I");
  String imgPath = path.substring(1);
  ftpClient.NewFile(imgPath.c_str());

  File imgFile = SD_MMC.open(path.c_str());
  if (!imgFile) {
    Serial.println("Failed to open image file.");
  } else {
    while (imgFile.available()) {
      uint8_t buf[512];
      size_t len = imgFile.read(buf, sizeof(buf));
      ftpClient.WriteData(buf, len);
    }
    imgFile.close();
    Serial.println("Image file written to FTP.");
    ftpClient.CloseFile();
  }

  ftpClient.CloseConnection();
  Serial.println("FTP connection closed.");
 
}

and for the esp8266 I have:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>


const char* ssid = "mywifi";
const char* password = "mywifi";
const char* esp32camIP = "192.168.1.184";

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    WiFiClient client; // Create a WiFiClient object

    // Construct the URL for triggering photo capture
    String url = "http://" + String(esp32camIP) + "/capture_photo";
    Serial.print("Sending GET request to ESP32-CAM: ");
    Serial.println(url);

    // Begin the HTTP request
    http.begin(client, url);

    // Send the request and get the response
    int httpCode = http.GET();

    // Check the HTTP response code
    if (httpCode > 0) {
      Serial.printf("HTTP status code: %d\n", httpCode);
      String payload = http.getString();
      Serial.println("Response: " + payload);
    } else {
      Serial.println("HTTP request failed");
    }

    // End the request
    http.end();

    delay(5000); // Delay before sending the next request
  } else {
    Serial.println("WiFi not connected");
    delay(1000);
  }
}

It gets a connection but never a response from my esp32-cam server

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