Replies: 5 comments 2 replies
-
First, you should config your filesystem in When you don't use |
Beta Was this translation helpful? Give feedback.
-
I don't see where you include You should use this SdFat library. And you should replace the following lines in ESP-Mail-Client/src/ESP_Mail_FS.h Lines 116 to 118 in 779c305 with #include <SdFat.h> //https://github.com/greiman/SdFat
static SdFat sd_fat_fs; //should declare as static here
#define ESP_MAIL_DEFAULT_SD_FS sd_fat_fs
#define ESP_MAIL_CARD_TYPE_SD 1
#define ESP_MAIL_SD_FS_FILE SdFile The following lines in your code are not necessary and can remove. #include <SPI.h>
#include <SdFat.h> In case you don't use ESP-Mail-Client/src/extras/SDHelper.h Lines 16 to 26 in 779c305 ESP-Mail-Client/src/extras/SDHelper.h Lines 49 to 50 in 779c305 And you should initialize the SD with this in your sketch. ESP-Mail-Client/src/extras/SDHelper.h Lines 83 to 92 in 779c305 I recommend you use
|
Beta Was this translation helpful? Give feedback.
-
Hi @mobizt My first try for about 2 days was to use SDHelper.h. into Part #1 of my code Then I tried to solve the problem with chatGBT and 'that' left out the statement '#include <extras/SDHelper.h>' so I commented it out. As far as SDCARD.h file you are trying to Google. It is my code. I am using 2 HEADER files in my code (actually more headers) #if sd_on // That is to enable logging data into SD This way works and I can choose whatever I like and see what works and what not. That is my method since I have plenty of sensors and libraries in place not used most of the time and only want I want to use is what goes into compilation. Finally inside SDhelper.h there is a section referring to SPI/SD connection pins.
The point is that all gone when an update chane the file SDhelper.h. I will now go to make what you are suggesting without using SDhelper.h but in the end I will go for the SDhelper.h approach but more reading is needed. |
Beta Was this translation helpful? Give feedback.
-
Thank you @mobizt . What I did to help you COMMON HEADER : SD_COMMON.h #ifndef SD_COMMON #include <ESP_Mail_Client.h> #define SPI_CS_PIN 5 // https://github.com/greiman/SdFat #endif MAIL SENDING HEADER: EMAI.h #ifndef EMAIL_H #include "SD_COMMON.h" const char* filename1 = "MAIL.txt"; // Temperature and Humidity file SMTPSession smtp; void smtpCallback(SMTP_Status status); // Callback function to get the Email sending status */ #define SMTP_HOST "smtp.gmail.com" /** For Gmail, the app password will be used for log in
void email_send_file(){
if (send_attached_file)
}
} /* Callback function to get the Email sending status /
} #endif SD STORE HEADER: SD_STORE #ifndef SDSTORE_H #include "SD_COMMON.h" String dataMessage; void logData(const String& data, const char* filename); bool sd_store_init() void sd_append_1(){ void sd_append_2(){ void logData(const String& data, const char* filename) { #endif ERRORS ****. the MAIL.txt file is defiantly inside SD . I can see it. 2 - When I insert into compilation SDSTORE.h (with this part I am logging data into different files) there is an error: "expected primary-expression before '.' token File dataFile = SdFile.open(filename, FILE_WRITE);" Thank you |
Beta Was this translation helpful? Give feedback.
-
OK thank you for your help so far. I will proceed and correct my code. Regards |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have error in a line that writes to an SD ''File' was not declared in this scope File dataFile = sd.open(filename, FILE_WRITE);'
ESP_Mail_Client.h library version 3.2.2
ESP32 core 2.09
I have 2 sections 2 parts of the program
#1 - the part that send the attachment file
#2 - the part that writes sensor data to SD using <SdFat.h>
Part #1 is working OK if Part #2 is OFF.
Part #2 is working OK if Part #1 is OFF.
When Part #1 and Part #2 is included in the program I have the following error :
'SDSTORE.h:67:3: error: 'File' was not declared in this scope
File dataFile = sd.open(filename, FILE_WRITE);'
The conflict is something to do with ESP_Mail_Client.h library but I spent one day trying to solve with no success.
chatGBT helped me a lot but in the end failed to give me the code without the problem.
I only imagine where the problem is but I can not solve it.
Here is the 2 parts of the code:
Part #1
#ifndef EMAIL_H
#define EMAIL_H
#include <ESP_Mail_Client.h>
//#include <extras/SDHelper.h>
const char* filename1 = "MAIL.txt"; // Temperature and Humidity file
const char* filename1_path = "/MAIL.txt"; // Temperature and Humidity file
SMTPSession smtp;
void smtpCallback(SMTP_Status status); // Callback function to get the Email sending status */
void wifi_init_email();
void email_init();
void email_send_file();
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 587
#define AUTHOR_EMAIL "[email protected]"
#define AUTHOR_PASSWORD "xxx"
#define RECIPIENT_EMAIL "xxx"
Part #2
#ifndef SDCARD_H
#define SDCARD_H
#include <SPI.h>
#include <SdFat.h>
const int chipSelect = 5; // Change this to your SD card CS pin
SdFat sd;
SdFile attachmentFile;
String dataMessage;
float temperature_sd;
float humididty_sd;
float noise_sd;
void logData(const String& data, const char* filename);
void sd_init();
void sd_append_1();
void sd_append_2();
void sd_init(){
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized successfully!");
}
void sd_append_1(){
#if ahtx0_on
temperature_sd = (sensor_db[0].ahtx0_temp); //bme680 TEMPERATURE
humididty_sd = (sensor_db[0].ahtx0_hum); //bme680 HUMIDITY
char buffer_temp[10]; // Adjust the buffer size according to your needs
char buffer_hum[10]; // Adjust the buffer size according to your needs
dtostrf(temperature_sd, 4, 1, buffer_temp); // 4 total digits (including decimal point), 1 decimal place
dtostrf(humididty_sd, 4, 1, buffer_hum); // 4 total digits (including decimal point), 1 decimal place
#if timestamp_on
time_read();
#endif
dataMessage = (sensor_db[0].datestamp) + "," + // DATE
(sensor_db[0].timestamp) + "," + // TIME
buffer_temp + "," + // TEMPERATURE
buffer_hum; // HUMIDITY
logData(dataMessage, fn1);
//Serial.println("SD DONE TEMP & HUM");
#endif
}
void sd_append_2(){
#if inmp441_on
noise_sd = (sensor_db[0].inmp441_sound); //NOISE LEVEL
char buffer_noise[10]; // Adjust the buffer size according to your needs
dtostrf(noise_sd, 4, 1, buffer_noise); // 4 total digits (including decimal point), 1 decimal place
#if timestamp_on
time_read();
#endif
dataMessage = (sensor_db[0].datestamp) + "," + // DATE
(sensor_db[0].timestamp) + "," + // TIME
buffer_noise; // NOISE
logData(dataMessage, fn2);
//Serial.println("SD DONE NOISE");
#endif
}
void logData(const String& data, const char* filename) {
File dataFile = sd.open(filename, FILE_WRITE);
if (dataFile) {
dataFile.println(data);
dataFile.close();
Serial.println("Data logged to " + String(filename) + ": " + data);
} else {
Serial.println("Error opening " + String(filename) + "!");
}
}
#endif
String readDataFromFile() {
File dataFile = sd.open(filename1); // Replace "your_file_name.txt" with the actual file name
if (dataFile) {
// Read the data from the file
String data = dataFile.readString();
dataFile.close();
return data;
} else {
Serial.println("Error opening data file!");
return "";
}
}
void sendEmailWithAttachment(const String& attachmentData) {
// Create the email client and session objects
ESP_Mail_Session session("smtp_server", 465, "email_address", "email_password", "Sender Name");
ESP_Mail_Client mailClient(session);
}
#endif
Any help greatly appreciated
Beta Was this translation helpful? Give feedback.
All reactions