Home › Forums › The libraries hosted on the site › EMailSender send email with attachments › Use SD file system defined for EmailSender to create new files in SD
Tagged: EMailSender, SD
- This topic has 2 replies, 2 voices, and was last updated 1 year, 4 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
15 December 2023 at 15:49 #28818
Hello, and many thanks to Renzo, for this wonderful project!!
I have successfully installed EmailSender.h v3.0.13 in a d1Mini ESP8266 board with a SD card, using Arduino IDE V2.2.1.
I only had to set the option “#define DEFAULT_EXTERNAL_ESP8266_STORAGE STORAGE_SD” in EmailSenderKey.h, all other options are left by default, I had to write a very short squetch and voila! it is sending to my email messages with file attachments from the SD!I am trying to do a data logger that should capture some data, append it to a file in the SD, and send the file periodically by email. It is a plain text file.
This works very well, but only when the files are previously loaded in the SD. Until now I can not imagine how to access the SD to create or modify files with my own code in the same squetch.
The SD file system defined by EmailSender is fine, it is working, because it reads files to attach and send them OK. The problem is that I don´t know which instance of SD FS should I use, which name give to my own file objects or how to access and use the same SD file system for my own purposes, to reference, open, read, write or close files in the SD. My squetch is as simple as that, and the code I don’t know how to do is in loop() section:
—————
#include "Arduino.h" #include <EMailSender.h> // tested with version 3.0.13 (see https://github.com/xreef/EMailSender) const char * ssid = " ** ** "; // edit to your own value const char * password = " ** ** "; // edit to your own value // global variables for this squetch uint8_t connection_state = 0; uint16_t reconnect_interval = 10000; const size_t txtsize = 60; // lenght for txt buffer including final {0} char txt[txtsize] = ""; // auxiliary buffer for text formatting // constructor for EMailSender /EMailSender emailSend("***@gmail.com", "password", "myDev"); / / edit to your own values void setup() { Serial.begin(115200); delay(500); // connect to WiFi WiFi.begin(ssid, password); Serial.println("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // create message, subject is chip_id (int32) as hex string EMailSender::EMailMessage message; snprintf(txt, txtsize, " % s % X", "Message from", system_get_chip_id()); message.subject = txt; message.mime = "text / html"; message.message = "Ciao come stai < br > io bene. < br > www.mischianti.org"; // define attachments EMailSender::FileDescriptior fileDescriptor[1]; // define only 1 attachment fileDescriptor[0].filename = "test.txt"; fileDescriptor[0].url = "/test.txt"; fileDescriptor[0].mime = "text / plain"; fileDescriptor[0].encode64 = false; fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD; EMailSender::Attachments attachs = { 1, fileDescriptor }; // send message EMailSender::Response resp = emailSend.send("test @mundobiji.com > ", message, attachs); // print sending result Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); } // end of setup() void loop() { // This section compiles without errors but does not work !!!!! FsFile myfile; myfile.open("test.txt", O_RDWR | O_CREAT | O_AT_END); // open to append: this fails txt = "some new data"; myfile.write(txt, strlen(txt)); // this should append new data myfile.close(); // send file test.txt again by email with EmailSender // … // wait and repeat delay(60000); } // end of loop()
—————
Please, could you give me any ideas about that? How can I reference the SD File system created by EmailSender to create and use a new file? Thank you in advance!-
This topic was modified 1 year, 5 months ago by
Mariano B.
-
This topic was modified 1 year, 5 months ago by
-
22 January 2024 at 02:54 #29313
SOLVED!
It seems as there is a bug in EmailSender.h file when using STORAGE_SDFAT2 option: using SdFat library with ESP8266, you have to edit line 323 of this file in the section ‘#elif (EXTERNAL_STORAGE == STORAGE_SDFAT2)’
from ‘extern SdFat EXTERNAL_STORAGE_CLASS;’
to ‘extern SdFs EXTERNAL_STORAGE_CLASS;’For others interested to use this wonderful library to build small devices that must log data in the SD and send a file by email, my settings in file EMailSenderKey.h from default must be set as follows:
#define SD_CS_PIN D4 // GPIO pin connected to my SD CS pin
#define DEFAULT_EXTERNAL_ESP8266_STORAGE STORAGE_SDFAT2
#define DEFAULT_EXTERNAL_ESP32_STORAGE STORAGE_SDFAT2
#define DEFAULT_INTERNAL_ESP8266_STORAGE STORAGE_NONE
#define DEFAULT_INTERNAL_ESP32_STORAGE STORAGE_NONE
#define STORAGE_INTERNAL_FORCE_DISABLE // if internal storage is not neededWith this, it works as charm and uses much less resources to send emails than other similar libraries.
Thank you, Renzo!
-
22 January 2024 at 08:34 #29319
Hi Mariano,
Thanks a lot for your feedback.It’s strange my version works with SdFat as the key to manage the connection, not SdFs, but I think It can be the style of programming that determines the problem; the interaction method must be the same as the library.
Thanks again Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.