Raspberry Pico W & EmailSender

Viewing 15 reply threads
  • Author
    Posts
    • #23916
      Erick
      Participant

        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!
        
        
      • #23919
        Renzo Mischianti
        Keymaster

          Hi Erick,
          I think you don’t enable STORAGE_SD on external storage in EMailSenderKey.h.
          Please paste your EMailSenderKey.h.
          Bye Renzo

          • #28657
            Erick
            Participant

              Ican’t use SD because filename has more 8 caracters …
              And SD card is on SPI1 not SPI0
              It’s more easy to use SDFS for me.

              Sory.

              Erick

            • #28658
              Erick
              Participant

                Yes I’m confused !
                Now It’s good.

                Many Thank’s Renzo.

            • #23946
              Erick
              Participant

                Thank’s for your replay Renzo
                I think that’s it too, because the latest debug lines are :
                ————————————-
                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
                Sending status:
                0
                500
                EMAIL_STORAGE_TYPE_SD not enabled on EMailSenderKey.h
                ———————————-

              • #23949
                Renzo Mischianti
                Keymaster

                  Hi,
                  change this

                  
                  #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                      #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                      #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                      #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_NONE
                  #endif
                  

                  to

                  
                  #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                      #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                      #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                      #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD
                  #endif
                  

                  Bye Renzo

                • #23965
                  Erick
                  Participant

                    Hi Renzo
                    New problem …
                    with :

                    // Arduino SAMD microcontrollers configuration
                    #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                        #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                        #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                        #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_NONE
                    #endif

                    and

                    //#define SD_CS_PIN SS
                    #define SPIFM_CS_PIN SS
                    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;

                  • #23967
                    Renzo Mischianti
                    Keymaster

                      Hi Erick,
                      you can’t remove the define in the library header

                      //#define SD_CS_PIN SS

                      If you put define it externally It survives in the external context, not in the internal of the library.

                      Bye Renzo

                    • #23968
                      Erick
                      Participant

                        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

                        DATA:
                        354 End data with <CR><LF>.<CR><LF>

                        Array: test.txt
                        –frontier
                        Content-Type:
                        text/plain
                        ; charset=”UTF-8″
                        Readed filename: test.txt
                        SD Check
                        Sending status:
                        0
                        500
                        Error on startup SD filesystem!

                      • #23969
                        Renzo Mischianti
                        Keymaster

                          Hi Erick,
                          try STORAGE_SDFAT2.
                          Bye RM

                        • #23970
                          Erick
                          Participant

                            Thank you for your speed Renzo.

                            With :
                            #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                            #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                            #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                            #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT2
                            #endif

                            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();
                            | ^~~

                          • #24002
                            Erick
                            Participant

                              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

                              
                              /*
                              in Key.h
                              #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                              #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                              #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                              -> //#define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SD
                              -> #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT2
                              #endif
                              
                              -> #define SD_CS_PIN 13
                              

                              in .h
                              Ligne 290

                              
                              #define EMAIL_FILE_READ_EX FILE_READ
                              -> //#define EMAIL_FILE_EX FsFile
                              -> #define EMAIL_FILE_EX File32
                              

                              in .cpp
                              line 982

                              
                              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!
                              
                            • #24005
                              Renzo Mischianti
                              Keymaster

                                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.

                                
                                #ifndef DEFAULT_EMAIL_NETWORK_TYPE_RP2040
                                    #define DEFAULT_EMAIL_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
                                    #define DEFAULT_INTERNAL_ARDUINO_RP2040_STORAGE STORAGE_LITTLEFS
                                    #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFAT_RP2040_ESP8266
                                #endif
                                

                                Please try it and give me feedback.
                                Thanks, Renzo

                              • #24008
                                Erick
                                Participant

                                  OK Many Thank’s Renzo IT’S SUPER GOOD !

                                  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!

                                • #24009
                                  Renzo Mischianti
                                  Keymaster

                                    Hi,
                                    you can change HELO contents with

                                    
                                    setPublicIpDescriptor("Pippo");
                                    

                                    Bye Renzo

                                  • #25386
                                    Erick
                                    Participant

                                      Hi Renzo

                                      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).

                                      Thank you

                                      Erick

                                    • #28633
                                      Erick
                                      Participant

                                        Hi Renzo

                                        i am back,
                                        Now with RP2040 I no longer use SdFat but SDFS instead
                                        can you add with RP2040 SDFS

                                        #define DEFAULT_EXTERNAL_ARDUINO_RP2040_STORAGE STORAGE_SDFS

                                        https://arduino-pico.readthedocs.io/en/latest/fs.html

                                        Thank’s you.
                                        Erick

                                      • #28642
                                        Renzo Mischianti
                                        Keymaster

                                          Hi Erick,
                                          Do you already try to set the SD filesystem in the external storage?
                                          Bye Renzo

                                      Viewing 15 reply threads
                                      • You must be logged in to reply to this topic.
                                      Exit mobile version