2021-01-03 21:43:35 +00:00
|
|
|
#include <FTPFilesystem.h>
|
2021-03-12 22:21:45 +00:00
|
|
|
#include <SPIFFS.h>
|
2021-01-03 21:43:35 +00:00
|
|
|
#include <logger.h>
|
2021-03-12 22:21:45 +00:00
|
|
|
|
2021-01-04 22:10:23 +00:00
|
|
|
#include "Task.h"
|
2021-03-12 22:21:45 +00:00
|
|
|
#include "TaskFTP.h"
|
|
|
|
#include "project_configuration.h"
|
2021-01-03 21:43:35 +00:00
|
|
|
|
2021-03-12 22:21:45 +00:00
|
|
|
FTPTask::FTPTask() : Task(TASK_FTP, TaskFtp), _beginCalled(false) {
|
2021-01-03 21:43:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 22:21:45 +00:00
|
|
|
FTPTask::~FTPTask() {
|
2021-01-03 21:43:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 22:44:37 +00:00
|
|
|
bool FTPTask::setup(System &system) {
|
|
|
|
for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) {
|
2021-03-12 22:21:45 +00:00
|
|
|
logPrintD("Adding user to FTP Server: ");
|
|
|
|
logPrintlnD(user.name);
|
2021-05-18 23:03:35 +00:00
|
|
|
_ftpServer.addUser(user.name, user.password);
|
2021-03-12 22:21:45 +00:00
|
|
|
}
|
2021-05-18 23:03:35 +00:00
|
|
|
_ftpServer.addFilesystem("SPIFFS", &SPIFFS);
|
2021-03-12 22:21:45 +00:00
|
|
|
_stateInfo = "waiting";
|
|
|
|
return true;
|
2021-01-03 21:43:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 22:44:37 +00:00
|
|
|
bool FTPTask::loop(System &system) {
|
2021-03-12 22:21:45 +00:00
|
|
|
if (!_beginCalled) {
|
2021-05-18 23:03:35 +00:00
|
|
|
_ftpServer.begin();
|
2021-03-12 22:21:45 +00:00
|
|
|
_beginCalled = true;
|
|
|
|
}
|
2021-05-18 23:03:35 +00:00
|
|
|
_ftpServer.handle();
|
2021-03-12 22:21:45 +00:00
|
|
|
static bool configWasOpen = false;
|
2021-05-18 23:03:35 +00:00
|
|
|
if (configWasOpen && _ftpServer.countConnections() == 0) {
|
2021-03-12 22:21:45 +00:00
|
|
|
logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
|
|
|
logPrintlnW("");
|
|
|
|
ESP.restart();
|
|
|
|
}
|
2021-05-18 23:03:35 +00:00
|
|
|
if (_ftpServer.countConnections() > 0) {
|
2021-03-12 22:21:45 +00:00
|
|
|
configWasOpen = true;
|
|
|
|
_stateInfo = "has connection";
|
|
|
|
}
|
|
|
|
return true;
|
2021-01-03 21:43:35 +00:00
|
|
|
}
|