Hi everyone, I’m doing my assignment and get some following problems. The purpose of this project is that transfer my ESP32 - CAM into a FTP clients, linked to a host server (already done). I’ve ready create a new folder and a .txt file and a picture (.jpg) and send to the server using FTP. And now I want to display that picture on the blynk app, using image gallery widget, but i don’t know what’s wrong with my code or my setup. Please help me because i have so little time left to finish this project.
Here is my code:
// Blynk configuration
#define BLYNK_TEMPLATE_ID "TMPL6-3JBT6Sn"
#define BLYNK_TEMPLATE_NAME "Live Video Streaming Test Online1"
#define BLYNK_AUTH_TOKEN "elTdWigV9lEreKLYKyUpU_AFdkigbwf3"
#include <BlynkSimpleEsp32.h>
#include "Arduino.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP32_FTPClient.h>
#include "octocat.h"
const char *WIFI_SSID ="";
const char *WIFI_PASS = "";
char ftp_server[] = "";
char ftp_user[] = "";
char ftp_pass[] = "";
ESP32_FTPClient ftp(ftp_server, ftp_user, ftp_pass, 5000, 2);
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.println("Connecting Wifi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Blynk initialization
Blynk.begin(BLYNK_AUTH_TOKEN, WIFI_SSID, WIFI_PASS);
// FTP operations
ftp.OpenConnection();
ftp.InitFile("Type A");
String list[128];
ftp.ChangeWorkDir("/");
ftp.ContentList("", list);
Serial.println("\nDirectory info: ");
for (int i = 0; i < sizeof(list); i++) {
if (list[i].length() > 0)
Serial.println(list[i]);
else
break;
}
ftp.MakeDir("my_new_dir");
ftp.ChangeWorkDir("my_new_dir");
ftp.InitFile("Type I");
ftp.NewFile("octocat.jpg");
ftp.WriteData(octocat_pic, sizeof(octocat_pic));
ftp.CloseFile();
ftp.InitFile("Type A");
ftp.NewFile("hello_world.txt");
ftp.Write("Hello World");
ftp.CloseFile();
ftp.CloseConnection();
}
void loop() {
BLYNK_WRITE(V1) {
Serial.println("BLYNK_WRITE(V1) has been called"); // Kiểm tra hàm có được gọi hay không
int pinValue = param.asInt();
Serial.print("Pin value received from Blynk: ");
Serial.println(pinValue); // In giá trị pin nhận từ Blynk
if (pinValue == 1) {
Serial.println("Pin value is 1, performing action...");
} else if (pinValue == 0) {
Serial.println("Pin value is 0, performing action...");
}
// Kiểm tra lệnh Blynk.setProperty
Blynk.setProperty(V1, "offImageUrl", "https://");
Serial.println("Blynk.setProperty has been executed");
delay(1000);
}
Blynk.run();
}
@datvdhe176651 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
Pete.
1 Like
Thank you, sir, I’ve ready edited my post. Hope someone can help me soon.
Why are you trying to run Blynk code on your ESP32-CAM if all you need to do is…
If the image is already available on a publicly resolvable url the just point the image gallery widget to that url.
If you want to be able to do other things, like control your ESP32-CAM from the Blynk app then you need to clearly state what the functional requirements of your project are.
Your current code won’t work for so many reasons, and I’m not going into those reasons at this point unless you explain your functional requirements in more detail, and post some working code which demonstrates ESP32-CAM image capture and FTP upload functionality.
Pete.
Hello guys, please help me with my project. I’ve been doing my assignment and having some troubles. My aim is that the ESP32-CAM can take a picture and automatically save it to the SD card. And then i use the FTP upload code to upload the picture which has been taken to the pre-setup folder, but at the moment I just want to up only 1 fixed file to the folder on my online server through FTP. At the same time, I also create an Image Button in the Blynk app, with the aim to display the photo esp32-cam took. But when i merge the taking photo code and the uploading code together, it seems to be not working correctly. Even it shows that there is no error in the serial monitor board, I cannot see the image that ESP32 - CAM just took.
PLease check my code below and give me some advice if you guys used to have this trouble and fixed it.
// Blynk configuration
#define BLYNK_TEMPLATE_ID "TMPL6-3JBT6Sn"
#define BLYNK_TEMPLATE_NAME "Live Video Streaming Test Online1"
#define BLYNK_AUTH_TOKEN "elTdWigV9lEreKLYKyUpU_AFdkigbwf3"
#include "esp_camera.h"
#include "Arduino.h"
#include "FS.h" // SD Card ESP32
#include "SD_MMC.h" // SD Card ESP32
#include "soc/soc.h" // Disable brownout problems
#include "soc/rtc_cntl_reg.h" // Disable brownout problems
#include "driver/rtc_io.h"
#include <EEPROM.h> // read and write from flash memory
#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP32_FTPClient.h>
#include <BlynkSimpleEsp32.h>
#include <string.h>
#define EEPROM_SIZE 1
// Pin definition for CAMERA_MODEL_AI_THINKER
#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 *WIFI_SSID = "";
const char *WIFI_PASS = "";
char ftp_server[] = "";
char ftp_user[] = "";
char ftp_pass[] = "";
ESP32_FTPClient ftp(ftp_server, ftp_user, ftp_pass, 5000, 2);
int pictureNumber = 0;
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
// Initialize Wi-Fi
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.println("Connecting Wifi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Initialize Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, WIFI_SSID, WIFI_PASS);
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; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
// Init Camera
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
// Start SD Card
if(!SD_MMC.begin()){
Serial.println("SD Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD Card attached");
return;
}
// Take Picture with Camera
camera_fb_t * fb = esp_camera_fb_get();
if(!fb) {
Serial.println("Camera capture failed");
return;
}
// initialize EEPROM with predefined size
EEPROM.begin(EEPROM_SIZE);
pictureNumber = EEPROM.read(0) + 1;
// Path where new picture will be saved in SD Card
String path = "/picture" + String(pictureNumber) +".jpg";
fs::FS &fs = SD_MMC;
Serial.printf("Picture file name: %s\n", path.c_str());
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
} else {
file.write(fb->buf, fb->len); // payload (image), payload length
Serial.printf("Saved file to path: %s\n", path.c_str());
EEPROM.write(0, pictureNumber);
EEPROM.commit();
}
file.close();
esp_camera_fb_return(fb);
// Upload picture to FTP server
ftp.OpenConnection();
ftp.InitFile("Type I");
//String a = String(pictureNumber) + ".jpg";
ftp.NewFile("1.jpg");
File imageFile = fs.open(path.c_str());
if (imageFile) {
Serial.printf("open file to path: %s\n", path.c_str());
size_t fileSize = imageFile.size();
uint8_t *fileBuffer = new uint8_t[fileSize];
imageFile.read(fileBuffer, fileSize);
ftp.WriteData(fileBuffer, fileSize);
delete[] fileBuffer;
imageFile.close();
}
ftp.CloseFile();
ftp.CloseConnection();
// Update Blynk with image URL
String imageUrl = "https://smarttmfu.com/smtrash/view/assets/img/AnhKDTest/1.jpg";
Blynk.setProperty(V1, "offImageUrl", imageUrl.c_str());
Serial.println("Blynk.setProperty has been executed with image URL: " + imageUrl);
// Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4
pinMode(4, OUTPUT);
digitalWrite(4, LOW);
rtc_gpio_hold_en(GPIO_NUM_4);
delay(2000);
Serial.println("Going to sleep now");
delay(2000);
esp_deep_sleep_start();
}
BLYNK_WRITE(V1) {
Serial.println("BLYNK_WRITE(V1) has been called"); // Kiểm tra hàm có được gọi hay không
int pinValue = param.asInt();
Serial.print("Pin value received from Blynk: ");
Serial.println(pinValue); // In giá trị pin nhận từ Blynk
if (pinValue == 1)
{
Serial.println("Pin value is 1, performing action...");
} else if (pinValue == 0)
{
Serial.println("Pin value is 0, performing action...");
}
// Kiểm tra lệnh Blynk.setProperty
// Blynk.setProperty(V1, "offImageUrl", "https://smarttmfu.com/smtrash/view/assets/img/AnhKDTest/my_new_dir/octocat.jpg");
// Serial.println("Blynk.setProperty has been executed");
delay(1000);
}
void loop() {
// Khai báo đường dẫn ảnh (URL) đúng trước khi sử dụng
String imageUrl = "https://smarttmfu.com/smtrash/view/assets/img/AnhKDTest/1.jpg";
// Sử dụng biến imageUrl đã khai báo
Blynk.setProperty(V1, "offImageUrl", imageUrl.c_str());
Serial.println("Blynk.setProperty has been executed");
delay(5000);
Blynk.run();
}
@datvdhe176651 you created a new topic about basically the same issue, so I’ve merged this into your previous topic.
Please keep the discussion in one topic, its much neater that way and avoids people having to repeat themselves.
Pete.