Skip to content

Instantly share code, notes, and snippets.

@nishanc
Created May 15, 2021 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/a4d28d411e2a805abccff52ecf4a6211 to your computer and use it in GitHub Desktop.
Save nishanc/a4d28d411e2a805abccff52ecf4a6211 to your computer and use it in GitHub Desktop.
static esp_err_t save_photo_numbered()
{
file_number++;
Serial.print("Taking picture: ");
Serial.print(file_number);
camera_fb_t *fb = esp_camera_fb_get();
//char *filename = (char*)malloc(21 + sizeof(int));
char *filename = (char*)malloc(21 + sizeof(file_number));
sprintf(filename, "/sdcard/capture_%d.jpg", file_number);
Serial.println(filename);
FILE *file = fopen(filename, "w");
if (file != NULL) {
size_t err = fwrite(fb->buf, 1, fb->len, file);
Serial.printf("File saved: %s\n", filename);
} else {
Serial.println("Could not open file");
}
fclose(file);
esp_camera_fb_return(fb);
free(filename);
}
static esp_err_t save_photo_dated()
{
Serial.println("Taking picture...");
camera_fb_t *fb = esp_camera_fb_get();
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%F_%H_%M_%S", &timeinfo);
char *filename = (char*)malloc(21 + sizeof(strftime_buf));
sprintf(filename, "/sdcard/capture_%s.jpg", strftime_buf);
Serial.println(filename);
FILE *file = fopen(filename, "w");
if (file != NULL) {
size_t err = fwrite(fb->buf, 1, fb->len, file);
Serial.printf("File saved: %s\n", filename);
} else {
Serial.println("Could not open file");
}
fclose(file);
esp_camera_fb_return(fb);
free(filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment