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!
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 needed
With this, it works as charm and uses much less resources to send emails than other similar libraries.
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
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.