Skip to content

Commit

Permalink
Merge pull request #22 from heliumonoxide/image-name
Browse files Browse the repository at this point in the history
added image unique naming based on time and added note
  • Loading branch information
heliumonoxide authored Nov 8, 2024
2 parents e46f0e4 + 8647e8e commit 68d52c5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 8 deletions.
74 changes: 66 additions & 8 deletions esp32_cam/ESP32CAM/ESP32CAM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ESP32_FTPClient.h"
#include <octocat.h>
#include "esp_camera.h"
#include <time.h>


#define PWDN_GPIO_NUM 41
Expand All @@ -33,14 +34,51 @@
#define PCLK_GPIO_NUM 13

// Thanks to NORVI for supplying these configuration of ESP32 S3 with OV5640 https://www.esp32.com/viewtopic.php?f=17&t=40731 information: https://github.com/IndustrialArduino/NORVI-ESP32-CAMERA
// Also big thanks to Leonardo Bispo in https://github.com/ldab for developing ESP32_FTPClient

#define WIFI_SSID "dapoersemar"
#define WIFI_PASS "warkopds"
#define WIFI_SSID "dapoersemar" // Your wifi name
#define WIFI_PASS "warkopds" // Your wifi password

// Please make sure your wifi can access internet and have bandwidth since esp will be client of the wifi.

char ftp_server[] = "VM External IP";
uint16_t ftp_port = 21;
char ftp_user[] = "VM user username";
char ftp_pass[] = "VM user password";
uint16_t ftp_port = 21; // Usually used for FTP connection in port 21
char ftp_user[] = "VM Users username";
char ftp_pass[] = "VM Users password";

// Make sure your VM has set up FTP server with correct firewall configuration. using below command:
// sudo apt-get update
// sudo apt-get install vsftpd
// vsftpd --version

// Also, make sure the config of VSFTPD is also correct by using command in debian as below:
// sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak --> for backup
// sudo nano /etc/vsftpd.conf

// Edit to:
// Listen_ipv6=YES
// anonymous_enable=NO
// pasv_enable=YES
// pasv_min_port=1024
// pasv_max_port=1048
// local_enable=YES
// write_enable=YES
// local_umask=022
// dirmessage_enable=YES
// use_localtime=YES
// xferlog_enable=YES
// connect_from_port_20=YES
// chroot_local_user=YES
// allow_writeable_chroot=YES
// secure_root_dir=/var/run/vsftpd/empty
// pam_service_name=vsftpd
// rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
// rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
// ssl_enable=NO

// after saving by click ctrl+x and y then click enter. Now restart vsftpd server by running command:
// sudo systemctl restart vsftpd
// sudo systemctl status vsftpd

ESP32_FTPClient ftp(ftp_server, ftp_port, ftp_user, ftp_pass);

Expand All @@ -60,6 +98,16 @@ void setup() {
Serial.print("ESP32-CAM IP Address: ");
Serial.println(WiFi.localIP());

// Configure time and set timezone
configTime(25200, 0, "pool.ntp.org"); // Use NTP to sync time to jakarta time +7hours

// Ensure time is synced
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}

// Camera configuration
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
Expand Down Expand Up @@ -142,7 +190,6 @@ void setup() {

void loop() {
// Capture the image

camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
Expand All @@ -159,6 +206,17 @@ void loop() {
// // Return the frame buffer back to the driver for reuse
// esp_camera_fb_return(fb);

struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
}

// Create a buffer to hold the formatted time
char filename[30];
strftime(filename, sizeof(filename), "image_%Y%m%d_%H%M%S.jpg", &timeinfo);

Serial.println("Generated file name: " + String(filename));

// Connect to FTP server
ftp.OpenConnection();
Serial.println("Connected to FTP server.");
Expand All @@ -168,7 +226,7 @@ void loop() {

// Send the image as a .jpg file
ftp.InitFile("Type I"); // Switch to binary mode
ftp.NewFile("testImage.jpg");
ftp.NewFile(filename);
Serial.println("Writing data to jpg image...");
ftp.WriteData((unsigned char*)fb->buf, fb->len); // Send JPEG buffer
ftp.CloseFile(); // Finalize the file transfer
Expand All @@ -178,5 +236,5 @@ void loop() {
esp_camera_fb_return(fb); // Release frame buffer


delay(40000); // Capture every 40 seconds
delay(60000); // Capture every 60 seconds
}
33 changes: 33 additions & 0 deletions esp32_cam/readme_for_VM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Make sure your VM has set up FTP server with correct firewall configuration. using below command:
sudo apt-get update
sudo apt-get install vsftpd
vsftpd --version

Also, make sure the config of VSFTPD is also correct by using command in debian as below:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak --> for backup
sudo nano /etc/vsftpd.conf

Edit to:
Listen_ipv6=YES
anonymous_enable=NO
pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
allow_writeable_chroot=YES
secure_root_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

after saving by click ctrl+x and y then click enter. Now restart vsftpd server by running command:
sudo systemctl restart vsftpd
sudo systemctl status vsftpd

0 comments on commit 68d52c5

Please sign in to comment.