Skip to content

Commit

Permalink
Fix filesystems, native Ethernet and Ethernet integration issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Sep 15, 2023
1 parent 74e45c6 commit b1cb92c
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 64 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,33 @@ ENABLE_SMTP // For SMTP class compilation
ENABLE_NTP_TIME // For enabling the device or library time setup from NTP server
ENABLE_ERROR_STRING // For enabling the error string from error reason
ESP_MAIL_USE_PSRAM // For enabling PSRAM support
ESP_MAIL_DEFAULT_FLASH_FS // For enabling flash filesystem support
ESP_MAIL_DEFAULT_SD_FS // For enabling SD filesystem support
ESP_MAIL_DEFAULT_FLASH_FS // For enabling Flash filesystem support
ESP_MAIL_DEFAULT_SD_FS // For enabling SD filesystem support
ESP_MAIL_CARD_TYPE_SD or ESP_MAIL_CARD_TYPE_SD_MMC // The SD card type for SD filesystem
```

The Flash and SD filesystems are predefined.

SD is the default SD filesystem for all devices.

For ESP8266 and Arduino Pico, LittleFS is the default flash filesystem.

For ESP32 since v2.0.x, LittleFS is the default flash filesystem otherwise SPIFFS is the default flash filesystem.

In otherr devices, SPIFFS is the default flash filesystem.

User can change `ESP_MAIL_DEFAULT_FLASH_FS` and `ESP_MAIL_DEFAULT_SD_FS` with `ESP_MAIL_CARD_TYPE_SD` or `ESP_MAIL_CARD_TYPE_SD_MMC` defined values for other filesystems.


### Optional Options

The following options are not yet defined in [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) and can be assigned by user.

```cpp
SILENT_MODE // For silent operation (no debug printing and callback)
ESP_MAIL_ETHERNET_MODULE_LIB `"EthernetLibrary.h"` // For the Ethernet library to work with external Ethernet module
ESP_MAIL_ETHERNET_MODULE_CLASS EthernetClass // For the Ethernet class object of Ethernet library to work with external Ethernet module
ESP_MAIL_ETHERNET_MODULE_TIMEOUT 2000 // For the time out in milliseconds to wait external Ethernet module to connect to network
ENABLE_ESP8266_ENC28J60_ETH // For ENC28J60 Ethernet module support in ESP8266
ENABLE_ESP8266_W5500_ETH // For W5500 Ethernet module support in ESP8266
ENABLE_ESP8266_W5100_ETH // For W5100 Ethernet module support in ESP8266
Expand All @@ -415,6 +432,15 @@ build_flags = -D ESP_MAIL_DEBUG_PORT=Serial
-D ESP_MAIL_DISABLE_ONBOARD_WIFI
```

For external Ethernet module integation used with function `setEthernetClient`, both `ESP_MAIL_ETHERNET_MODULE_LIB` and `ESP_MAIL_ETHERNET_MODULE_CLASS` should be defined.

`ESP_MAIL_ETHERNET_MODULE_LIB` is the Ethernet library name with extension (.h) and should be inside `""` or `<>` e.g. `"Ethernet.h"`.

`ESP_MAIL_ETHERNET_MODULE_CLASS` is the name of static object defined from class e.g. `Ethernet`.

`ESP_MAIL_ETHERNET_MODULE_TIMEOUT` is the time out in milliseconds to wait network connection.


For disabling predefined options instead of editing the [**ESP_Mail_FS.h**](src/ESP_Mail_FS.h) or using `#undef` in `Custom_ESP_Mail_FS.h`, you can define these build flags with these names or macros in `Custom_ESP_Mail_FS.h`.

