mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Модуль FTP
This commit is contained in:
@@ -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()!!
|
||||
}
|
||||
@@ -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...
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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()!!
|
||||
}
|
||||
105
lib/SimpleFTPServer/examples/ESP32_FFAT_WiFi/ESP32_FFAT_WiFi.ino
Normal file
105
lib/SimpleFTPServer/examples/ESP32_FFAT_WiFi/ESP32_FFAT_WiFi.ino
Normal 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()!!
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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()!!
|
||||
}
|
||||
@@ -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()!!
|
||||
}
|
||||
@@ -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...
|
||||
}
|
||||
@@ -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...
|
||||
}
|
||||
@@ -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...
|
||||
}
|
||||
106
lib/SimpleFTPServer/examples/Wio_terminal/Wio_terminal.ino
Normal file
106
lib/SimpleFTPServer/examples/Wio_terminal/Wio_terminal.ino
Normal 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()!!
|
||||
}
|
||||
@@ -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()!!
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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()!!
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user