-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP32-CAM-2-FTP.ino
72 lines (49 loc) · 1.46 KB
/
ESP32-CAM-2-FTP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "settings.h"
#include "camera.h"
#include "wifi.h"
#include "ftp.h"
const char ftp_remote_dir[] = "/pics";
void setup() {
Serial.begin(115200);
Serial.println("Serial [OK]");
if(!SD_MMC.begin()){
Serial.println("SD Card Mount Failed");
return;
}
Serial.println("SD Card [OK]");
if (cameraInit())
Serial.println("CAMERA [OK]");
wifi_connect();
Serial.println("WIFI [OK]");
configure_ftp();
Serial.println("FTP [OK]");
}
void loop() {
char ftp_server_c [20];
char ftp_user_c [20];
char ftp_pass_c [20];
strcpy (ftp_server_c, ftp_server.c_str());
strcpy (ftp_user_c, ftp_user.c_str());
strcpy (ftp_pass_c, ftp_pass.c_str());
ESP32_FTPClient ftp(ftp_server_c, 21, ftp_user_c, ftp_pass_c, 1000, 2);
int pictureNumber = readIntFromFile("/picno.txt") + 1;
delay(1000); // say cheese!!
String path = "pic_" + String(pictureNumber) +".jpg";
camera_fb_t *fb = NULL;
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
return;
}
delay(500); // not even sure why... :-/
ftp.OpenConnection();
ftp.InitFile("Type I");
ftp.ChangeWorkDir(ftp_remote_dir);
ftp.NewFile(path.c_str());
ftp.WriteData(fb->buf, fb->len);
ftp.CloseFile();
esp_camera_fb_return(fb);
writeIntToFile("/picno.txt", pictureNumber);
delay(5000);
delay(5000);
}