Skip to content

Commit 9f36a4a

Browse files
committed
Fix esp8266 Ethernet (w5x00) issue and explain solution for ESP32 Ethernet (w5x00), add new Networks management
[Comments](https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32/#comment-15612) [Forum](https://www.mischianti.org/it/forums/topic/simpleftpserver-con-esp32-o-esp8266-e-w5500/#post-24104)
1 parent 62aa2c4 commit 9f36a4a

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

FtpServer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void FtpServer::begin( const char * _user, const char * _pass, const char * _wel
7070
}
7171
// Tells the ftp server to begin listening for incoming connection
7272
ftpServer.begin();
73-
#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
73+
#if (defined(ESP8266) && (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242)) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
7474
ftpServer.setNoDelay( true );
7575
#endif
7676
// localIp = _localIP == FTP_NULLIP() || (uint32_t) _localIP == 0 ? NET_CLASS.localIP() : _localIP ;
@@ -90,7 +90,7 @@ void FtpServer::begin( const char * _user, const char * _pass, const char * _wel
9090
this->welcomeMessage = _welcomeMessage;
9191

9292
dataServer.begin();
93-
#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
93+
#if (defined(ESP8266) && (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242)) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
9494
dataServer.setNoDelay( true );
9595
#endif
9696

@@ -199,7 +199,8 @@ uint8_t FtpServer::handleFTP() {
199199
*
200200
*/
201201
// DEBUG_PRINTLN(status);
202-
#elif defined(ESP8266) // || defined(ARDUINO_ARCH_RP2040)
202+
#elif (defined(ESP8266) && (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242))
203+
203204
if( ftpServer.hasClient())
204205
{
205206
client.stop();
@@ -995,7 +996,7 @@ int FtpServer::dataConnect( bool out150 )
995996
{
996997
#if (FTP_SERVER_NETWORK_TYPE == NETWORK_WiFiNINA)
997998
data = dataServer.available();
998-
#elif defined(ESP8266) // || defined(ARDUINO_ARCH_RP2040)
999+
#elif (defined(ESP8266) && (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242)) // || defined(ARDUINO_ARCH_RP2040)
9991000
if( dataServer.hasClient())
10001001
{
10011002
data.stop();

FtpServer.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef FTP_SERVER_H
2121
#define FTP_SERVER_H
2222

23-
#define FTP_SERVER_VERSION "2.1.5 (2023-01-13)"
23+
#define FTP_SERVER_VERSION "2.1.6 (2023-02-02)"
2424

2525
#if ARDUINO >= 100
2626
#include "Arduino.h"
@@ -141,6 +141,21 @@
141141
#define NET_CLASS WiFi
142142
// #define CommandIs( a ) (command != NULL && ! strcmp_P( command, PSTR( a )))
143143
// #define ParameterIs( a ) ( parameter != NULL && ! strcmp_P( parameter, PSTR( a )))
144+
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_GENERIC)
145+
146+
#include <Ethernet_Generic.h>
147+
#include <SPI.h>
148+
#define FTP_CLIENT_NETWORK_CLASS EthernetClient
149+
#define FTP_SERVER_NETWORK_SERVER_CLASS EthernetServer
150+
#define NET_CLASS Ethernet
151+
152+
// #if defined(ESP8266) || defined(ESP32)
153+
// #define CommandIs( a ) (command != NULL && ! strcmp_P( command, PSTR( a )))
154+
// #define ParameterIs( a ) ( parameter != NULL && ! strcmp_P( parameter, PSTR( a )))
155+
// #else
156+
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
157+
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
158+
// #endif
144159
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_W5100 || FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_ENC)
145160

146161
#include <Ethernet.h>
@@ -170,15 +185,15 @@
170185
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
171186
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
172187
// #endif
173-
#elif(EMAIL_NETWORK_TYPE == NETWORK_ETHERNET_LARGE)
188+
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_LARGE)
174189

175190
#include <EthernetLarge.h>
176191
#include <SPI.h>
177192
#define FTP_CLIENT_NETWORK_CLASS EthernetClient
178193
#define FTP_SERVER_NETWORK_SERVER_CLASS EthernetServer
179194
#define NET_CLASS Ethernet
180195

181-
#elif(EMAIL_NETWORK_TYPE == NETWORK_ETHERNET_STM)
196+
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_STM)
182197

183198
#include <Ethernet_STM.h>
184199
#include <SPI.h>

FtpServerKey.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
// Uncomment to enable printing out nice debug messages.
2121
// #define FTP_SERVER_DEBUG
22+
// #define FTP_ADDITIONAL_DEBUG
2223

2324
// Define where debug output will be printed.
2425
#define DEBUG_PRINTER Serial
@@ -38,6 +39,7 @@
3839
#define NETWORK_ESP8266 (2) // Standard ESP8266WiFi
3940
#define NETWORK_ESP8266_242 (3) // ESP8266WiFi before 2.4.2 core
4041
#define NETWORK_W5100 (4) // Standard Arduino Ethernet library
42+
#define NETWORK_ETHERNET (4) // Standard Arduino Ethernet library
4143
#define NETWORK_ENC28J60 (5) // UIPEthernet library
4244
#define NETWORK_ESP32 (6) // Standard WiFi library
4345
#define NETWORK_RP2040_WIFI (6) // Raspberry Pi Pico W standard WiFi library
@@ -48,6 +50,7 @@
4850
#define NETWORK_ETHERNET_ENC (11) // EthernetENC library (evolution of UIPEthernet
4951
#define NETWORK_ETHERNET_STM (12)
5052
#define NETWORK_UIPETHERNET (13) // UIPEthernet library same of NETWORK_ENC28J60
53+
#define NETWORK_ETHERNET_GENERIC (14) // Ethernet generic
5154

5255
// esp8266 configuration
5356
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266
@@ -58,6 +61,25 @@
5861
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
5962
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 NETWORK_ESP32
6063
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_FFAT
64+
/**
65+
To use Ethernet.h with esp32 fix would be to change in Ethernet.h the line
66+
class EthernetServer : public Server {
67+
to
68+
class EthernetServer : public Stream {
69+
70+
or
71+
72+
in \esp32\2.0.6\cores\esp32\Server.h
73+
A workaround is to change line 28 of the ESP32 core's Server.h from:
74+
virtual void begin(uint16_t port=0) =0;
75+
to
76+
virtual void begin() =0;
77+
However, the last one, that will break anything that uses the ESP32 WiFi library's WebServer class.
78+
79+
https://github.com/arduino-libraries/Ethernet/issues/193
80+
https://github.com/arduino-libraries/Ethernet/issues/88
81+
*
82+
*/
6183
#endif
6284
// Standard AVR Arduino configuration
6385
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Wio Terminal (SdFat 2, Seed SD, and native FAT)
1313

1414
#### Changelog
15+
- 2022-02-02 2.1.6 Fix esp8266 Ethernet (w5x00) issue and explain solution for ESP32 Ethernet (w5x00), add new Networks management
1516
- 2022-01-13 2.1.5 Fix SPIFM external SPI Flash date management (add SPIFM esp32 example)
1617
- 2022-09-21 2.1.4 Add support for Raspberry Pi Pico W and rp2040 boards, Fix SD card config
1718
- 2022-09-20 2.1.3 Soft AP IP management, more disconnect event and SD_MCC

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
},
1717
"url": "https://www.mischianti.org",
1818
"frameworks": "Arduino",
19-
"version": "2.1.5",
19+
"version": "2.1.6",
2020
"platforms": "*"
2121
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SimpleFTPServer
2-
version=2.1.5
2+
version=2.1.6
33
author=Renzo Mischianti <renzo.mischianti@gmail.com>
44
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
55
sentence=Simple FTP server for esp8266, esp32, STM32, Raspberry Pi Pico and Arduino

0 commit comments

Comments
 (0)