mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Модуль FTP
This commit is contained in:
97
src/modules/exec/Ftp/Ftp.cpp
Normal file
97
src/modules/exec/Ftp/Ftp.cpp
Normal 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;
|
||||
}
|
||||
68
src/modules/exec/Ftp/modinfo.json
Normal file
68
src/modules/exec/Ftp/modinfo.json
Normal 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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(): ");
|
||||
|
||||
Reference in New Issue
Block a user