I have a ESP32 AIthinker CAM. I have the ESP32 CAM book . I successfully used the code in the book to take a photo and send the photo as an attachment to my Gmail (great!). As similar article is on:
Instead of using SPIFFS I wish to attach a file from the SD card. I believe that SPIFFS memory is only about 1.3 MB and it also has a limited life of writes (100,000?), regardless it’s too small. All of the examples in the book uses SPIFFS, for sending emails. It gives an example on how to store a picture on a SD card. This website has a similar tutorial for SD card saving https://randomnerdtutorials.com/esp32-cam-take-photo-save-microsd-card/
I tried to merge the codes of both examples, but the email never has the attachment. Even when I just try and send a saved photo “/photo.jpg” it does not work. I did change the code as follows;
Is there a reason why the book never tried this because it can not be done? Or am I missing one minor setting?
I was able to send an email with SD attachment using the code from indestructables
However the image quality is very very bad; unacceptable (very dark with a green tinge).
The indestructibles uses SD.h library whilst the Random Nerds code uses SD_MMC.h .
Can anyone give clues why the SD.h file saving method makes a terrible quality picture and/or why can’t the SD_MMC.h attach the picture in the email?
After searching for a while, it seems that the MailClient library doesn’t support the SD_MMC library.
The SD library works well with the MaiClient library and I’m also able to send the photo. But, the photos with the SD library are more green than the others and worst quality.
I think it may be because SD and SD_MMC are different:
“SD runs on SPI, and SD_MMC uses the SDMMC hardware bus on the ESP32.”
It should be possible to attach the picture to the email using SD_MMC, but maybe not with this library.
Thank you for your response. It saved me a lot of time. Please consider updating your web page that the SD_MMC.h library can not send email with attachments from SD card and the SD.h library saves terrible photos.
I have found a partial fix but need help in one final part.
I put both SD.h and SD_MMC.h into one function. It first saves the photo using the SD_MMC.h library and then emails using the SD.h library. It successfully saved the photo on the SD card using SD_MMC.h, but then the SD card did not initialise/mount with the SD.h library. To fix this after the photo was taken using SD_MMC.h the ESP went to deepsleep for 10ms and when it woke up the SD card was able to initialise/mount with SD.h library and email with attachment was sent.
After the email was sent I put the ESP32 to sleep again so the server code and SD_MMC.h could load up again and be ready for the next photo. Unfortunately the SD card could not intitlise/mount and had an error
Starting SD Card MMC
E (4862) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
SD Card Mount Failed MMC
Failed to open directory
I did try ESP.restart(); , but no success. I also tried pressing the rest button on the board with no success. I was only able to load the SD_MMC.h library by cutting the power and turning it on again. Is there a software way to flush all memory out of the ESP as if it was a power turn off? Or is there a way to dismount the SDcard via software? Also why does discionnecting the power fix the problem, but not reset, I had a similar issue with DS18B20 temperature sensors only fixing thier zero readings only when the power was unplugged.
I searched for a while, and the SD.h library doesn’t have any function to close/stop the sd card.
There is a way to disable SDMMC peripherals, but I don’t know exactly how to use it with Arduino IDE: https://docs.espressif.com/projects/esp-idf/en/v3.0.9/api-reference/storage/sdmmc.html#protocol-layer-apis
Can you share the snippet of code that does what you mention? If I take a look at the code, maybe I can find something.
Thank you. I do not understand how to use these commands, I am learning amateur (duct tape programmer!) trying to make useful electronics for personal and work (agriculture). So I have abandoned trying to get SD.h and SD_MMC.h working together. I have worked on another way to send photos by email and save a copy on the SD by joining two of your projects together (SFIFFS photo email and save photo to SD card). I will post this code soon for I found a little issue that adds a second or two to the procedure, but it works..
I’m happy that you’ve found a workaround for your project and got it working.
If you want, please share your code with us.
I managed to get the code working to to take a photo, store the photo on a SD card and send the photo as a email attachment.
Below is the code and descriptions of minor problems I could not fix. I could not get the code to inject the file name above the picture to work.
/********* Rui Santos Complete instructions at https://RandomNerdTutorials.com/esp32-cam-projects-ebook/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. This code is a merging of two code examples from the Rui Santos ESP32 CAM book (good book) from the pages below to take a photo, store the photo on a SD card and send the photo as a email attachment. p145 Module 2 Unit 6: Web Server SD Card Photo Manager: Capture, View and Delete p201 Module 3 Unit 3: Take and Email Photo with a Web Server Similar code can be found on their website.