Closed codingwithmeow closed 7 months ago
Hi, here my example ` /*
*/
uint8_t connection_state = 0; uint16_t reconnect_interval = 10000;
const char ssid = "YS"; const char password = "passwd";
//EMailSender emailSend("smtp_account@gmail.com", "
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);
while (!Serial) {delay(100);};
if(!LittleFS.begin()){
Serial.println("An Error has occurred while mounting LittleFS");
return;
}
File file = LittleFS.open("test.txt", "w");
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print("dajeeeeeeeeeeeeeeeeee")){
Serial.println("- file written");
} else {
Serial.println("- frite failed");
}
file.close();
Serial.println("ReadDir");
Dir dir = LittleFS.openDir("/");
while (dir.next()) {
Serial.print(dir.fileName());
if(dir.fileSize()) {
File f = dir.openFile("r");
Serial.println(f.size());
}
}
connection_state = WiFiConnect(ssid, password);
if(!connection_state) // if not connected to WIFI
Awaits(); // constantly trying to connect
EMailSender::EMailMessage message;
message.subject = "Soggetto";
message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";
EMailSender::FileDescriptior fileDescriptor[1];
fileDescriptor[0].filename = F("test.txt");
fileDescriptor[0].url = F("/test.txt");
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_LITTLE_FS;
fileDescriptor[0].mime = MIME_TEXT_PLAIN;
EMailSender::Attachments attachs = {1, fileDescriptor};
// fileDescriptor[0].filename = F("logo.jpg"); // fileDescriptor[0].url = F("/logo.jpg"); // fileDescriptor[0].mime = "image/jpg"; // fileDescriptor[0].encode64 = true; // fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_LITTLE_FS;
// EMailSender::Attachments attachs = {2, fileDescriptor};
EMailSender::Response resp = emailSend.send("renzo.mischianti@gmail.com", message, attachs);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
}
void loop() {
}
`
Bye Renzo
Hello,
So I want to send an email using Raspberry Pi Pico W I tried your examples and it did not work. You are saying it can be used in RP2040 can you explain how?
Thank you in advance