Модуль FTP

This commit is contained in:
Mit4el
2023-06-20 00:51:56 +03:00
parent 309d974b73
commit ed6d0a253a
30 changed files with 5739 additions and 23 deletions

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimpleFTPServer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,758 @@
/*
* FtpServer Arduino, esp8266 and esp32 library for Ftp Server
* Derived form Jean-Michel Gallego version
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
/*******************************************************************************
** **
** DEFINITIONS FOR FTP SERVER **
** **
*******************************************************************************/
#include <FtpServerKey.h>
#ifndef FTP_SERVER_H
#define FTP_SERVER_H
#define FTP_SERVER_VERSION "2.1.6 (2023-02-02)"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
//
//#if(NETWORK_ESP8266_SD == DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266)
// #define ESP8266_GT_2_4_2_SD_STORAGE_SELECTED
// #define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
//#endif
#if !defined(FTP_SERVER_NETWORK_TYPE)
// select Network type based
#if defined(ESP8266) || defined(ESP31B)
#if(NETWORK_ESP8266_242 == DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266)
#define ARDUINO_ESP8266_RELEASE_2_4_2
#define FTP_SERVER_NETWORK_TYPE_SELECTED NETWORK_ESP8266_242
#define FTP_SERVER_NETWORK_TYPE NETWORK_ESP8266
#else
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266
#endif
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_ESP8266
#elif defined(ESP32)
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_ESP32
#elif defined(ARDUINO_ARCH_STM32)
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_STM32
#elif defined(ARDUINO_ARCH_RP2040)
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_RP2040
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_RP2040
#elif defined(ARDUINO_ARCH_SAMD)
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_SAMD
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_SAMD
#else
#define FTP_SERVER_NETWORK_TYPE DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO
#define STORAGE_TYPE DEFAULT_STORAGE_TYPE_ARDUINO
// #define STORAGE_SD_ENABLED
#endif
#endif
#ifndef FTP_SERVER_NETWORK_TYPE_SELECTED
#define FTP_SERVER_NETWORK_TYPE_SELECTED FTP_SERVER_NETWORK_TYPE
#endif
#if defined(ESP8266) || defined(ESP31B)
#ifndef STORAGE_SD_FORCE_DISABLE
#define STORAGE_SD_ENABLED
#endif
#ifndef STORAGE_SPIFFS_FORCE_DISABLE
#define STORAGE_SPIFFS_ENABLED
#endif
#elif defined(ESP32)
#ifndef STORAGE_SD_FORCE_DISABLE
#define STORAGE_SD_ENABLED
#endif
#ifndef STORAGE_SPIFFS_FORCE_DISABLE
#define STORAGE_SPIFFS_ENABLED
#endif
#else
#ifndef STORAGE_SD_FORCE_DISABLE
#define STORAGE_SD_ENABLED
#endif
#endif
// Includes and defined based on Network Type
#if(FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
// Note:
// No SSL/WSS support for client in Async mode
// TLS lib need a sync interface!
#if defined(ESP8266)
#include <ESP8266WiFi.h>
//#include <WiFiClientSecure.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiClientSecure
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#elif defined(ESP32)
#include <WiFi.h>
//#include <WiFiClientSecure.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiClientSecure
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#elif defined(ESP31B)
#include <ESP31BWiFi.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiClientSecure
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#else
#error "network type ESP8266 ASYNC only possible on the ESP mcu!"
#endif
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266 || FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242)
#if !defined(ESP8266) && !defined(ESP31B)
#error "network type ESP8266 only possible on the ESP mcu!"
#endif
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <ESP31BWiFi.h>
#endif
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiClientSecure
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#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>
#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_ENC28J60 || FTP_SERVER_NETWORK_TYPE == NETWORK_UIPETHERNET)
#include <UIPEthernet.h>
#define FTP_CLIENT_NETWORK_CLASS UIPClient
#define FTP_SERVER_NETWORK_SERVER_CLASS UIPServer
#define NET_CLASS Ethernet
// #if define(ESP8266) || define(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_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(FTP_SERVER_NETWORK_TYPE == NETWORK_ETHERNET_STM)
#include <Ethernet_STM.h>
#include <SPI.h>
#define FTP_CLIENT_NETWORK_CLASS EthernetClient
#define FTP_SERVER_NETWORK_SERVER_CLASS EthernetServer
#define NET_CLASS Ethernet
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_ESP32)
#include <WiFi.h>
//#include <WiFiClientSecure.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiClientSecure
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#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_ESP32_ETH)
#include <ETH.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#define NET_CLASS Ethernet
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_WiFiNINA)
#include <WiFiNINA.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiSSLClient
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#define NET_CLASS WiFi
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
#elif(FTP_SERVER_NETWORK_TYPE == NETWORK_SEEED_RTL8720DN)
#include <rpcWiFi.h>
#define FTP_CLIENT_NETWORK_CLASS WiFiClient
//#define FTP_CLIENT_NETWORK_SSL_CLASS WiFiSSLClient
#define FTP_SERVER_NETWORK_SERVER_CLASS WiFiServer
#define NET_CLASS WiFi
// #define CommandIs( a ) ( ! strcmp_PF( command, PSTR( a )))
// #define ParameterIs( a ) ( ! strcmp_PF( parameter, PSTR( a )))
#else
#error "no network type selected!"
#endif
#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#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
#if(STORAGE_TYPE == STORAGE_SPIFFS)
#if defined(ESP32)
// #define FS_NO_GLOBALS
#include <SPIFFS.h>
#define FTP_FILE File
#define FTP_DIR File
#else
#ifdef ARDUINO_ESP8266_RELEASE_2_4_2
#define FS_NO_GLOBALS
#include "FS.h"
#define FTP_FILE fs::File
#define FTP_DIR fs::Dir
#else
#include "FS.h"
#define FTP_FILE File
#define FTP_DIR Dir
#endif
#endif
#if ESP8266
#define FTP_FILE_READ "r"
#define FTP_FILE_READ_ONLY "r"
#define FTP_FILE_READ_WRITE "w+"
#define FTP_FILE_WRITE_APPEND "a+"
#define FTP_FILE_WRITE_CREATE "w+"
#else
#define FTP_FILE_READ "r"
#define FTP_FILE_READ_ONLY "r"
#define FTP_FILE_READ_WRITE "w"
#define FTP_FILE_WRITE_APPEND "a"
#define FTP_FILE_WRITE_CREATE "w"
#endif
#define STORAGE_MANAGER SPIFFS
#define FILENAME_LENGTH 32
#elif(STORAGE_TYPE == STORAGE_FFAT)
#include "FS.h"
#include "FFat.h"
#define STORAGE_MANAGER FFat
#define FTP_FILE File
#define FTP_DIR File
#define FTP_FILE_READ "r"
#define FTP_FILE_READ_ONLY "r"
#define FTP_FILE_READ_WRITE "w"
#define FTP_FILE_WRITE_APPEND "a"
#define FTP_FILE_WRITE_CREATE "w"
#define FILENAME_LENGTH 255
#elif(STORAGE_TYPE == STORAGE_LITTLEFS)
#if ESP8266 || ARDUINO_ARCH_RP2040
#include "LittleFS.h"
#define STORAGE_MANAGER LittleFS
#define FTP_FILE File
#define FTP_DIR Dir
#define FTP_FILE_READ "r"
#define FTP_FILE_READ_ONLY "r"
#define FTP_FILE_READ_WRITE "w+"
#define FTP_FILE_WRITE_APPEND "a+"
#define FTP_FILE_WRITE_CREATE "w+"
#else
#ifdef ESP32
#if ESP_ARDUINO_VERSION_MAJOR >= 2
#include "FS.h"
#include "LittleFS.h"
#define STORAGE_MANAGER LittleFS
#else
#include "LITTLEFS.h"
#define STORAGE_MANAGER LITTLEFS
#endif
#else
#include "LittleFS.h"
#define STORAGE_MANAGER LittleFS
#endif
#define FTP_FILE File
#define FTP_DIR File
#define FTP_FILE_READ "r"
#define FTP_FILE_READ_ONLY "r"
#define FTP_FILE_READ_WRITE "w"
#define FTP_FILE_WRITE_APPEND "a"
#define FTP_FILE_WRITE_CREATE "w"
#endif
#define FILENAME_LENGTH 32
#elif(STORAGE_TYPE == STORAGE_SD)
#include <SPI.h>
#include <SD.h>
#define STORAGE_MANAGER SD
#define FTP_FILE File
#define FTP_DIR File
#define FTP_FILE_READ FILE_READ
#define FTP_FILE_READ_ONLY FILE_READ
#ifdef ESP32
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_APPEND
#else
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_WRITE
#endif
#define FTP_FILE_WRITE_CREATE FILE_WRITE
#define FILENAME_LENGTH 255
#elif(STORAGE_TYPE == STORAGE_SD_MMC)
#include <SPI.h>
#include <SD_MMC.h>
#define STORAGE_MANAGER SD_MMC
#define FTP_FILE File
#define FTP_DIR File
#define FTP_FILE_READ FILE_READ
#define FTP_FILE_READ_ONLY FILE_READ
#define FTP_FILE_READ_WRITE FILE_WRITE
#ifdef ESP32
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_APPEND
#else
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_WRITE
#endif
#define FTP_FILE_WRITE_CREATE FILE_WRITE
#define FILENAME_LENGTH 255
#elif(STORAGE_TYPE == STORAGE_SEEED_SD)
#include <Seeed_FS.h>
#define STORAGE_MANAGER SD
#include "SD/Seeed_SD.h"
// #define STORAGE_MANAGER SPIFLASH
// #include "SFUD/Seeed_SFUD.h"
#define FTP_FILE File
#define FTP_DIR File
#define FTP_FILE_READ FILE_READ
#define FTP_FILE_READ_ONLY FILE_READ
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_APPEND
#define FTP_FILE_WRITE_CREATE FILE_WRITE
#define FILENAME_LENGTH 255
#elif (STORAGE_TYPE == STORAGE_SDFAT1)
#include <SdFat.h>
#include <sdios.h>
#define STORAGE_MANAGER sd
#define FTP_FILE SdFile
#define FTP_DIR SdFile
extern SdFat STORAGE_MANAGER;
#define FTP_FILE_READ O_READ
#define FTP_FILE_READ_ONLY O_RDONLY
#define FTP_FILE_READ_WRITE O_RDWR
#define FTP_FILE_WRITE_APPEND O_WRITE | O_APPEND
#define FTP_FILE_WRITE_CREATE O_WRITE | O_CREAT
#define FILENAME_LENGTH 255
#elif (STORAGE_TYPE == STORAGE_SDFAT2)
#include <SdFat.h>
#include <sdios.h>
#define STORAGE_MANAGER sd
#define FTP_FILE FsFile
#define FTP_DIR FsFile
extern SdFat STORAGE_MANAGER;
#define FTP_FILE_READ O_READ
#define FTP_FILE_READ_ONLY O_RDONLY
#define FTP_FILE_READ_WRITE O_RDWR
#define FTP_FILE_WRITE_APPEND O_WRITE | O_APPEND
#define FTP_FILE_WRITE_CREATE O_WRITE | O_CREAT
#define FILENAME_LENGTH 255
#elif (STORAGE_TYPE == STORAGE_SPIFM)
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>
#include <sdios.h>
#define STORAGE_MANAGER fatfs
#define FTP_FILE File
#define FTP_DIR File
extern FatFileSystem STORAGE_MANAGER;
extern Adafruit_SPIFlash flash;
#define FTP_FILE_READ FILE_READ
#define FTP_FILE_READ_ONLY FILE_READ
#define FTP_FILE_READ_WRITE FILE_WRITE
#define FTP_FILE_WRITE_APPEND FILE_WRITE
#define FTP_FILE_WRITE_CREATE FILE_WRITE
#define FILENAME_LENGTH 255
#elif (STORAGE_TYPE == STORAGE_FATFS)
#include <FatFs.h>
#include <sdios.h>
#define STORAGE_MANAGER sdff
#define FTP_FILE FileFs
#define FTP_DIR DirFs
extern FatFsClass STORAGE_MANAGER;
#define O_READ FA_READ
#define O_WRITE FA_WRITE
#define O_RDWR FA_READ | FA_WRITE
#define O_CREAT FA_CREATE_ALWAYS
#define O_APPEND FA_OPEN_APPEND
#define FTP_FILE_READ O_READ
#define FTP_FILE_READ_ONLY O_RDONLY
#define FTP_FILE_READ_WRITE O_RDWR
#define FTP_FILE_WRITE_APPEND O_WRITE | O_APPEND
#define FTP_FILE_WRITE_CREATE O_WRITE | O_CREAT
#define FILENAME_LENGTH 255
#endif
//#ifdef FTP_CLIENT_NETWORK_SSL_CLASS
//#define FTP_CLIENT_NETWORK_CLASS FTP_CLIENT_NETWORK_SSL_CLASS
//#endif
#define OPEN_CLOSE_SPIFFS
#define OPEN_CLOSE_SD
// Setup debug printing macros.
#ifdef FTP_SERVER_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#endif
#define FTP_CMD_PORT 21 // Command port on wich server is listening
#define FTP_DATA_PORT_DFLT 20 // Default data port in active mode
#define FTP_DATA_PORT_PASV 50009 // Data port in passive mode
#define FF_MAX_LFN 255 // max size of a long file name
#define FTP_CMD_SIZE FF_MAX_LFN+8 // max size of a command
#define FTP_CWD_SIZE FF_MAX_LFN+8 // max size of a directory name
#define FTP_FIL_SIZE FF_MAX_LFN // max size of a file name
#define FTP_CRED_SIZE 16 // max size of username and password
#define FTP_NULLIP() IPAddress(0,0,0,0)
enum ftpCmd { FTP_Stop = 0, // In this stage, stop any connection
FTP_Init, // initialize some variables
FTP_Client, // wait for client connection
FTP_User, // wait for user name
FTP_Pass, // wait for user password
FTP_Cmd }; // answers to commands
enum ftpTransfer { FTP_Close = 0, // In this stage, close data channel
FTP_Retrieve, // retrieve file
FTP_Store, // store file
FTP_List, // list of files
FTP_Nlst, // list of name of files
FTP_Mlsd }; // listing for machine processing
enum ftpDataConn { FTP_NoConn = 0,// No data connexion
FTP_Pasive, // Pasive type
FTP_Active }; // Active type
enum FtpOperation {
FTP_CONNECT,
FTP_DISCONNECT,
FTP_FREE_SPACE_CHANGE
};
enum FtpTransferOperation {
FTP_UPLOAD_START = 0,
FTP_UPLOAD = 1,
FTP_DOWNLOAD_START = 2,
FTP_DOWNLOAD = 3,
FTP_TRANSFER_STOP = 4,
FTP_DOWNLOAD_STOP = 4,
FTP_UPLOAD_STOP = 4,
FTP_TRANSFER_ERROR = 5,
FTP_DOWNLOAD_ERROR = 5,
FTP_UPLOAD_ERROR = 5
};
class FtpServer
{
public:
FtpServer( uint16_t _cmdPort = FTP_CMD_PORT, uint16_t _pasvPort = FTP_DATA_PORT_PASV );
void begin( const char * _user, const char * _pass, const char * welcomeMessage = "Welcome to Simply FTP server" );
void begin( const char * welcomeMessage = "Welcome to Simply FTP server" );
void end();
void setLocalIp(IPAddress localIp);
void credentials( const char * _user, const char * _pass );
uint8_t handleFTP();
void setCallback(void (*_callbackParam)(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace) )
{
_callback = _callbackParam;
}
void setTransferCallback(void (*_transferCallbackParam)(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize) )
{
_transferCallback = _transferCallbackParam;
}
private:
void (*_callback)(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){};
void (*_transferCallback)(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){};
void iniVariables();
void clientConnected();
void disconnectClient();
bool processCommand();
bool haveParameter();
int dataConnect( bool out150 = true );
bool dataConnected();
bool doRetrieve();
bool doStore();
bool doList();
bool doMlsd();
void closeTransfer();
void abortTransfer();
bool makePath( char * fullName, char * param = NULL );
bool makeExistsPath( char * path, char * param = NULL );
bool openDir( FTP_DIR * pdir );
bool isDir( char * path );
uint8_t getDateTime( char * dt, uint16_t * pyear, uint8_t * pmonth, uint8_t * pday,
uint8_t * phour, uint8_t * pminute, uint8_t * second );
char * makeDateTimeStr( char * tstr, uint16_t date, uint16_t time );
bool timeStamp( char * path, uint16_t year, uint8_t month, uint8_t day,
uint8_t hour, uint8_t minute, uint8_t second );
bool getFileModTime( char * path, uint16_t * pdate, uint16_t * ptime );
#if STORAGE_TYPE != STORAGE_FATFS
bool getFileModTime( uint16_t * pdate, uint16_t * ptime );
#endif
int8_t readChar();
const char* getFileName(FTP_FILE *file){
#if STORAGE_TYPE <= STORAGE_SDFAT2
int max_characters = 100;
char f_name[max_characters];
file->getName(f_name, max_characters);
String filename = String(f_name);
return filename.c_str();
#elif STORAGE_TYPE == STORAGE_FATFS
return file->fileName();
#else
return file->name();
#endif
}
bool exists( const char * path ) {
#if STORAGE_TYPE == STORAGE_SPIFFS || (STORAGE_TYPE == STORAGE_SD && FTP_SERVER_NETWORK_TYPE == NETWORK_ESP8266_242)
if (strcmp(path, "/") == 0) return true;
#endif
#if STORAGE_TYPE == STORAGE_FFAT || (STORAGE_TYPE == STORAGE_LITTLEFS && defined(ESP32))
FTP_DIR f = STORAGE_MANAGER.open(path, "r");
return (f == true);
#else
return STORAGE_MANAGER.exists( path );
#endif
};
bool remove( const char * path ) { return STORAGE_MANAGER.remove( path ); };
#if STORAGE_TYPE == STORAGE_SPIFFS
bool makeDir( const char * path ) { return false; };
bool removeDir( const char * path ) { return false; };
#else
bool makeDir( const char * path ) { return STORAGE_MANAGER.mkdir( path ); };
bool removeDir( const char * path ) { return STORAGE_MANAGER.rmdir( path ); };
#endif
#if STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC
bool rename( const char * path, const char * newpath );
#else
bool rename( const char * path, const char * newpath ) { return STORAGE_MANAGER.rename( path, newpath ); };
#endif
#if (STORAGE_TYPE == STORAGE_SEEED_SD)
bool openFile( char path[ FTP_CWD_SIZE ], int readTypeInt );
#elif (STORAGE_TYPE == STORAGE_SD && defined(ESP8266))// FTP_SERVER_NETWORK_TYPE_SELECTED == NETWORK_ESP8266_242)
bool openFile( char path[ FTP_CWD_SIZE ], int readTypeInt );
#elif (STORAGE_TYPE == STORAGE_SPIFFS || STORAGE_TYPE == STORAGE_LITTLEFS || STORAGE_TYPE == STORAGE_FFAT )
bool openFile( const char * path, const char * readType );
// bool openFile( char path[ FTP_CWD_SIZE ], int readTypeInt );
#elif STORAGE_TYPE <= STORAGE_SDFAT2 || STORAGE_TYPE == STORAGE_SPIFM || (STORAGE_TYPE == STORAGE_SD && ARDUINO_ARCH_SAMD)
bool openFile( char path[ FTP_CWD_SIZE ], int readTypeInt );
#else
bool openFile( char path[ FTP_CWD_SIZE ], const char * readType );
bool openFile( const char * path, const char * readType );
// bool openFile( char path[ FTP_CWD_SIZE ], int readTypeInt );
#endif
// bool openFile( char path[ FTP_CWD_SIZE ], const char * readType );
// bool openFile( const char * path, const char * readType );
uint32_t fileSize( FTP_FILE file );
#if STORAGE_TYPE == STORAGE_SPIFFS || STORAGE_TYPE == STORAGE_LITTLEFS
#if ESP8266 || ARDUINO_ARCH_RP2040
uint32_t capacity() {
FSInfo fi;
STORAGE_MANAGER.info(fi);
return fi.totalBytes >> 1;
};
uint32_t free() {
FSInfo fi;
STORAGE_MANAGER.info(fi);
return (fi.totalBytes - fi.usedBytes) >> 1;
};
#else
uint32_t capacity() {
return STORAGE_MANAGER.totalBytes() >> 1;
};
uint32_t free() {
return (STORAGE_MANAGER.totalBytes() -
STORAGE_MANAGER.usedBytes()) >> 1;
};
#endif
#elif STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC
uint32_t capacity() { return true; };
uint32_t free() { return true; };
#elif STORAGE_TYPE == STORAGE_SEEED_SD
uint32_t capacity() {
return STORAGE_MANAGER.totalBytes() >> 1;
};
uint32_t free() {
return (STORAGE_MANAGER.totalBytes() -
STORAGE_MANAGER.usedBytes()) >> 1;
};
#elif STORAGE_TYPE == STORAGE_SDFAT1
uint32_t capacity() { return STORAGE_MANAGER.card()->cardSize() >> 1; };
uint32_t free() { return STORAGE_MANAGER.vol()->freeClusterCount() *
STORAGE_MANAGER.vol()->sectorsPerCluster() >> 1; };
#elif STORAGE_TYPE == STORAGE_SDFAT2
uint32_t capacity() { return STORAGE_MANAGER.card()->sectorCount() >> 1; };
uint32_t free() { return STORAGE_MANAGER.vol()->freeClusterCount() *
STORAGE_MANAGER.vol()->sectorsPerCluster() >> 1; };
#elif STORAGE_TYPE == STORAGE_SPIFM
uint32_t capacity() { return flash.size() >> 10; };
uint32_t free() { return 0; }; // TODO //
#elif STORAGE_TYPE == STORAGE_FATFS
uint32_t capacity() { return STORAGE_MANAGER.capacity(); };
uint32_t free() { return STORAGE_MANAGER.free(); };
#elif STORAGE_TYPE == STORAGE_FFAT
uint32_t capacity() { return STORAGE_MANAGER.totalBytes(); };
uint32_t free() { return STORAGE_MANAGER.freeBytes(); };
#endif
bool legalChar( char c ) // Return true if char c is allowed in a long file name
{
if( c == '"' || c == '*' || c == '?' || c == ':' ||
c == '<' || c == '>' || c == '|' )
return false;
#if STORAGE_TYPE == STORAGE_FATFS
return 0x1f < c && c < 0xff;
#else
return 0x1f < c && c < 0x7f;
#endif
}
IPAddress localIp; // IP address of server as seen by clients
IPAddress dataIp; // IP address of client for data
FTP_SERVER_NETWORK_SERVER_CLASS ftpServer;
FTP_SERVER_NETWORK_SERVER_CLASS dataServer;
FTP_CLIENT_NETWORK_CLASS client;
FTP_CLIENT_NETWORK_CLASS data;
FTP_FILE file;
FTP_DIR dir;
ftpCmd cmdStage; // stage of ftp command connexion
ftpTransfer transferStage; // stage of data connexion
ftpDataConn dataConn; // type of data connexion
bool anonymousConnection = false;
uint8_t __attribute__((aligned(4))) // need to be aligned to 32bit for Esp8266 SPIClass::transferBytes()
buf[ FTP_BUF_SIZE ]; // data buffer for transfers
char cmdLine[ FTP_CMD_SIZE ]; // where to store incoming char from client
char cwdName[ FTP_CWD_SIZE ]; // name of current directory
char rnfrName[ FTP_CWD_SIZE ]; // name of file for RNFR command
const char * user; // user name
const char * pass; // password
char command[ 5 ]; // command sent by client
bool rnfrCmd; // previous command was RNFR
char * parameter; // point to begin of parameters sent by client
const char * welcomeMessage;
uint16_t cmdPort,
pasvPort,
dataPort;
uint16_t iCL; // pointer to cmdLine next incoming char
uint16_t nbMatch;
uint32_t millisDelay, //
millisEndConnection, //
millisBeginTrans, // store time of beginning of a transaction
bytesTransfered; //
};
#endif // FTP_SERVER_H

