├── README.md ├── esp32_cam_ftp.png └── esp32cam_ftp.ino /README.md: -------------------------------------------------------------------------------- 1 | # ESP32Cam_ftp 2 | 3 | Upload photos from ESP32-CAM to ftp server. 4 | 5 | ![Imagen](esp32_cam_ftp.png) 6 | 7 | Check out the [blog](http://www.gsampallo.com/blog/?p=686) for more details. 8 | -------------------------------------------------------------------------------- /esp32_cam_ftp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gsampallo/esp32cam_ftp/dc363de25910ca379941d0075a5d6b756cadcaaf/esp32_cam_ftp.png -------------------------------------------------------------------------------- /esp32cam_ftp.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * ESP32cam_ftp 3 | * Blog: http://www.gsampallo.com/blog/?p=686 4 | * Twitter: @gsampallo.com 5 | */ 6 | #include "esp_camera.h" 7 | #include "soc/soc.h" // Disable brownour problems 8 | #include "soc/rtc_cntl_reg.h" // Disable brownour problems 9 | #include "driver/rtc_io.h" 10 | #include 11 | #include 12 | #include "ESP32_FTPClient.h" 13 | 14 | #include //For request date and time 15 | #include 16 | #include "time.h" 17 | 18 | char* ftp_server = "FTP_SERVER"; 19 | char* ftp_user = "USER"; 20 | char* ftp_pass = "PASSWORD"; 21 | char* ftp_path = "/timelapse/"; 22 | 23 | const char* WIFI_SSID = "network"; 24 | const char* WIFI_PASS = "password"; 25 | 26 | WiFiUDP ntpUDP; 27 | NTPClient timeClient(ntpUDP, "pool.ntp.org", (-3600*3), 60000); 28 | 29 | ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2); 30 | 31 | // Pin definition for CAMERA_MODEL_AI_THINKER 32 | #define PWDN_GPIO_NUM 32 33 | #define RESET_GPIO_NUM -1 34 | #define XCLK_GPIO_NUM 0 35 | #define SIOD_GPIO_NUM 26 36 | #define SIOC_GPIO_NUM 27 37 | 38 | #define Y9_GPIO_NUM 35 39 | #define Y8_GPIO_NUM 34 40 | #define Y7_GPIO_NUM 39 41 | #define Y6_GPIO_NUM 36 42 | #define Y5_GPIO_NUM 21 43 | #define Y4_GPIO_NUM 19 44 | #define Y3_GPIO_NUM 18 45 | #define Y2_GPIO_NUM 5 46 | #define VSYNC_GPIO_NUM 25 47 | #define HREF_GPIO_NUM 23 48 | #define PCLK_GPIO_NUM 22 49 | 50 | camera_config_t config; 51 | 52 | void setup() { 53 | WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector 54 | 55 | Serial.begin(115200); 56 | 57 | WiFi.begin(WIFI_SSID, WIFI_PASS); 58 | 59 | Serial.println("Connecting Wifi..."); 60 | while (WiFi.status() != WL_CONNECTED) { 61 | delay(500); 62 | Serial.println("Connecting to WiFi.."); 63 | 64 | } 65 | Serial.println("IP address: "); 66 | 67 | Serial.println(WiFi.localIP()); 68 | 69 | initCamera(); 70 | 71 | timeClient.begin(); 72 | timeClient.update(); 73 | 74 | 75 | Serial.println(timeClient.getFullFormattedTimeForFile()); 76 | 77 | ftp.OpenConnection(); 78 | } 79 | 80 | void loop() { 81 | timeClient.update(); 82 | takePhoto(); 83 | delay(1000); 84 | } 85 | 86 | void initCamera() { 87 | config.ledc_channel = LEDC_CHANNEL_0; 88 | config.ledc_timer = LEDC_TIMER_0; 89 | config.pin_d0 = Y2_GPIO_NUM; 90 | config.pin_d1 = Y3_GPIO_NUM; 91 | config.pin_d2 = Y4_GPIO_NUM; 92 | config.pin_d3 = Y5_GPIO_NUM; 93 | config.pin_d4 = Y6_GPIO_NUM; 94 | config.pin_d5 = Y7_GPIO_NUM; 95 | config.pin_d6 = Y8_GPIO_NUM; 96 | config.pin_d7 = Y9_GPIO_NUM; 97 | config.pin_xclk = XCLK_GPIO_NUM; 98 | config.pin_pclk = PCLK_GPIO_NUM; 99 | config.pin_vsync = VSYNC_GPIO_NUM; 100 | config.pin_href = HREF_GPIO_NUM; 101 | config.pin_sscb_sda = SIOD_GPIO_NUM; 102 | config.pin_sscb_scl = SIOC_GPIO_NUM; 103 | config.pin_pwdn = PWDN_GPIO_NUM; 104 | config.pin_reset = RESET_GPIO_NUM; 105 | config.xclk_freq_hz = 20000000; 106 | config.pixel_format = PIXFORMAT_JPEG; 107 | 108 | if(psramFound()){ 109 | config.frame_size = FRAMESIZE_UXGA;//FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA 110 | config.jpeg_quality = 10; 111 | config.fb_count = 2; 112 | } else { 113 | config.frame_size = FRAMESIZE_UXGA; 114 | config.jpeg_quality = 12; 115 | config.fb_count = 1; 116 | } 117 | // Init Camera 118 | esp_err_t err = esp_camera_init(&config); 119 | if (err != ESP_OK) { 120 | Serial.printf("Camera init failed with error 0x%x", err); 121 | return; 122 | } 123 | } 124 | 125 | void takePhoto() { 126 | 127 | 128 | camera_fb_t * fb = NULL; 129 | 130 | 131 | // Take Picture with Camera 132 | fb = esp_camera_fb_get(); 133 | if(!fb) { 134 | Serial.println("Camera capture failed"); 135 | return; 136 | } 137 | 138 | /* 139 | * Upload to ftp server 140 | */ 141 | 142 | 143 | ftp.ChangeWorkDir(ftp_path); 144 | ftp.InitFile("Type I"); 145 | 146 | String nombreArchivo = timeClient.getFullFormattedTimeForFile()+".jpg"; // AAAAMMDD_HHMMSS.jpg 147 | Serial.println("Subiendo "+nombreArchivo); 148 | int str_len = nombreArchivo.length() + 1; 149 | 150 | char char_array[str_len]; 151 | nombreArchivo.toCharArray(char_array, str_len); 152 | 153 | ftp.NewFile(char_array); 154 | ftp.WriteData( fb->buf, fb->len ); 155 | ftp.CloseFile(); 156 | 157 | /* 158 | * Free 159 | */ 160 | esp_camera_fb_return(fb); 161 | } 162 | --------------------------------------------------------------------------------