```cpp
Expand Down
6 changes: 6 additions & 0 deletions examples/SMTP/External_Client/EthernetClient/ESP32/ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@

#include <ESP_Mail_Client.h>

// https://github.com/arduino-libraries/Ethernet
#include <Ethernet.h>

// For using other Ethernet library that works with other Ethernet module,
// the following build flags or macros should be assigned in src/ESP_Mail_FS.h or your Custom_ESP_Mail_FS.h.
// ESP_MAIL_ETHERNET_MODULE_LIB and ESP_MAIL_ETHERNET_MODULE_CLASS
// See src/ESP_Mail_FS.h for detail.

#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 587

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@

#include <ESP_Mail_Client.h>

// https://github.com/arduino-libraries/Ethernet
#include <Ethernet.h>

// For using other Ethernet library that works with other Ethernet module,
// the following build flags or macros should be assigned in src/ESP_Mail_FS.h or your Custom_ESP_Mail_FS.h.
// ESP_MAIL_ETHERNET_MODULE_LIB and ESP_MAIL_ETHERNET_MODULE_CLASS
// See src/ESP_Mail_FS.h for detail.

#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 587

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP Mail Client",
"version": "3.4.13",
"version": "3.4.14",
"keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino",
"description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=3.4.13
version=3.4.14

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "3.4.13"
#define ESP_MAIL_VERSION_NUM 30413
#define ESP_MAIL_VERSION "3.4.14"
#define ESP_MAIL_VERSION_NUM 30414

/* The inconsistent file version checking to prevent mixed versions compilation. */
#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM)
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONST_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define ESP_MAIL_ERROR_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
13 changes: 12 additions & 1 deletion src/ESP_Mail_FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONFIG_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down Expand Up @@ -136,6 +136,17 @@
*
* 🏷️ For silent operation (no debug printing and callback)
* #define SILENT_MODE
*
* 🏷️ For external Ethernet module support.
* - Should define both library name and class object name.
* - ESP_MAIL_ETHERNET_MODULE_LIB is the Ethernet library name with extension (.h) and
* should be inside "" or <> e.g. "Ethernet.h".
* - ESP_MAIL_ETHERNET_MODULE_CLASS is the name of static object defined from class e.g. Ethernet.
* - ESP_MAIL_ETHERNET_MODULE_TIMEOUT is the time out in milliseconds to wait network connection.
*
* #define ESP_MAIL_ETHERNET_MODULE_LIB "EthernetLib.h"
* #define ESP_MAIL_ETHERNET_MODULE_CLASS EthernetClass
* #define ESP_MAIL_ETHERNET_MODULE_TIMEOUT 2000
*
* 🏷️ For ENC28J60 Ethernet module support in ESP8266
* #define ENABLE_ESP8266_ENC28J60_ETH
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define ESP_MAIL_IMAP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_SMTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define ESP_MAIL_SMTP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
29 changes: 18 additions & 11 deletions src/ESP_Mail_TCPClient.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* The Network Upgradable Arduino Secure TCP Client Class, ESP_Mail_TCPClient.h v1.0.3
* The Network Upgradable Arduino Secure TCP Client Class, ESP_Mail_TCPClient.h v1.0.4
*
* Created September 13, 2023
* Created September 14, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -30,7 +30,7 @@
#define ESP_MAIL_TCPCLIENT_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down Expand Up @@ -1030,7 +1030,7 @@ class ESP_Mail_TCPClient
#if defined(ESP_MAIL_ETHERNET_MODULE_IS_AVAILABLE)

if (_ethernet_cs_pin > -1)
Ethernet.init(_ethernet_cs_pin);
ETH_MODULE_CLASS.init(_ethernet_cs_pin);

if (_ethernet_reset_pin > -1)
{
Expand All @@ -1057,18 +1057,18 @@ class ESP_Mail_TCPClient
{

if (_static_ip->optional == false)
Ethernet.begin(_ethernet_mac, _static_ip->ipAddress, _static_ip->dnsServer, _static_ip->defaultGateway, _static_ip->netMask);
else if (!Ethernet.begin(_ethernet_mac))
ETH_MODULE_CLASS.begin(_ethernet_mac, _static_ip->ipAddress, _static_ip->dnsServer, _static_ip->defaultGateway, _static_ip->netMask);
else if (!ETH_MODULE_CLASS.begin(_ethernet_mac))
{
Ethernet.begin(_ethernet_mac, _static_ip->ipAddress, _static_ip->dnsServer, _static_ip->defaultGateway, _static_ip->netMask);
ETH_MODULE_CLASS.begin(_ethernet_mac, _static_ip->ipAddress, _static_ip->dnsServer, _static_ip->defaultGateway, _static_ip->netMask);
}
}
else
Ethernet.begin(_ethernet_mac);
ETH_MODULE_CLASS.begin(_ethernet_mac);

unsigned long to = millis();

while (Ethernet.linkStatus() == LinkOFF && millis() - to < 2000)
while (ETH_MODULE_CLASS.linkStatus() == LinkOFF && millis() - to < ESP_MAIL_ETHERNET_MODULE_TIMEOUT)
{
delay(100);
}
Expand All @@ -1081,7 +1081,7 @@ class ESP_Mail_TCPClient
if (ret)
{
esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR("Connected with IP "), esp_mail_debug_tag_type_info, false);
ESP_MAIL_DEFAULT_DEBUG_PORT.println(Ethernet.localIP());
ESP_MAIL_DEFAULT_DEBUG_PORT.println(ETH_MODULE_CLASS.localIP());
}
else
esp_mail_debug_print_tag((const char *)MBSTRING_FLASH_MCR("Can't connect"), esp_mail_debug_tag_type_error, true);
Expand All @@ -1096,7 +1096,14 @@ class ESP_Mail_TCPClient
bool ethernetConnected()
{
#if defined(ESP_MAIL_ETHERNET_MODULE_IS_AVAILABLE)
_network_status = Ethernet.linkStatus() == LinkON;
_network_status = ETH_MODULE_CLASS.linkStatus() == LinkON && validIP(ETH_MODULE_CLASS.localIP());

if (!_network_status)
{
delay(ESP_MAIL_ETHERNET_MODULE_TIMEOUT);
_network_status = ETH_MODULE_CLASS.linkStatus() == LinkON && validIP(ETH_MODULE_CLASS.localIP());
}

#endif
return _network_status;
}
Expand Down
31 changes: 2 additions & 29 deletions src/extras/MB_FS.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* The MB_FS, filesystems wrapper class v1.0.16
* The MB_FS, filesystems wrapper class v1.0.17
*
* This wrapper class is for SD and Flash filesystems interface which supports SdFat (//https://github.com/greiman/SdFat)
*
* Created June 14, 2023
* Created September 13, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -46,23 +46,6 @@
#include "SPI.h"
#endif

#if defined(ESP32) && __has_include(<sys/stat.h>)
#ifdef _LITTLEFS_H_
#define MB_FS_USE_POSIX_STAT
#include <sys/stat.h>
namespace mb_fs_ns
{
inline bool exists(const char *mountPoint, const char *filename)
{
MB_String path = mountPoint;
path += filename;
struct stat st;
return stat(path.c_str(), &st) == 0;
}
};
#endif
#endif

using namespace mb_string;

#if defined(BOARD_HAS_PSRAM) && defined(MB_STRING_USE_PSRAM)
Expand Down Expand Up @@ -661,17 +644,7 @@ class MB_FS

#if defined(MBFS_FLASH_FS)
if (type == mbfs_flash)
{

// The workaround for ESP32 LittleFS when calling vfs_api.cpp open() issue.
// See https://github.com/espressif/arduino-esp32/issues/7615
#if defined(MB_FS_USE_POSIX_STAT)
return mb_fs_ns::exists("/littlefs", filename.c_str());
#else
return MBFS_FLASH_FS.exists(filename.c_str());
#endif
}

#endif

#if defined(MBFS_SD_FS)
Expand Down
2 changes: 1 addition & 1 deletion src/extras/MB_Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MB_Time_H

#include "./ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30413)
#if !VALID_VERSION_CHECK(30414)
#error "Mixed versions compilation."
#endif

Expand Down
Loading

0 comments on commit b1cb92c

Please sign in to comment.