View File

@@ -0,0 +1,128 @@
/*
* FtpServer Arduino, esp8266 and esp32 library for Ftp Server
* Derived form Jean-Michel Gallego version
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
/*******************************************************************************
** **
** SETTINGS FOR FTP SERVER **
** **
*******************************************************************************/
#ifndef FTP_SERVER_CONFIG_H
#define FTP_SERVER_CONFIG_H
// 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
#define STORAGE_SDFAT1 1 // Library SdFat version 1.4.x
#define STORAGE_SDFAT2 2 // Library SdFat version >= 2.0.2
#define STORAGE_SPIFM 3 // Libraries Adafruit_SPIFlash and SdFat-Adafruit-Fork
#define STORAGE_FATFS 4 // Library FatFs
#define STORAGE_SD 5 // Standard SD library (suitable for Arduino esp8266 and esp32
#define STORAGE_SPIFFS 6 // SPIFFS
#define STORAGE_LITTLEFS 7 // LITTLEFS
#define STORAGE_SEEED_SD 8 // Seeed_SD library
#define STORAGE_FFAT 9 // ESP32 FFAT
#define STORAGE_SD_MMC 10 // SD_MMC library
#define NETWORK_ESP8266_ASYNC (1)
#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
#define NETWORK_ESP32_ETH (7) // Standard ETH library
#define NETWORK_WiFiNINA (8) // Standard WiFiNINA library
#define NETWORK_SEEED_RTL8720DN (9) // Standard SEED WiFi library
#define NETWORK_ETHERNET_LARGE (10)
#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
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
#define DEFAULT_STORAGE_TYPE_ESP8266 STORAGE_LITTLEFS
#endif
// esp32 configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 NETWORK_ESP32
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS
/**
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
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO NETWORK_W5100
#define DEFAULT_STORAGE_TYPE_ARDUINO STORAGE_SD
#endif
// STM32 configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32 NETWORK_W5100
#define DEFAULT_STORAGE_TYPE_STM32 STORAGE_SDFAT2
#endif
// Raspberry Pi Pico (rp2040) configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_RP2040
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_RP2040 NETWORK_RP2040_WIFI
#define DEFAULT_STORAGE_TYPE_RP2040 STORAGE_LITTLEFS
#endif
// Arduino SAMD21 like Arduino MKR Nano 33 IoT or Wio Terminal
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO_SAMD
// Wio Terminal
// #define DEFAULT_FTP_SERVER_NETWORK_TYPE_SAMD NETWORK_SEEED_RTL8720DN
// #define DEFAULT_STORAGE_TYPE_SAMD STORAGE_SEEED_SD
// Arduino SAMD
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_SAMD NETWORK_WiFiNINA
#define DEFAULT_STORAGE_TYPE_SAMD STORAGE_SD
#endif
#define UTF8_SUPPORT
//#define SD_CS_PIN 4
// Disconnect client after 5 minutes of inactivity (expressed in seconds)
#define FTP_TIME_OUT 5 * 60
// Wait for authentication for 10 seconds (expressed in seconds)
#define FTP_AUTH_TIME_OUT 10
// Size of file buffer for read/write
// Transfer speed depends of this value
// Best value depends on many factors: SD card, client side OS, ...
// But it can be reduced to 512 if memory usage is critical.
#define FTP_BUF_SIZE 1024 //2048 //1024 // 512
#endif // FTP_SERVER_CONFIG_H

View File

@@ -0,0 +1,24 @@
The MIT License (MIT)
Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved.
You may copy, alter and reuse this code in any way you like, but please leave
reference to www.mischianti.org in your comments if you redistribute this code.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,108 @@
# SimpleFTPServer
[Instruction on FTP server on esp8266 and esp32](https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32)
[Simple FTP Server library now with support for Wio Terminal and SD](https://www.mischianti.org/2021/07/01/simple-ftp-server-library-now-with-support-for-wio-terminal-and-sd/)
#### Simple FTP Server for
- Raspberry Pi Pico W (Flash: LittleFS) (To test SD and SdFat)
- esp8266 (Flash: SPIFFs, LittleFS. SD: SD, SdFat 2)
- esp32 (SPIFFS, LITTLEFS, FFAT, SD: SD, SdFat)
- stm32 (SdFat, SPI flash)
- Arduino (SD with 8.3 file format, SD: SD, SdFat 2)
- 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
- 2022-05-21 2.1.2 Fix SD path (#19)
- 2022-05-21 2.1.1 Minor fix
- 2022-03-30 2.1.0 Add UTF8 support and enabled It by default (Thanks to @plaber)
- 2022-03-30 2.0.0 Complete support for STM32 with SD and SPI Flash minor bux fix and HELP command support
- 2022-03-17 1.3.0 Fix enc28j60 and w5500 support and restructuring for local settings
- 2022-02-25 1.2.1 Fix anonymous user begin and fix SPIFFS wrong display
- 2022-02-22 1.2.0 Add anonymous user and implement correct RFC (#9 now work correctly with File Explorer)
- 2022-02-01 1.1.1 Add workaround to start FTP server before connection, add end and setLocalIP method.
<!-- wp:paragraph -->
<p>When I develop a new solution I'd like to divide the application in layer, and so I'd like focus my attention in only one aspect at time. </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p> In detail I separate the REST layer (written inside the microcontroller) and the Front-End (written in Angular, React/Redux or vanilla JS), so I'd like to upload new web interface directly to the microcontroller via FTP. </p>
<!-- /wp:paragraph -->
<!-- wp:image {"align":"center","id":2155} -->
<div class="wp-block-image"><figure class="aligncenter"><img width="450px" src="https://www.mischianti.org/wp-content/uploads/2019/06/FTPTransferEsp8266-1024x662.jpg" alt="" class="wp-image-2155"/><figcaption></figcaption></figure></div>
<!-- /wp:image -->
<!-- wp:paragraph -->
<p>For static information (Web pages for examples), that not change frequently, esp8266 or esp32 have internal SPIFFS (SPI Flash File System) and you can upload data via Arduino IDE as explained in the article "<a href="https://www.mischianti.org/2019/08/30/wemos-d1-mini-esp8266-integrated-spiffs-filesistem-part-2/">WeMos D1 mini (esp8266), integrated SPIFFS Filesystem</a>" for esp8266 or "<a rel="noreferrer noopener" href="https://www.mischianti.org/2020/06/04/esp32-integrated-spiffs-filesystem-part-2/" target="_blank">ESP32: integrated SPIFFS FileSystem</a>" for esp32 or with LittleFS "<a href="https://www.mischianti.org/2020/06/22/wemos-d1-mini-esp8266-integrated-littlefs-filesystem-part-5/">WeMos D1 mini (esp8266), integrated LittleFS Filesystem</a>" but for fast operation and future support It's usefully use FTP.</p>
<!-- /wp:paragraph -->
```cpp
/*
* FtpServer esp8266 and esp32 with SPIFFS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif defined ESP32
#include <WiFi.h>
#include "SPIFFS.h"
#endif
#include <SimpleFTPServer.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
#ifdef ESP32 //esp32 we send true to format spiffs if cannot mount
if (SPIFFS.begin(true)) {
#elif defined ESP8266
if (SPIFFS.begin()) {
#endif
Serial.println("SPIFFS opened!");
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
// server.handleClient(); //example if running a webserver you still need to call .handleClient();
}
```
https://downloads.arduino.cc/libraries/logs/github.com/xreef/SimpleFTPServer/

View File

@@ -0,0 +1,18 @@
/*
* FtpServer Arduino, esp8266 and esp32 library for Ftp Server
* Derived form https://github.com/nailbuster/esp8266FTPServer
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#ifndef SIMPLE_FTP_SERVER_H
#define SIMPLE_FTP_SERVER_H
#include <FtpServer.h>
#endif
#pragma once

View File

@@ -0,0 +1,62 @@
/*
* FtpServer Arduino with Ethernet library and w5100 shield
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include <SPI.h>
#include <Ethernet.h>
#include "SD.h"
#include <SimpleFtpServer.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE1 };
// Set the static IP address to use if the DHCP fails to assign
byte macAddr[] = {0x5e, 0xa4, 0x18, 0xf0, 0x8a, 0xf2};
IPAddress arduinoIP(192, 168, 1, 177);
IPAddress dnsIP(192, 168, 1, 1);
IPAddress gatewayIP(192, 168, 1, 1);
IPAddress subnetIP(255, 255, 255, 0);
FtpServer ftpSrv;
void setup(void){
Serial.begin(115200);
delay(2000);
// If other chips are connected to SPI bus, set to high the pin connected
// to their CS before initializing Flash memory
pinMode( 4, OUTPUT );
digitalWrite( 4, HIGH );
pinMode( 10, OUTPUT );
digitalWrite( 10, HIGH );
Serial.print("Starting SD.");
while (!SD.begin(4)) {
Serial.print(".");
}
Serial.println("finish!");
// start the Ethernet connection:
Serial.print("Starting ethernet.");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(macAddr, arduinoIP, dnsIP, gatewayIP, subnetIP);
}else{
Serial.println("ok to configure Ethernet using DHCP");
}
Serial.print("IP address ");
Serial.println(Ethernet.localIP());
Serial.println("SPIFFS opened!");
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp.
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,133 @@
/*
* FtpServer Arduino with Ethernet library and w5100 shield
* With SdFat version > 2 (full name and more size)
*
* #ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO
* #define DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO NETWORK_W5100
* #define DEFAULT_STORAGE_TYPE_ARDUINO STORAGE_SDFAT2
* #endif
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include <SdFat.h>
#include <sdios.h>
#include <FtpServer.h>
#include <FreeStack.h>
// Define Chip Select for your SD card according to hardware
// #define CS_SDCARD 4 // SD card reader of Ehernet shield
#define CS_SDCARD 4 // Chip Select for SD card reader on Due
// Define Reset pin for W5200 or W5500
// set to -1 for other ethernet chip or if Arduino reset board is used
#define W5x00_RESET -1
//#define W5x00_RESET 8 // on Due
// #define W5x00_RESET 3 // on MKR
// Object for File system
SdFat sd;
// Object for FtpServer
// Command port and Data port in passive mode can be defined here
// FtpServer ftpSrv( 221, 25000 );
// FtpServer ftpSrv( 421 ); // Default data port in passive mode is 55600
FtpServer ftpSrv; // Default command port is 21 ( !! without parenthesis !! )
// Mac address of ethernet adapter
// byte mac[] = { 0x90, 0xa2, 0xda, 0x00, 0x00, 0x00 };
byte mac[] = { 0x00, 0xaa, 0xbb, 0xcc, 0xde, 0xef };
// IP address of FTP server
// if set to 0, use DHCP for the routeur to assign IP
// IPAddress serverIp( 192, 168, 1, 40 );
IPAddress serverIp( 0, 0, 0, 0 );
// External IP address of FTP server
// In passive mode, when accessing the serveur from outside his subnet, it can be
// necessary with some clients to reply them with the server's external ip address
// IPAddress externalIp( 192, 168, 1, 2 );
ArduinoOutStream cout( Serial );
void setup()
{
Serial.begin( 115200 );
cout << F("=== Test of FTP Server with SdFat ") << SD_FAT_VERSION << F(" file system ===") << endl;
// If other chips are connected to SPI bus, set to high the pin connected
// to their CS before initializing Flash memory
pinMode( 4, OUTPUT );
digitalWrite( 4, HIGH );
pinMode( 10, OUTPUT );
digitalWrite( 10, HIGH );
// Mount the SD card memory
cout << F("Mount the SD card memory... ");
if( ! sd.begin( CS_SDCARD, SD_SCK_MHZ( 50 )))
{
cout << F("Unable to mount SD card") << endl;
while( true ) ;
}
pinMode( CS_SDCARD, OUTPUT );
digitalWrite( CS_SDCARD, HIGH );
cout << F("ok") << endl;
// Show capacity and free space of SD card
cout << F("Capacity of card: ") << long( sd.card()->sectorCount() >> 1 )
<< F(" kBytes") << endl;
cout << F("Free space on card: ")
<< long( sd.vol()->freeClusterCount() * sd.vol()->sectorsPerCluster() >> 1 )
<< F(" kBytes") << endl;
// Send reset to Ethernet module
if( W5x00_RESET > -1 )
{
pinMode( W5x00_RESET, OUTPUT );
digitalWrite( W5x00_RESET, LOW );
delay( 200 );
digitalWrite( W5x00_RESET, HIGH );
delay( 200 );
}
// Initialize the network
cout << F("Initialize ethernet module ... ");
if( serverIp[0] != 0 )
Ethernet.begin( mac, serverIp );
else if( Ethernet.begin( mac ) == 0 )
{
cout << F("failed!") << endl;
while( true ) ;
}
uint16_t wizModule[] = { 0, 5100, 5200, 5500 };
cout << F("W") << wizModule[ Ethernet.hardwareStatus()] << F(" ok") << endl;
serverIp = Ethernet.localIP();
cout << F("IP address of server: ")
<< int( serverIp[0]) << "." << int( serverIp[1]) << "."
<< int( serverIp[2]) << "." << int( serverIp[3]) << endl;
// Initialize the FTP server
ftpSrv.begin("user","password");
// ftpSrv.init( externalIp );
// ftpSrv.init( IPAddress( 11, 22, 33, 44 ));
// Default username and password are set to 'arduino' and 'test'
// but can then be changed by calling ftpSrv.credentials()
// ftpSrv.credentials( "myname", "123" );
cout << F("Free stack: ") << FreeStack() << endl;
cout << "Viaaa!";
}
void loop()
{
ftpSrv.handleFTP();
// more processes...
}

View File

@@ -0,0 +1,96 @@
/*
* FtpServer esp8266 and esp32 with SD
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include <WiFi.h>
#include "SD.h"
#include <SimpleFTPServer.h>
const char* ssid = "<YOUR-SSID>";
const char* password = "<YOUR-PASSWD>";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
Serial.print(">>>>>>>>>>>>>>> _callback " );
Serial.print(ftpOperation);
/* FTP_CONNECT,
* FTP_DISCONNECT,
* FTP_FREE_SPACE_CHANGE
*/
Serial.print(" ");
Serial.print(freeSpace);
Serial.print(" ");
Serial.println(totalSpace);
// freeSpace : totalSpace = x : 360
if (ftpOperation == FTP_CONNECT) Serial.println(F("CONNECTED"));
if (ftpOperation == FTP_DISCONNECT) Serial.println(F("DISCONNECTED"));
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
Serial.print(">>>>>>>>>>>>>>> _transferCallback " );
Serial.print(ftpOperation);
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
Serial.print(" ");
Serial.print(name);
Serial.print(" ");
Serial.println(transferredSize);
};
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
SPI.begin(14, 12, 15, 13); //SCK, MISO, MOSI,SS
if (SD.begin(13, SPI)) {
Serial.println("SD opened!");
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp. (default 21, 50009 for PASV)
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
// server.handleClient(); //example if running a webserver you still need to call .handleClient();
}

