Can you tell me how can I save 5 images to flash and then delete after 10 seconds?
Checking the picture and saving it in flash memory:
Code: Select all
char FILE_PHOTO[10];
int i = 1;
1. bool checkPhoto( fs::FS & fs ) {
2. File f_pic = fs.open( FILE_PHOTO );
3. unsigned int pic_sz = f_pic.size();
4. return ( pic_sz > 100 );
5. }
6.
7. // Capture Photo and Save it to SPIFFS
8. void capturePhoto( void ) {
9.
10. camera_fb_t * fb = NULL; // pointer
11. bool ok = 0; // Boolean indicating if the picture has been taken correctly
12.
13. // Take a photo with the camera
14. Serial.println("Taking a photo...");
15.
16. fb = esp_camera_fb_get();
17. if (!fb) {
18. Serial.println("Camera capture failed");
19. return;
20. }
21.
22. do {
23.
24. Serial.printf("Picture file name: %s\n", FILE_PHOTO);
25. File file = SPIFFS.open(FILE_PHOTO, FILE_WRITE);
26.
27. // Insert the data in the photo file
28. if (!file) {
29. Serial.println("Failed to open file in writing mode");
30. }
31. else {
32. file.write(fb->buf, fb->len); // payload (image), payload length
33.
34. Serial.print("The picture has been saved in ");
35. Serial.print(FILE_PHOTO);
36. Serial.print(" - Size: ");
37. Serial.print(file.size());
38. Serial.println(" bytes");
39. }
40. file.close();
41. SPIFFS.remove(FILE_PHOTO);
42. esp_camera_fb_return(fb);
43. ok = checkPhoto(SPIFFS);
44.
45. } while ( !ok );
46. }