Hello. Thank you for the EmailSender library which is really useful.
I’m trying to use it on a Raspberry Pico W environment
and the ESP8266SdFat library on SPI 1.
I defined in the EMailSenderKey.h file
#define SD_CS_PIN 13 instead of #define SD_CS_PIN SS
The mail message part is ok, but not the attachment of the .CSV file
If you can help me.
Thank you.
Bord is Raspberry Pi W with :
Raspberry Pi RP2040 Core platform file By Earle F. Philhower
name=Raspberry Pi RP2040 Boards(2.3.3)
version=2.3.3
#include <EMailSender.h>
#include <WiFi.h>
#include "SdFat.h"
#include <stdio.h>
#include "sdios.h"
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "hardware/gpio.h"
#include "SdFat.h"
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 1
// Try max SPI clock for an SD 50. Reduce SPI_CLOCK if errors occur.
#define SPI_CLOCK SD_SCK_MHZ(80)
// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
#endif // HAS_SDIO_CLASS
#if SD_FAT_TYPE == 0
SdFat sd;
File file;
File root;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
File32 file;
#elif SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
#elif SD_FAT_TYPE == 3
SdFs sd;
FsFile file;
#else // SD_FAT_TYPE
#error Invalid SD_FAT_TYPE
#endif // SD_FAT_TYPE
//——————————————————————————
// store error strings in flash memory
#define error(s) sd.errorHalt(PSTR(s))
//——————————————————————————
uint8_t connection_state = 0;
uint16_t reconnect_interval = 10000;
EMailSender emailSend(email_login, email_password, email_from, smtp_server,
smtp_port);
uint8_t WiFiConnect(const char *nSSID = nullptr,
const char *nPassword = nullptr) {
static uint16_t attempt = 0;
Serial.print("Connecting to ");
if (nSSID) {
WiFi.begin(nSSID, nPassword);
Serial.println(nSSID);
}
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 50) {
delay(200);
Serial.print(".");
}
++attempt;
Serial.println("");
if (i == 51) {
Serial.print("Connection: TIMEOUT on attempt: ");
Serial.println(attempt);
if (attempt % 2 == 0)
Serial.println(
"Check if access point available or SSID and Password\r\n");
return false;
}
Serial.println("Connection: ESTABLISHED");
Serial.print("Got IP address: ");
Serial.println(WiFi.localIP());
return true;
}
void Awaits() {
uint32_t ts = millis();
while (!connection_state) {
delay(50);
if (millis() > (ts + reconnect_interval) && !connection_state) {
connection_state = WiFiConnect();
ts = millis();
}
}
}
void setup() {
Serial.begin(115200);
delay(2000);
// initialisation carte SD
if (!sd.begin(SD_CS_PIN)) {
Serial.println("WARNING initialization SD failed!");
delay(1000);
} else {
Serial.println(F("Card is present."));
}
// Show capacity and free space of SD card
Serial.print(F("Capacity of card: "));
Serial.print(long(sd.card()->sectorCount() >> 1));
Serial.println(F(" kBytes"));
Serial.print(F("\nList of files on the SD.\n"));
sd.ls(LS_R);
connection_state = WiFiConnect(ssid, password);
if (!connection_state) // if not connected to WIFI
Awaits(); // constantly trying to connect
EMailSender::FileDescriptior fileDescriptor[1];
fileDescriptor[0].filename = F("Bernard_05011701_2023.CSV");
fileDescriptor[0].url = F("/Bernard_05011701_2023");
fileDescriptor[0].mime = MIME_TEXT_PLAIN;
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
EMailSender::Attachments attachs = { 1, fileDescriptor };
EMailSender::EMailMessage message;
message.subject = "Data File Result";
message.message =
"Resultat de l’annalyse.\n\r 1er test sans piece attachée\n\r NE PAS REPONDRE A CETTE ADRESSE.";
Serial.println("All structure created!");
EMailSender::Response resp = emailSend.send("xxx@gmx.fr", message, attachs);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
}
void loop() {
}
Out Serial.print :
Card is present.
Capacity of card: 7864320 kBytes
List of files on the SD.
.eeprom
.wifi
.log.csv
Bernard_05011701_2023.CSV
Connecting to Linux
Connection: ESTABLISHED
Got IP address: 192.168.1.32
All structure created!
ONLY ONE RECIPIENTmiltiple destination and attachments
Insecure client:0
smtp.free.fr
465
220 smtp6-g21.free.fr ESMTP Postfix
HELO mischianti
250 smtp6-g21.free.fr
AUTH LOGIN:
334 VXNlcm5hbWU6
Encoding
xxxxx@free.fr
13
ZjVleG9AZnJlZS5mcg==
Encoding
xxxx@free.fr
13
334 UGFzc3dvcmQ6
Encoding
pwd
8
c3U4ODY3aTE=
Encoding
pwd
8
235 2.7.0 Authentication successful
MAIL FROM: <xxxx@free.fr>
250 2.1.0 Ok
RCPT TO: <xxxx@gmx.fr>
250 2.1.5 Ok
DATA:
354 End data with <CR><LF>.<CR><LF>
Message end
250 2.0.0 Ok: queued as ABBC37802E5
221 2.0.0 Bye
Sending status:
1
0
Message sent!
This topic was modified 1 year, 4 months ago by Renzo Mischianti.
This topic was modified 1 year, 4 months ago by Renzo Mischianti.
compile ok
Card is present.
Capacity of card: 7864320 kBytes
List of files on the SD.
.eeprom
.wifi
.log.csv
test.txt
logo.jpg
Bernard_05011701_2023.CSV
Connecting to Linux
Connection: ESTABLISHED
Got IP address: 192.168.1.32
All structure created!
When : #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD
problem to compil :
In file included from /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:35:
/home/erick/Arduino/libraries/EMailSender/EMailSender.h:306: warning: "EMAIL_NETWORK_CLASS" redefined
306 | #define EMAIL_NETWORK_CLASS EMAIL_NETWORK_SSL_CLASS
|
In file included from /home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:35:
/home/erick/Arduino/libraries/EMailSender/EMailSender.h:186: note: this is the location of the previous definition
186 | #define EMAIL_NETWORK_CLASS WiFiClient
|
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp: In member function 'EMailSender::Response EMailSender::send(const char**, byte, byte, byte, EMailSender::EMailMessage&, EMailSender::Attachments)':
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:907:39: error: 'SD_CS_PIN' was not declared in this scope; did you mean 'SPIFM_CS_PIN'?
907 | if(!EXTERNAL_STORAGE_CLASS.begin(SD_CS_PIN)){
| ^~~~~~~~~
| SPIFM_CS_PIN
exit status 1
Errore durante la compilazione per la scheda Raspberry Pi Pico W.
-----------
SS pin is define in the top with , and ok to SD access.
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
It’s better but another problem
Here is the SD_FAT_TYPE
// 1 for FAT16/FAT32
#define SD_FAT_TYPE 1
and Sdat library is ESP8266SdFat contained in Earle F. Philhower RP2040 package 2.7.1
Card is present.
Capacity of card: 7864320 kBytes
List of files on the SD.
.eeprom
.wifi
.log.csv
test.txt
logo.jpg
Bernard_05011701_2023.CSV
Connecting to Linux
Connection: ESTABLISHED
Got IP address: 192.168.1.32
All structure created!
.
.
.
..
RCPT TO: <ffffff@gmx.fr>
250 2.1.5 Ok
Compil problem :
|
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp: In member function ‘EMailSender::Response EMailSender::send(const char**, byte, byte, byte, EMailSender::EMailMessage&, EMailSender::Attachments)’:
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:935:54: error: conversion from ‘File32’ to non-scalar type ‘FsFile’ requested
935 | EMAIL_FILE_EX myFile = EXTERNAL_STORAGE_CLASS.open(attachments.fileDescriptor[i].url.c_str());
/home/erick/Arduino/libraries/EMailSender/EMailSender.cpp:985:29: error: ‘SdFat’ {aka ‘class SdFat32’} has no member named ‘end’
985 | EXTERNAL_STORAGE_CLASS.end();
| ^~~
Hello Renzo
After several type of tests, I arrived at something positive.
If this can be a clue for you, here is what I did to get it to work properly.
Erick
if (sdActive){
DEBUG_PRINTLN(F(“SD end”));
#ifndef ARDUINO_ESP8266_RELEASE_2_4_2
-> //EXTERNAL_STORAGE_CLASS.end();
#endif
DEBUG_PRINTLN(F(“SD end 2″));
}
*/
Debug out :
DATA:
354 End data with <CR><LF>.<CR><LF>
Array: Bernard_05011701_2023.CSV
–frontier
Content-Type:
text/csv
; charset=”UTF-8”
Readed filename: Bernard_05011701_2023.CSV
SD Check
Open file:
OK
NORMAL
Message end
250 2.0.0 Ok: queued as 596F678035E
221 2.0.0 Bye
Sending status:
1
0
Message sent!
Hi Erick,
I understand the ESP8266SdFat given by Raspberry is different from the original one, so I integrate your change in the version that you can find in the master branch.
Another question if I can afford Renzo:
With some provider the message is indeed sent, but not delivered.
Probably because of HELO contents.
Can it be contained in an external const char* if it’s possible ?
Thank you for all.
Erick
——————————————
250 2.1.5 Ok
DATA:
354 End data with <CR><LF>.<CR><LF>
Array: Bernard_05011701_2023.CSV
–frontier
Content-Type:
text/csv
; charset=”UTF-8″
Readed filename: Bernard_05011701_2023.CSV
SD Check
Open file:
OK
NORMAL
Message end
250 2.0.0 Ok: queued as 05021780304
221 2.0.0 Bye
Sending status:
1
0
Message sent!
A new problem, with a file join type csv.
When a line is longer than 1071 characters, the line is broken with a newline character.
And also a newline character is added at the end of the file. (For this it is not too annoying).
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.