View File

@@ -0,0 +1,124 @@
/*
* FtpServer esp32 with FFat FS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include "Arduino.h"
#include "FS.h"
#include "FFat.h"
#include <SimpleFTPServer.h>
#ifdef STA_MODE
const char* ssid = "<YOUR-SSID>";
const char* password = "<YOUR-PASSWD>";
#endif
const char* ssid_AP = "ESP32";
const char* password_AP = "aabbccdd77";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup(void){
Serial.begin(115200);
//AP mode
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid_AP, password_AP);
delay(1000);
//IPAddress IP = IPAddress (10, 10, 10, 1);
//IPAddress NMask = IPAddress (255, 255, 255, 0);
//WiFi.softAPConfig(IP, IP, NMask);
Serial.print("Set AP named:");
Serial.println(ssid_AP);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
#ifdef STA_MODE
// STA mode
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
#endif
/////FTP Setup, ensure FFAT is started before ftp; /////////
Serial.print(F("Inizializing FS..."));
if (FFat.begin(true)){
Serial.println(F("done."));
}else{
Serial.println(F("fail."));
while (true) { delay(1000); };
}
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("Start FTP with user: user and passwd: password!");
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
ftpSrv.setLocalIp(myIP);
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,105 @@
/*
* FtpServer esp32 with FFat FS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include "Arduino.h"
#include "FS.h"
#include "FFat.h"
#include <SimpleFTPServer.h>
const char* ssid = "<YOUR-SSID>";
const char* password = "<YOUR-PASSWD>";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure FFAT is started before ftp; /////////
Serial.print(F("Inizializing FS..."));
if (FFat.begin(true)){
Serial.println(F("done."));
}else{
Serial.println(F("fail."));
while (true) { delay(1000); };
}
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("Start FTP with user: user and passwd: password!");
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,130 @@
/*
* FtpServer esp32 with FFat and EthernetENC (or UIPEthernet)
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include "Arduino.h"
#include <SPI.h>
#include <EthernetENC.h>
#include "FS.h"
#include "FFat.h"
#include <SimpleFTPServer.h>
#define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
uint8_t macaddress[6] = {MACADDRESS};
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
Serial.print(">>>>>>>>>>>>>>> _callback " );
Serial.print(ftpOperation);
/* FTP_CONNECT,
* FTP_DISCONNECT,
* FTP_FREE_SPACE_CHANGE
*/
Serial.print(" ");
Serial.print(freeSpace);
Serial.print(" ");
Serial.println(totalSpace);
// freeSpace : totalSpace = x : 360
if (ftpOperation == FTP_CONNECT) Serial.println(F("CONNECTED"));
if (ftpOperation == FTP_DISCONNECT) Serial.println(F("DISCONNECTED"));
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
Serial.print(">>>>>>>>>>>>>>> _transferCallback " );
Serial.print(ftpOperation);
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
Serial.print(" ");
Serial.print(name);
Serial.print(" ");
Serial.println(transferredSize);
};
void setup(void){
Serial.begin(115200);
Serial.println("Begin Ethernet");
Ethernet.init(5);
if (Ethernet.begin(macaddress)) { // Dynamic IP setup
Serial.println("DHCP OK!");
}else{
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
IPAddress ip(MYIPADDR);
IPAddress dns(MYDNS);
IPAddress gw(MYGW);
IPAddress sn(MYIPMASK);
Ethernet.begin(macaddress, ip, dns, gw, sn);
Serial.println("STATIC OK!");
}
delay(5000);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("Ethernet Successfully Initialized");
/////FTP Setup, ensure FFat is started before ftp; /////////
if (FFat.begin(true)) {
Serial.println("FFat opened!");
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
ftpSrv.begin("user","password"); //username, password for ftp. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
Serial.println("FTP server started!");
} else {
Serial.println("FFat opened FAIL!!!!!");
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
// server.handleClient(); //example if running a webserver you still need to call .handleClient();
}

View File

@@ -0,0 +1,148 @@
/**
* ESP32 and external SPI Flash FTP server
*
*
// esp32 configuration
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 NETWORK_ESP32
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFM
#endif
*
*/
#include <Arduino.h>
#include "SdFat.h"
#include "Adafruit_SPIFlash.h"
#include <WiFi.h>
#include <SimpleFTPServer.h>
Adafruit_FlashTransport_SPI flashTransport(SS, SPI); // Set CS and SPI interface
Adafruit_SPIFlash flash(&flashTransport);
// file system object from SdFat
FatFileSystem fatfs;
const char* ssid = "<YOUR_SSID>";
const char* password = "<YOUR_PASSWD>";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.print(F("FTP: Free space change, free "));
Serial.print(freeSpace);
Serial.print(F(" of "));
Serial.println(totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.print(F("FTP: Upload of file "));
Serial.print(name);
Serial.print(F(" "));
Serial.print(transferredSize);
Serial.println(F("bytes"));
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup()
{
// Initialize serial port and wait for it to open before continuing.
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Serial.println("FTP with external SPIFlash");
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("SN address: ");
Serial.println(WiFi.subnetMask());
if (flash.begin()) {
Serial.println(F("Device finded and supported!"));
} else {
Serial.println(F("Problem to discover and configure device, check wiring also!"));
while(1) yield();
}
// Set 4Mhz SPI speed
flashTransport.setClockSpeed(4000000, 4000000); // added to prevent speed problem
Serial.print("JEDEC ID: "); Serial.println(flash.getJEDECID(), HEX);
Serial.print("Flash size: "); Serial.println(flash.size());
Serial.flush();
// First call begin to mount the filesystem. Check that it returns true
// to make sure the filesystem was mounted.
if (!fatfs.begin(&flash)) {
Serial.println("Error, failed to mount newly formatted filesystem!");
Serial.println("Was the flash chip formatted with the SdFat_format example?");
while(1) yield();
}
Serial.println("Mounted filesystem!");
Serial.println();
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("Starting FTP Server!");
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
// ftpSrv.beginAnonymous();
}
// The loop function is called in an endless loop
void loop()
{
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,103 @@
/*
* FtpServer Raspberry Pi Pico W with LittleFS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#include <WiFi.h>
#include <LittleFS.h>
#include <SimpleFTPServer.h>
const char* ssid = "<YOUR-SSID>";
const char* password = "<YOUR-PASSWD>";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup(void){
Serial.begin(115200);
while (!Serial) {delay(100);};
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
if (LittleFS.begin()) {
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("LittleFS opened!");
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,136 @@
/**
* SimpleFTPServer ^1.3.0 on STM32 (need FLASH > 64K)
* and ethernet w5500
* SPI Flash with Adafruit_SPIFlash and SdFat-Adafruit-Fork library
*
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32 NETWORK_ETHERNET_ENC
#define DEFAULT_STORAGE_TYPE_STM32 STORAGE_SPIFM
#endif
*
* @author Renzo Mischianti <www.mischianti.org>
* @details https://www.mischianti.org/category/my-libraries/simple-ftp-server/
* @version 0.1
* @date 2022-03-22
*
* @copyright Copyright (c) 2022
*
*/
#include <Arduino.h>
#include <EthernetEnc.h>
#include "SdFat.h"
#include "Adafruit_SPIFlash.h"
#include <SimpleFTPServer.h>
Adafruit_FlashTransport_SPI flashTransport(SS, SPI); // Set CS and SPI interface
Adafruit_SPIFlash flash(&flashTransport);
// file system object from SdFat
FatFileSystem fatfs;
#define ETHERNET_CS_PIN PA3
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Initialize serial port and wait for it to open before continuing.
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Serial.println("Adafruit SPI Flash FatFs Full Usage Example");
// Initialize flash library and check its chip ID.
if (!flash.begin()) {
Serial.println("Error, failed to initialize flash chip!");
while(1) yield();
}
Serial.print("JEDEC ID: "); Serial.println(flash.getJEDECID(), HEX);
Serial.print("Flash size: "); Serial.println(flash.size());
Serial.flush();
// First call begin to mount the filesystem. Check that it returns true
// to make sure the filesystem was mounted.
if (!fatfs.begin(&flash)) {
Serial.println("Error, failed to mount newly formatted filesystem!");
Serial.println("Was the flash chip formatted with the SdFat_format example?");
while(1) yield();
}
Serial.println("Mounted filesystem!");
Serial.println();
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(ETHERNET_CS_PIN);
if (Ethernet.begin(mac)) { // Dynamic IP setup
Serial.println(F("DHCP OK!"));
}else{
Serial.println(F("Failed to configure Ethernet using DHCP"));
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :("));
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(F("Ethernet cable is not connected."));
}
IPAddress ip(MYIPADDR);
IPAddress dns(MYDNS);
IPAddress gw(MYGW);
IPAddress sn(MYIPMASK);
Ethernet.begin(mac, ip, dns, gw, sn);
Serial.println("STATIC OK!");
}
delay(5000);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("Ethernet Successfully Initialized");
Serial.println();
// Initialize the FTP server
ftpSrv.begin("user","password");
Serial.println("Ftp server started!");
}
void loop()
{
ftpSrv.handleFTP();
// more processes...
}

View File

@@ -0,0 +1,135 @@
/**
* SimpleFTPServer ^1.3.0 on STM32 (need FLASH > 64K)
* and ethernet w5500
* SD connected on secondary SPI or primary
*
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32 NETWORK_W5100
#define DEFAULT_STORAGE_TYPE_STM32 STORAGE_SDFAT2
#endif
*
* @author Renzo Mischianti <www.mischianti.org>
* @details https://www.mischianti.org/category/my-libraries/simple-ftp-server/
* @version 0.1
* @date 2022-03-22
*
* @copyright Copyright (c) 2022
*
*/
#include <SdFat.h>
#include <sdios.h>
#include <SimpleFtpServer.h>
#include <EthernetEnc.h>
// Ethernet CS
#define ETHERNET_CS_PIN PA3
// To use SD with primary SPI
#define SD_CS_PIN PA2
// To use SD with secondary SPI
// #define SD_CS_PIN PB12
// static SPIClass mySPI2(PB15, PB14, PB13, SD_CS_PIN);
// #define SD2_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(18), &mySPI2)
SdFat sd;
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
Serial.begin( 115200 );
while (!Serial) { delay(100); }
pinMode( SD_CS_PIN, OUTPUT );
digitalWrite( SD_CS_PIN, HIGH );
pinMode( ETHERNET_CS_PIN, OUTPUT );
digitalWrite( ETHERNET_CS_PIN, HIGH );
Serial.print("\nInitializing SD card...");
// To use SD with secondary SPI
// if (!sd.begin(SD2_CONFIG)) {
// To use SD with primary SPI
if (!sd.begin(SD_CS_PIN)) {
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card inserted?"));
Serial.println(F("* is your wiring correct?"));
Serial.println(F("* did you change the chipSelect pin to match your shield or module?"));
while (1);
} else {
Serial.println(F("Wiring is correct and a 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"));
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(ETHERNET_CS_PIN);
if (Ethernet.begin(mac)) { // Dynamic IP setup
Serial.println(F("DHCP OK!"));
}else{
Serial.println(F("Failed to configure Ethernet using DHCP"));
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :("));
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(F("Ethernet cable is not connected."));
}
IPAddress ip(MYIPADDR);
IPAddress dns(MYDNS);
IPAddress gw(MYGW);
IPAddress sn(MYIPMASK);
Ethernet.begin(mac, ip, dns, gw, sn);
Serial.println("STATIC OK!");
}
delay(5000);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("Ethernet Successfully Initialized");
Serial.println();
// Initialize the FTP server
ftpSrv.begin("user","password");
Serial.println("Ftp server started!");
}
void loop()
{
ftpSrv.handleFTP();
// more processes...
}

View File

@@ -0,0 +1,128 @@
/**
* SimpleFTPServer ^1.3.0 on STM32 (need FLASH > 64K)
* and ethernet w5500
* SD connected on secondary SPI or primary
*
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_STM32 NETWORK_W5100
#define DEFAULT_STORAGE_TYPE_STM32 STORAGE_SDFAT2
#endif
*
* @author Renzo Mischianti <www.mischianti.org>
* @details https://www.mischianti.org/category/my-libraries/simple-ftp-server/
* @version 0.1
* @date 2022-03-22
*
* @copyright Copyright (c) 2022
*
*/
#include <SdFat.h>
#include <sdios.h>
#include <Ethernet.h>
#include <SimpleFtpServer.h>
// To use SD with primary SPI
// #define SD_CS_PIN PA4
// To use SD with secondary SPI
#define SD_CS_PIN PB12
static SPIClass mySPI2(PB15, PB14, PB13, SD_CS_PIN);
#define SD2_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(18), &mySPI2)
SdFat sd;
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
Serial.begin( 115200 );
while (!Serial) { delay(100); }
Serial.print("\nInitializing SD card...");
// Secondary SPI for SD
if (!sd.begin(SD2_CONFIG)) {
// Primary SPI for SD
// if (!SD.begin(SD_CS_PIN)) {
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card inserted?"));
Serial.println(F("* is your wiring correct?"));
Serial.println(F("* did you change the chipSelect pin to match your shield or module?"));
while (1);
} else {
Serial.println(F("Wiring is correct and a 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"));
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(PA4);
if (Ethernet.begin(mac)) { // Dynamic IP setup
Serial.println(F("DHCP OK!"));
}else{
Serial.println(F("Failed to configure Ethernet using DHCP"));
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :("));
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(F("Ethernet cable is not connected."));
}
IPAddress ip(MYIPADDR);
IPAddress dns(MYDNS);
IPAddress gw(MYGW);
IPAddress sn(MYIPMASK);
Ethernet.begin(mac, ip, dns, gw, sn);
Serial.println("STATIC OK!");
}
delay(5000);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("Ethernet Successfully Initialized");
Serial.println();
// Initialize the FTP server
ftpSrv.begin("user","password");
Serial.println("Ftp server started!");
}
void loop()
{
ftpSrv.handleFTP();
// more processes...
}

View File

@@ -0,0 +1,106 @@
/*
* FtpServer Wio Terminal
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/category/my-libraries/simple-ftp-server/
*/
#include <Seeed_FS.h>
#include "SD/Seeed_SD.h"
// #define DEFAULT_FTP_SERVER_NETWORK_TYPE_SAMD NETWORK_SEEED_RTL8720DN
// #define DEFAULT_STORAGE_TYPE_SAMD STORAGE_SEEED_SD
#include <rpcWiFi.h>
#include <FtpServer.h>
FtpServer ftpSrv;
const char *ssid = "<YOUR-SSID>";
const char *password = "<YOUR-PASSWD>";
void listDir(const char* dirname, uint8_t levels) {
Serial.print("Listing directory: ");
Serial.println(dirname);
File root = SD.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(file.name(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void setup()
{
Serial.begin(115200);
delay(1000);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
while (!SD.begin(SDCARD_SS_PIN,SDCARD_SPI,4000000UL)) {
Serial.println("Card Mount Failed");
return;
}
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(1000);
Serial.print("Starting SD.");
Serial.println("finish!");
listDir("/", 0);
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp.
}
void loop(void) {
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,104 @@
/*
* FtpServer Wio Terminal with SdFat library
* and with callbacks to the main actions of FTP server
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/category/my-libraries/simple-ftp-server/
*
*/
#include "SdFat.h"
#include <rpcWiFi.h>
#include <FtpServer.h>
// #define DEFAULT_FTP_SERVER_NETWORK_TYPE_SAMD NETWORK_SEEED_RTL8720DN
// #define DEFAULT_STORAGE_TYPE_SAMD STORAGE_SDFAT2
#define SD_CONFIG SdSpiConfig(SDCARD_SS_PIN, 2)
SdFs sd;
FtpServer ftpSrv;
const char *ssid = "<YOUR-SSID>";
const char *password = "<YOUR-PASSWD>";
void setup()
{
Serial.begin(115200);
delay(1000);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
// Initialize the SD.
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
}
FsFile dir;
FsFile file;
// Open root directory
if (!dir.open("/")){
Serial.println("dir.open failed");
}
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(1000);
Serial.print("Starting SD.");
Serial.println("finish!");
while (file.openNext(&dir, O_RDONLY)) {
file.printFileSize(&Serial);
Serial.write(' ');
file.printModifyDateTime(&Serial);
Serial.write(' ');
file.printName(&Serial);
if (file.isDir()) {
// Indicate a directory.
Serial.write('/');
}
Serial.println();
file.close();
}
if (dir.getError()) {
Serial.println("openNext failed");
} else {
Serial.println("Done!");
}
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp.
}
void loop(void) {
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,367 @@
/*
* FtpServer Wio Terminal with SdFat library
* and with callbacks to the main actions of FTP server
* and a monitor on TFT
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/category/my-libraries/simple-ftp-server/
*
*/
#include "SdFat.h"
#include <rpcWiFi.h>
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include <FtpServer.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define DEG2RAD 0.0174532925
byte inc = 0;
unsigned int col = 0;
#define SD_CONFIG SdSpiConfig(SDCARD_SS_PIN, 2)
SdFs sd;
FtpServer ftpSrv;
const char *ssid = "reef-casa-sopra";
const char *password = "aabbccdd77";
#define MAIN_TOP 110
#define FREE_SPACE_PIE_X 80
#define FREE_SPACE_PIE_Y MAIN_TOP+40
#define FREE_SPACE_PIE_RADIUS 50
void freeSpacePieData(unsigned int freeSpace, unsigned int totalSpace) {
int pieFree = 360 - (freeSpace * 360 / totalSpace);
fillSegment(FREE_SPACE_PIE_X, FREE_SPACE_PIE_Y, 0, pieFree, FREE_SPACE_PIE_RADIUS, TFT_RED);
fillSegment(FREE_SPACE_PIE_X, FREE_SPACE_PIE_Y, pieFree, 360 - pieFree, FREE_SPACE_PIE_RADIUS, TFT_BLUE);
// Set "cursor" at top left corner of display (0,0) and select font 2
// (cursor will move to next line automatically during printing with 'tft.println'
// or stay on the line is there is room for the text with tft.print)
tft.setCursor(FREE_SPACE_PIE_X + 80, MAIN_TOP, 2);
// Set the font colour to be white with a black background, set text size multiplier to 1
tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(1);
// We can now plot text on screen using the "print" class
Serial.print(freeSpace/1000);Serial.print("Mb/");Serial.print(String(totalSpace/1000));Serial.println("Mb");
tft.print(freeSpace/1000);tft.print("Mb/");tft.print(String(totalSpace/1000));tft.println("Mb");
}
void connectedDisconnected(bool connected) {
tft.fillCircle(FREE_SPACE_PIE_X + 80 + 10, MAIN_TOP+25+7, 10, (connected)?TFT_GREEN:TFT_RED);
tft.setCursor(FREE_SPACE_PIE_X + 80 + 25, MAIN_TOP+25, 2);
tft.println(" ");
tft.setCursor(FREE_SPACE_PIE_X + 80 + 25, MAIN_TOP+25, 2);
(connected)?tft.println("Connected!"):tft.println("Disconnected!");
}
void transfer(bool transfer, bool upload) {
tft.fillCircle(FREE_SPACE_PIE_X + 80 + 10, MAIN_TOP+25+25+7, 10, (transfer)?(upload)?TFT_GREEN:TFT_BLUE:TFT_RED);
tft.setCursor(FREE_SPACE_PIE_X + 80 + 25, MAIN_TOP+25+25, 2);
tft.println(" ");
tft.setCursor(FREE_SPACE_PIE_X + 80 + 25, MAIN_TOP+25+25, 2);
(transfer)?tft.println((upload)?"Upload!":"Download!"):tft.println("Idle!");
}
//index - starting at, n- how many chars
char* subString(const char *s, int index, int n){
char* b = (char*) malloc((strlen(s) + 1) * sizeof(char));
strcpy(b,s);
Serial.println("--------------------------------------");
Serial.println(s);
Serial.println(index);
Serial.println(n);
char *res = new char[n + 1];
Serial.println(res);
sprintf(res, "%.*s", n, b + index);
Serial.println(res);
free(b);
return res;
}
void fileTransfer(FtpTransferOperation ftpOperation, const char* filename, unsigned int transferredSize) {
int yoffset = 2;
tft.setCursor(20, MAIN_TOP+(FREE_SPACE_PIE_RADIUS*2)+yoffset, 2);
tft.println(F(" "));
tft.setCursor(20, MAIN_TOP+(FREE_SPACE_PIE_RADIUS*2)+yoffset, 2);
int lenfile = strlen(filename);
Serial.println(lenfile);
if (lenfile>22) {
tft.print(subString(filename, 0, 16));tft.print(F("~"));
tft.print( subString(filename, (lenfile-4), 4) );
} else {
tft.print(filename);
}
tft.setCursor(20+160, MAIN_TOP+(FREE_SPACE_PIE_RADIUS*2)+yoffset, 2);
tft.print(F(" "));
tft.setCursor(20+160, MAIN_TOP+(FREE_SPACE_PIE_RADIUS*2)+yoffset, 2);
tft.print(transferredSize);tft.print("Kb");
tft.setCursor(320-55, MAIN_TOP+(FREE_SPACE_PIE_RADIUS*2)+yoffset, 2);
switch (ftpOperation) {
case FTP_UPLOAD:
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.print(F("Upload"));
tft.setTextColor(TFT_WHITE, TFT_BLACK);
break;
case FTP_DOWNLOAD:
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.print(F("Down"));
tft.setTextColor(TFT_WHITE, TFT_BLACK);
break;
case FTP_TRANSFER_STOP:
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.print(F("OK"));
tft.setTextColor(TFT_WHITE, TFT_BLACK);
break;
case FTP_TRANSFER_ERROR:
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.print(F("Error"));
tft.setTextColor(TFT_WHITE, TFT_BLACK);
break;
default:
break;
}
}
void wifiStrenght (int8_t RSSI, bool connection = false) {
Serial.print("RSSI --> ");Serial.println(RSSI);
int marginX = 30;
int startX = 90;
int widthW = 320-(startX+marginX);
int startY = 60;
int heightY = 10;
tft.setCursor(marginX, startY - 5, 2);
tft.print(F(" "));
tft.setCursor(marginX, startY - 5, 2);
if (connection) {
tft.print(F("Connectint to: "));
tft.print(ssid);
}else{
tft.println("WiFi str: ");
// 120 : 120-RSSI = 300 : x
tft.drawRoundRect(startX, startY, widthW, heightY, 5, TFT_WHITE);
uint32_t colorRSSI = TFT_GREEN;
if (abs(RSSI)<55) {
colorRSSI = TFT_GREEN;
} else if (abs(RSSI)<75) {
colorRSSI = TFT_YELLOW;
} else if (abs(RSSI)<75) {
colorRSSI = TFT_RED;
}
tft.fillRoundRect(startX+1, startY+1, (120+RSSI)*widthW/120, heightY-2, 5, colorRSSI);
tft.setCursor(marginX, startY + 15, 2);
tft.print("IP: ");
tft.println(WiFi.localIP());
}
}
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
Serial.print(">>>>>>>>>>>>>>> _callback " );
Serial.print(ftpOperation);
/* FTP_CONNECT,
* FTP_DISCONNECT,
* FTP_FREE_SPACE_CHANGE
*/
Serial.print(" ");
Serial.print(freeSpace);
Serial.print(" ");
Serial.println(totalSpace);
// freeSpace : totalSpace = x : 360
freeSpacePieData(freeSpace, totalSpace);
if (ftpOperation == FTP_CONNECT) connectedDisconnected(true);
if (ftpOperation == FTP_DISCONNECT) connectedDisconnected(false);
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
Serial.print(">>>>>>>>>>>>>>> _transferCallback " );
Serial.print(ftpOperation);
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
Serial.print(" ");
Serial.print(name);
Serial.print(" ");
Serial.println(transferredSize);
(ftpOperation==FTP_UPLOAD || ftpOperation==FTP_DOWNLOAD)?transfer(true, ftpOperation==FTP_UPLOAD):transfer(false, false);
fileTransfer(ftpOperation, name, transferredSize);
};
void setup()
{
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.begin(115200);
delay(1000);
tft.init();
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(TFT_BLACK, TFT_WHITE); tft.setTextSize(2);
tft.fillRoundRect(3, 3, 320-6, 40, 5, TFT_WHITE);
tft.drawCentreString("www.mischianti.org", 160, 14,1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
freeSpacePieData(0, 0);
connectedDisconnected(false);
transfer(false, false);
wifiStrenght(0, true);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
WiFi.begin(ssid, password);
Serial.print(".");
tft.print(F("."));
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
wifiStrenght(WiFi.RSSI());
delay(1000);
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
}
FsFile dir;
FsFile file;
// Open root directory
if (!dir.open("/")){
Serial.println("dir.open failed");
}
ftpSrv.begin("wioterminal","wioterminal"); //username, password for ftp.
}
void loop() {
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}
// #########################################################################
// Draw circle segments
// #########################################################################
// x,y == coords of centre of circle
// start_angle = 0 - 359
// sub_angle = 0 - 360 = subtended angle
// r = radius
// colour = 16 bit colour value
int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned int colour) {
// Calculate first pair of coordinates for segment start
float sx = cos((start_angle - 90) * DEG2RAD);
float sy = sin((start_angle - 90) * DEG2RAD);
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
// Draw colour blocks every inc degrees
for (int i = start_angle; i < start_angle + sub_angle; i++) {
// Calculate pair of coordinates for segment end
int x2 = cos((i + 1 - 90) * DEG2RAD) * r + x;
int y2 = sin((i + 1 - 90) * DEG2RAD) * r + y;
tft.fillTriangle(x1, y1, x2, y2, x, y, colour);
// Copy segment end to sgement start for next segment
x1 = x2;
y1 = y2;
}
}
// #########################################################################
// Return the 16 bit colour with brightness 0-100%
// #########################################################################
unsigned int brightness(unsigned int colour, int brightness) {
byte red = colour >> 11;
byte green = (colour & 0x7E0) >> 5;
byte blue = colour & 0x1F;
blue = (blue * brightness) / 100;
green = (green * brightness) / 100;
red = (red * brightness) / 100;
return (red << 11) + (green << 5) + blue;
}

View File

@@ -0,0 +1,110 @@
/*
* FtpServer esp8266 and esp32 with LittleFS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <LittleFS.h>
#elif defined ESP32
#include <WiFi.h>
#include <FS.h>
#include <LittleFS.h>
#endif
#include <SimpleFTPServer.h>
const char* ssid = "<YOUR-SSID>";
const char* password = "<YOUR-PASSWD>";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
#ifdef ESP32 //esp32 we send true to format spiffs if cannot mount
if (LittleFS.begin(true)) {
#elif defined ESP8266
if (LittleFS.begin()) {
#endif
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("LittleFS opened!");
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}

View File

@@ -0,0 +1,110 @@
/*
* FtpServer esp8266 and esp32 with SPIFFS
*
* AUTHOR: Renzo Mischianti
*
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
*
*/
#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif defined ESP32
#include <WiFi.h>
#include "SPIFFS.h"
#endif
#include <SimpleFTPServer.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
switch (ftpOperation) {
case FTP_CONNECT:
Serial.println(F("FTP: Connected!"));
break;
case FTP_DISCONNECT:
Serial.println(F("FTP: Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
break;
default:
break;
}
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
switch (ftpOperation) {
case FTP_UPLOAD_START:
Serial.println(F("FTP: Upload start!"));
break;
case FTP_UPLOAD:
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
break;
case FTP_TRANSFER_STOP:
Serial.println(F("FTP: Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
Serial.println(F("FTP: Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
};
void setup(void){
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
#ifdef ESP32 //esp32 we send true to format spiffs if cannot mount
if (SPIFFS.begin(true)) {
#elif defined ESP8266
if (SPIFFS.begin()) {
#endif
ftpSrv.setCallback(_callback);
ftpSrv.setTransferCallback(_transferCallback);
Serial.println("SPIFFS opened!");
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp. (default 21, 50009 for PASV)
}
}
void loop(void){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
// server.handleClient(); //example if running a webserver you still need to call .handleClient();
}

View File

@@ -0,0 +1,17 @@
#######################################
# Datatypes (KEYWORD1)
#######################################
SimpleFtpServer KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
setLocalIp KEYWORD2
credentials KEYWORD2
setCallback KEYWORD2
setTransferCallback KEYWORD2
handleFTP KEYWORD2

View File

@@ -0,0 +1,21 @@
{
"name": "SimpleFTPServer",
"description": "Simple FTP Server for using esp8266, esp32, STM32, Arduino",
"keywords": "arduino, esp8266, esp32, stm32, rp2040, Raspberry Pi, ftp, FtpServer, spiffs, Fat, LittleFS, Ethernet, WiFi, WiFiNINA",
"homepage": "https://www.mischianti.org/category/my-libraries/simple-ftp-server/",
"authors":
{
"name": "Renzo Mischianti",
"email": "renzo.mischianti@gmail.com",
"url": "https://www.mischianti.org"
},
"repository":
{
"type": "git",
"url": "https://github.com/xreef/SimpleFTPServer"
},
"url": "https://www.mischianti.org",
"frameworks": "Arduino",
"version": "2.1.6",
"platforms": "*"
}

View File

@@ -0,0 +1,11 @@
name=SimpleFTPServer
version=2.1.6
author=Renzo Mischianti <renzo.mischianti@gmail.com>
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
sentence=Simple FTP server for esp8266, esp32, STM32, Raspberry Pi Pico and Arduino
paragraph=Simple FTP server for Raspberry Pi Pico W (LittleFS), esp8266 (SPIFFS and LittleFS or SD, SdFat 2.x), esp32 (SPIFFS, LittleFS and FFAT or SD, SdFat 2.x) and Arduino (SdFat, SD basic lib with 8.3 file format), Wio Terminal (Seed_SD, SdFat 2.x), Arduino MKR (SdFat 2), STM32 (Flash >64K SdFat 2.x and SPI Flash). Support w5500, w5100 and enc28j60. With internal callback to chck the phase of communication.
category=Communication
url=https://www.mischianti.org/category/my-libraries/simple-ftp-server/
repository=https://github.com/xreef/SimpleFTPServer.git
architectures=*
includes=SimpleFTPServer.h

View File

@@ -118,7 +118,7 @@
},
{
"path": "src/modules/sensors/Ds2423",
"active": true
"active": false
},
{
"path": "src/modules/sensors/Emon",
@@ -170,7 +170,7 @@
},
{
"path": "src/modules/sensors/Ntc",
"active": true
"active": false
},
{
"path": "src/modules/sensors/Pzem004t",
@@ -190,7 +190,7 @@
},
{
"path": "src/modules/sensors/Scd40",
"active": true
"active": false
},
{
"path": "src/modules/sensors/Sds011",
@@ -238,6 +238,10 @@
"path": "src/modules/exec/EspCam",
"active": false
},
{
"path": "src/modules/exec/Ftp",
"active": false
},
{
"path": "src/modules/exec/HttpGet",
"active": false

View File

@@ -0,0 +1,97 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <SimpleFTPServer.h>
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS
class FTPModule : public IoTItem
{
private:
String login;
String pass;
FtpServer ftpSrv; // set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
public:
FTPModule(String parameters) : IoTItem(parameters)
{
jsonRead(parameters, F("login"), login);
jsonRead(parameters, F("pass"), pass);
ftpSrv.setCallback(FTPModule::_callback);
ftpSrv.setTransferCallback(FTPModule::_transferCallback);
ftpSrv.begin(login.c_str(), pass.c_str(), "Welcome IoTManager FTP server"); // username, password for ftp. (default 21, 50009 for PASV)
SerialPrint("I", "FtpServer " + (String)_id, "begin");
}
void loop()
{
ftpSrv.handleFTP();
}
static void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace)
{
switch (ftpOperation)
{
case FTP_CONNECT:
SerialPrint("i", "FTP", F("Connected!"));
break;
case FTP_DISCONNECT:
SerialPrint("i", "FTP", F("Disconnected!"));
break;
case FTP_FREE_SPACE_CHANGE:
SerialPrint("i", "FTP", "Free space change, free " + (String)freeSpace + " of " + (String)totalSpace);
break;
default:
break;
}
}
static void _transferCallback(FtpTransferOperation ftpOperation, const char *name, unsigned int transferredSize)
{
switch (ftpOperation)
{
case FTP_UPLOAD_START:
SerialPrint("i","FTP", F("Upload start!"));
break;
case FTP_UPLOAD:
SerialPrint("i","FTP", "Upload of file " + (String)name + " byte " + (String)transferredSize);
break;
case FTP_TRANSFER_STOP:
SerialPrint("i","FTP", F("Finish transfer!"));
break;
case FTP_TRANSFER_ERROR:
SerialPrint("E","FTP", F("Transfer error!"));
break;
default:
break;
}
/* FTP_UPLOAD_START = 0,
* FTP_UPLOAD = 1,
*
* FTP_DOWNLOAD_START = 2,
* FTP_DOWNLOAD = 3,
*
* FTP_TRANSFER_STOP = 4,
* FTP_DOWNLOAD_STOP = 4,
* FTP_UPLOAD_STOP = 4,
*
* FTP_TRANSFER_ERROR = 5,
* FTP_DOWNLOAD_ERROR = 5,
* FTP_UPLOAD_ERROR = 5
*/
}
~FTPModule(){};
};
void *getAPI_FTPModule(String subtype, String param)
{
if (subtype == F("ftp"))
{
return new FTPModule(param);
}
//}
return nullptr;
}

View File

@@ -0,0 +1,68 @@
{
"menuSection": "Исполнительные устройства",
"configItem": [
{
"global": 0,
"name": "FTP сервер",
"type": "Reading",
"subtype": "ftp",
"id": "ftp",
"widget": "nil",
"page": "",
"descr": "FTP сервер",
"login": "admin",
"pass": "admin"
}
],
"about": {
"authorName": "Bubnov Mikhail",
"authorContact": "https://t.me/Mit4bmw",
"authorGit": "https://github.com/Mit4el",
"specialThanks": "",
"moduleName": "FTPModule",
"moduleVersion": "0.1",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"title": "FTP-сервер",
"moduleDesc": "Запускает FTP-сервер на плате esp",
"propInfo": {
"login": "Логин FTP сервера",
"pass": "Пароль FTP сервера"
}
},
"defActive": false,
"usedLibs": {
"esp32_4mb": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp32s2_4mb": [],
"esp8266_4mb": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8266_1mb": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8266_1mb_ota": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8285_1mb": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8285_1mb_ota": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8266_2mb": [
"https://github.com/xreef/SimpleFTPServer"
],
"esp8266_2mb_ota": [
"https://github.com/xreef/SimpleFTPServer"
]
}
}

View File

@@ -30,7 +30,7 @@ void printSerialNumber(uint16_t serial0, uint16_t serial1, uint16_t serial2)
}
// Функция инициализации библиотечного класса, возвращает Единстрвенный указать на библиотеку
SensirionI2CScd4x *instance()
SensirionI2CScd4x *instanceScd4x()
{
if (!scd4x)
{ // Если библиотека ранее инициализировалась, т о просто вернем указатель
@@ -41,7 +41,7 @@ SensirionI2CScd4x *instance()
//Останавливаем периодический опрос датчика вбиблиотеке для запроса Сер.номера (на всякий случай)
// stop potentially previously started measurement
errorCodeScd4x = instance()->stopPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->stopPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
@@ -52,7 +52,7 @@ SensirionI2CScd4x *instance()
uint16_t serial0;
uint16_t serial1;
uint16_t serial2;
errorCodeScd4x = instance()->getSerialNumber(serial0, serial1, serial2);
errorCodeScd4x = instanceScd4x()->getSerialNumber(serial0, serial1, serial2);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute getSerialNumber(): ");
@@ -66,7 +66,7 @@ SensirionI2CScd4x *instance()
//Обратно стартуем периодический опрос датчика библиотекой (по описанию библиотеки каждые 5сек)
// Start Measurement
errorCodeScd4x = instance()->startPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->startPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute startPeriodicMeasurement(): ");
@@ -102,7 +102,7 @@ public:
float humidity = 0.0f;
bool isDataReady = false;
//Запрашиваем библиотеку о готовности отправить запрос
errorCodeScd4x = instance()->getDataReadyFlag(isDataReady);
errorCodeScd4x = instanceScd4x()->getDataReadyFlag(isDataReady);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute getDataReadyFlag(): ");
@@ -115,7 +115,7 @@ public:
return;
}
//Если все нормально забираем у библиотеки данные
errorCodeScd4x = instance()->readMeasurement(co2, temperature, humidity);
errorCodeScd4x = instanceScd4x()->readMeasurement(co2, temperature, humidity);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute readMeasurement(): ");
@@ -158,7 +158,7 @@ public:
{
//Останавливаем периодический опрос датчика вбиблиотеке для запроса Сер.номера (на всякий случай)
// stop potentially previously started measurement
errorCodeScd4x = instance()->stopPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->stopPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
@@ -166,7 +166,7 @@ public:
}
delay(500); // Из описания performForcedRecalibration 2. Stop periodic measurement. Wait 500 ms.
uint16_t frcCorrection;
errorCodeScd4x = instance()->performForcedRecalibration(targetCo2, frcCorrection);
errorCodeScd4x = instanceScd4x()->performForcedRecalibration(targetCo2, frcCorrection);
if (errorCodeScd4x)
{
@@ -182,7 +182,7 @@ public:
//Обратно стартуем периодический опрос датчика библиотекой (по описанию библиотеки каждые 5сек)
// Start Measurement
errorCodeScd4x = instance()->startPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->startPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute startPeriodicMeasurement(): ");
@@ -197,14 +197,14 @@ public:
{
//Останавливаем периодический опрос датчика вбиблиотеке для запроса Сер.номера (на всякий случай)
// stop potentially previously started measurement
errorCodeScd4x = instance()->stopPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->stopPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
Serial.println(errorMessageScd4x);
}
errorCodeScd4x = instance()->startLowPowerPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->startLowPowerPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute startLowPowerPeriodicMeasurement(): ");
@@ -216,7 +216,7 @@ public:
Serial.println("startLowPowerPeriodicMeasurement(): OK!");
}
errorCodeScd4x = instance()->setAutomaticSelfCalibration((uint16_t)autoCalibration);
errorCodeScd4x = instanceScd4x()->setAutomaticSelfCalibration((uint16_t)autoCalibration);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute setAutomaticSelfCalibration(): ");
@@ -230,7 +230,7 @@ public:
//Обратно стартуем периодический опрос датчика библиотекой (по описанию библиотеки каждые 5сек)
// Start Measurement
errorCodeScd4x = instance()->startPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->startPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute startPeriodicMeasurement(): ");
@@ -262,7 +262,7 @@ public:
float temperature = 0.0f;
float humidity = 0.0f;
bool isDataReady = false;
errorCodeScd4x = instance()->getDataReadyFlag(isDataReady);
errorCodeScd4x = instanceScd4x()->getDataReadyFlag(isDataReady);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute getDataReadyFlag(): ");
@@ -274,7 +274,7 @@ public:
{
return;
}
errorCodeScd4x = instance()->readMeasurement(co2, temperature, humidity);
errorCodeScd4x = instanceScd4x()->readMeasurement(co2, temperature, humidity);
if (errorCodeScd4x)
{
Serial.print("errorCodeScd4x trying to execute readMeasurement(): ");
@@ -308,14 +308,14 @@ public:
{
//Останавливаем периодический опрос датчика вбиблиотеке для запроса Сер.номера (на всякий случай)
// stop potentially previously started measurement
errorCodeScd4x = instance()->stopPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->stopPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
Serial.println(errorMessageScd4x);
}
errorCodeScd4x = instance()->setTemperatureOffset((uint16_t)offsetT);
errorCodeScd4x = instanceScd4x()->setTemperatureOffset((uint16_t)offsetT);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute setTemperatureOffset(): ");
@@ -329,7 +329,7 @@ public:
//Обратно стартуем периодический опрос датчика библиотекой (по описанию библиотеки каждые 5сек)
// Start Measurement
errorCodeScd4x = instance()->startPeriodicMeasurement();
errorCodeScd4x = instanceScd4x()->startPeriodicMeasurement();
if (errorCodeScd4x)
{
Serial.print("Error trying to execute startPeriodicMeasurement(): ");
@@ -357,7 +357,7 @@ public:
float temperature = 0.0f;
float humidity = 0.0f;
bool isDataReady = false;
errorCodeScd4x = instance()->getDataReadyFlag(isDataReady);
errorCodeScd4x = instanceScd4x()->getDataReadyFlag(isDataReady);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute getDataReadyFlag(): ");
@@ -369,7 +369,7 @@ public:
{
return;
}
errorCodeScd4x = instance()->readMeasurement(co2, temperature, humidity);
errorCodeScd4x = instanceScd4x()->readMeasurement(co2, temperature, humidity);
if (errorCodeScd4x)
{
Serial.print("Error trying to execute readMeasurement(): ");