Skip to content

Commit

Permalink
Fix esp8266 Ethernet (w5x00) issue and explain solution for ESP32 Eth…
Browse files Browse the repository at this point in the history
  • Loading branch information
xreef committed Feb 2, 2023
1 parent 62aa2c4 commit 9f36a4a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
9 changes: 5 additions & 4 deletions FtpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void FtpServer::begin( const char * _user, const char * _pass, const char * _wel
}
// Tells the ftp server to begin listening for incoming connection
ftpServer.begin();
#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
#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
ftpServer.setNoDelay( true );
#endif
// localIp = _localIP == FTP_NULLIP() || (uint32_t) _localIP == 0 ? NET_CLASS.localIP() : _localIP ;
Expand All @@ -90,7 +90,7 @@ void FtpServer::begin( const char * _user, const char * _pass, const char * _wel
this->welcomeMessage = _welcomeMessage;

dataServer.begin();
#if defined(ESP8266) || defined(ARDUINO_ARCH_RP2040) || FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_SEEED_RTL8720DN
#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
dataServer.setNoDelay( true );
#endif

Expand Down Expand Up @@ -199,7 +199,8 @@ uint8_t FtpServer::handleFTP() {
*
*/
// DEBUG_PRINTLN(status);
#elif defined(ESP8266) // || defined(ARDUINO_ARCH_RP2040)
#elif (defined(ESP8266) && (FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242))

if( ftpServer.hasClient())
{
client.stop();
Expand Down Expand Up @@ -995,7 +996,7 @@ int FtpServer::dataConnect( bool out150 )
{
#if (FTP_SERVER_NETWORK_TYPE == NETWORK_WiFiNINA)
data = dataServer.available();
#elif defined(ESP8266) // || defined(ARDUINO_ARCH_RP2040)
#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)
if( dataServer.hasClient())
{
data.stop();
Expand Down
21 changes: 18 additions & 3 deletions FtpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef FTP_SERVER_H
#define FTP_SERVER_H

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

#if ARDUINO >= 100
#include "Arduino.h"
Expand Down Expand Up @@ -141,6 +141,21 @@
#define NET_CLASS WiFi
// #define CommandIs( a ) (command != NULL && ! strcmp_P( command, PSTR( a )))
// #define ParameterIs( a ) ( parameter != NULL && ! strcmp_P( parameter, PSTR( a )))
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_GENERIC)

#include <Ethernet_Generic.h>
#include <SPI.h>
#define FTP_CLIENT_NETWORK_CLASS EthernetClient
#define FTP_SERVER_NETWORK_SERVER_CLASS EthernetServer
#define NET_CLASS Ethernet

// #if defined(ESP8266) || defined(ESP32)
// #define CommandIs( a ) (command != NULL && ! strcmp_P( command, PSTR( a )))
// #define ParameterIs( a ) ( parameter != NULL && ! strcmp_P( parameter, PSTR( a )))
// #else
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
// #endif
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_W5100 || FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_ENC)

#include <Ethernet.h>
Expand Down Expand Up @@ -170,15 +185,15 @@
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
// #endif
#elif(EMAIL_NETWORK_TYPE == NETWORK_ETHERNET_LARGE)
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_LARGE)

#include <EthernetLarge.h>
#include <SPI.h>
#define FTP_CLIENT_NETWORK_CLASS EthernetClient
#define FTP_SERVER_NETWORK_SERVER_CLASS EthernetServer
#define NET_CLASS Ethernet

#elif(EMAIL_NETWORK_TYPE == NETWORK_ETHERNET_STM)
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_STM)

#include <Ethernet_STM.h>
#include <SPI.h>
Expand Down
22 changes: 22 additions & 0 deletions FtpServerKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// Uncomment to enable printing out nice debug messages.
// #define FTP_SERVER_DEBUG
// #define FTP_ADDITIONAL_DEBUG

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

// esp8266 configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266
Expand All @@ -58,6 +61,25 @@
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 NETWORK_ESP32
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_FFAT
/**
To use Ethernet.h with esp32 fix would be to change in Ethernet.h the line
class EthernetServer : public Server {
to
class EthernetServer : public Stream {
or
in \esp32\2.0.6\cores\esp32\Server.h
A workaround is to change line 28 of the ESP32 core's Server.h from:
virtual void begin(uint16_t port=0) =0;
to
virtual void begin() =0;
However, the last one, that will break anything that uses the ESP32 WiFi library's WebServer class.
https://github.com/arduino-libraries/Ethernet/issues/193
https://github.com/arduino-libraries/Ethernet/issues/88
*
*/
#endif
// Standard AVR Arduino configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Wio Terminal (SdFat 2, Seed SD, and native FAT)

#### Changelog
- 2022-02-02 2.1.6 Fix esp8266 Ethernet (w5x00) issue and explain solution for ESP32 Ethernet (w5x00), add new Networks management
- 2022-01-13 2.1.5 Fix SPIFM external SPI Flash date management (add SPIFM esp32 example)
- 2022-09-21 2.1.4 Add support for Raspberry Pi Pico W and rp2040 boards, Fix SD card config
- 2022-09-20 2.1.3 Soft AP IP management, more disconnect event and SD_MCC
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
},
"url": "https://www.mischianti.org",
"frameworks": "Arduino",
"version": "2.1.5",
"version": "2.1.6",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SimpleFTPServer
version=2.1.5
version=2.1.6
author=Renzo Mischianti <[email protected]>
maintainer=Renzo Mischianti <[email protected]>
sentence=Simple FTP server for esp8266, esp32, STM32, Raspberry Pi Pico and Arduino
Expand Down

0 comments on commit 9f36a4a

Please sign in to comment.