mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
не рабочая версия
This commit is contained in:
@@ -398,7 +398,7 @@
|
|||||||
"execLevel": "1",
|
"execLevel": "1",
|
||||||
"pinMode": "INPUT",
|
"pinMode": "INPUT",
|
||||||
"debounceDelay": 50,
|
"debounceDelay": 50,
|
||||||
"fixState": 1,
|
"fixState": 0,
|
||||||
"num": 30
|
"num": 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -455,18 +455,16 @@
|
|||||||
"num": 34
|
"num": 34
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "35. PWM ESP32",
|
"name": "35. PWM ESP8266",
|
||||||
"type": "Writing",
|
"type": "Writing",
|
||||||
"subtype": "Pwm32",
|
"subtype": "Pwm8266",
|
||||||
"id": "pwm",
|
"id": "pwm",
|
||||||
"widget": "range",
|
"widget": "range",
|
||||||
"page": "Кнопки",
|
"page": "Кнопки",
|
||||||
"descr": "PWM",
|
"descr": "PWM",
|
||||||
"int": 0,
|
"int": 0,
|
||||||
"pin": 2,
|
"pin": 15,
|
||||||
"freq": 5000,
|
"freq": 5000,
|
||||||
"ledChannel": 2,
|
|
||||||
"PWM_resolution": 10,
|
|
||||||
"val": 0,
|
"val": 0,
|
||||||
"apin": -1,
|
"apin": -1,
|
||||||
"num": 35
|
"num": 35
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef esp32_4mb
|
#ifdef esp32_4mb
|
||||||
#define USE_LITTLEFS false
|
#define USE_LITTLEFS true
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define START_DATETIME 1661990400 // 01.09.2022 00:00:00 константа для сокращения unix time
|
#define START_DATETIME 1661990400 // 01.09.2022 00:00:00 константа для сокращения unix time
|
||||||
|
|||||||
@@ -12,14 +12,17 @@ extern const String filepath(const String& filename);
|
|||||||
extern bool cutFile(const String& src, const String& dst);
|
extern bool cutFile(const String& src, const String& dst);
|
||||||
extern size_t countLines(const String filename);
|
extern size_t countLines(const String filename);
|
||||||
void removeFile(const String& filename);
|
void removeFile(const String& filename);
|
||||||
|
void removeDirectory(const String& dir);
|
||||||
void cleanDirectory(String path);
|
void cleanDirectory(String path);
|
||||||
void cleanLogs();
|
void cleanLogs1();
|
||||||
|
void cleanLogs2();
|
||||||
void saveDataDB(String id, String data);
|
void saveDataDB(String id, String data);
|
||||||
String readDataDB(String id);
|
String readDataDB(String id);
|
||||||
extern void onFlashWrite();
|
extern void onFlashWrite();
|
||||||
|
|
||||||
String FileList(String path);
|
String getFilesList8266(String& directory);
|
||||||
|
String getFilesList32(String& directory);
|
||||||
|
String getFilesList(String& directory);
|
||||||
extern void getFSInfo();
|
extern void getFSInfo();
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
extern bool getInfo(FSInfo& info);
|
extern bool getInfo(FSInfo& info);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
},
|
},
|
||||||
"projectProp": {
|
"projectProp": {
|
||||||
"platformio": {
|
"platformio": {
|
||||||
"default_envs": "esp32_4mb",
|
"default_envs": "esp8266_4mb",
|
||||||
"data_dir": "data_svelte"
|
"data_dir": "data_svelte"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ monitor_filters = esp32_exception_decoder
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
debug_tool = esp-prog
|
debug_tool = esp-prog
|
||||||
|
board_build.filesystem = littlefs
|
||||||
build_src_filter =
|
build_src_filter =
|
||||||
+<*.cpp>
|
+<*.cpp>
|
||||||
+<classes/*.cpp>
|
+<classes/*.cpp>
|
||||||
@@ -40,7 +41,7 @@ build_src_filter =
|
|||||||
${env:esp32_4mb_fromitems.build_src_filter}
|
${env:esp32_4mb_fromitems.build_src_filter}
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp32_4mb
|
default_envs = esp8266_4mb
|
||||||
data_dir = data_svelte
|
data_dir = data_svelte
|
||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
|
|||||||
@@ -196,8 +196,12 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//команда очистки всех логов esp
|
//команда очистки всех логов esp
|
||||||
if (headerStr == "/clean|") {
|
if (headerStr == "/clean1|") {
|
||||||
cleanLogs();
|
cleanLogs1();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headerStr == "/clean2|") {
|
||||||
|
cleanLogs2();
|
||||||
}
|
}
|
||||||
|
|
||||||
//команда обновления прошивки esp
|
//команда обновления прошивки esp
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
|
|||||||
void* getAPI_IoTServo(String subtype, String params);
|
void* getAPI_IoTServo(String subtype, String params);
|
||||||
void* getAPI_Mcp23017(String subtype, String params);
|
void* getAPI_Mcp23017(String subtype, String params);
|
||||||
void* getAPI_Mp3(String subtype, String params);
|
void* getAPI_Mp3(String subtype, String params);
|
||||||
void* getAPI_Pwm32(String subtype, String params);
|
void* getAPI_Pwm8266(String subtype, String params);
|
||||||
void* getAPI_TelegramLT(String subtype, String params);
|
void* getAPI_TelegramLT(String subtype, String params);
|
||||||
void* getAPI_Lcd2004(String subtype, String params);
|
void* getAPI_Lcd2004(String subtype, String params);
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
|||||||
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -119,46 +119,9 @@ class Loging : public IoTItem {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
|
||||||
void getFilesList8266() {
|
|
||||||
filesList = "";
|
|
||||||
String directory = "lg/" + id;
|
|
||||||
auto dir = FileFS.openDir(directory);
|
|
||||||
while (dir.next()) {
|
|
||||||
String fname = dir.fileName();
|
|
||||||
if (fname != "") filesList += directory + "/" + fname + ";";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ESP32)
|
|
||||||
void getFilesList32() {
|
|
||||||
filesList = "";
|
|
||||||
String directory = "/lg/" + id;
|
|
||||||
File root = FileFS.open(directory);
|
|
||||||
directory = String();
|
|
||||||
if (root.isDirectory()) {
|
|
||||||
File file = root.openNextFile();
|
|
||||||
while (file) {
|
|
||||||
String fname = file.name();
|
|
||||||
if (fname != "") filesList += fname + ";";
|
|
||||||
file = root.openNextFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void getFilesList() {
|
|
||||||
#if defined(ESP8266)
|
|
||||||
getFilesList8266();
|
|
||||||
#endif
|
|
||||||
#if defined(ESP32)
|
|
||||||
getFilesList32();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendChart() {
|
void sendChart() {
|
||||||
getFilesList();
|
String dir = "lg/" + id;
|
||||||
|
filesList = getFilesList(dir);
|
||||||
int f = 0;
|
int f = 0;
|
||||||
|
|
||||||
bool noData = true;
|
bool noData = true;
|
||||||
@@ -202,7 +165,8 @@ class Loging : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cleanData() {
|
void cleanData() {
|
||||||
getFilesList();
|
String dir = "lg/" + id;
|
||||||
|
filesList = getFilesList(dir);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (filesList.length()) {
|
while (filesList.length()) {
|
||||||
String buf = selectToMarker(filesList, ";");
|
String buf = selectToMarker(filesList, ";");
|
||||||
|
|||||||
@@ -183,42 +183,37 @@ void removeFile(const String& filename) {
|
|||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
if (FileFS.exists(path)) {
|
if (FileFS.exists(path)) {
|
||||||
if (!FileFS.remove(path)) {
|
if (!FileFS.remove(path)) {
|
||||||
// SerialPrint("i", "Files", "remove " + path);
|
SerialPrint("i", "Files", "remove file" + path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SerialPrint("E", "Files", "not exist " + path);
|
SerialPrint("E", "Files", "file not exist " + path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeDirectory(const String& dir) {
|
||||||
|
String path = filepath(dir);
|
||||||
|
if (FileFS.exists(path)) {
|
||||||
|
if (!FileFS.rmdir(path)) {
|
||||||
|
SerialPrint("i", "Files", "remove dir" + path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SerialPrint("E", "Files", "dir not exist " + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//очищаем директорию с файлами
|
//очищаем директорию с файлами
|
||||||
void cleanDirectory(String path) {
|
void cleanDirectory(String path) {
|
||||||
#if defined(ESP8266)
|
String filesList = getFilesList(path);
|
||||||
auto dir = FileFS.openDir(path);
|
int i = 0;
|
||||||
while (dir.next()) {
|
while (filesList.length()) {
|
||||||
String fname = dir.fileName();
|
String buf = selectToMarker(filesList, ";");
|
||||||
removeFile(path + "/" + fname);
|
|
||||||
SerialPrint("i", "Files", path + "/" + fname + " => deleted");
|
i++;
|
||||||
|
removeFile(buf);
|
||||||
|
SerialPrint("i", "Files", String(i) + ") " + buf + " => deleted");
|
||||||
|
|
||||||
|
filesList = deleteBeforeDelimiter(filesList, ";");
|
||||||
}
|
}
|
||||||
onFlashWrite();
|
|
||||||
#endif
|
|
||||||
#if defined(ESP32)
|
|
||||||
path = "/" + path;
|
|
||||||
File root = FileFS.open(path);
|
|
||||||
path = String();
|
|
||||||
if (!root) {
|
|
||||||
SerialPrint("E", "Files", "nothing to delete");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (root.isDirectory()) {
|
|
||||||
File file = root.openNextFile();
|
|
||||||
while (file) {
|
|
||||||
String fname = file.name();
|
|
||||||
removeFile(fname);
|
|
||||||
SerialPrint("i", "Files", fname + " => deleted");
|
|
||||||
file = root.openNextFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveDataDB(String id, String data) {
|
void saveDataDB(String id, String data) {
|
||||||
@@ -231,7 +226,8 @@ String readDataDB(String id) {
|
|||||||
return readFile(path, 2000);
|
return readFile(path, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanLogs() {
|
void cleanLogs1() {
|
||||||
|
SerialPrint("i", "Files", "cleanLogs1");
|
||||||
cleanDirectory("db");
|
cleanDirectory("db");
|
||||||
//очистка данных всех экземпляров графиков
|
//очистка данных всех экземпляров графиков
|
||||||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
@@ -241,6 +237,20 @@ void cleanLogs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanLogs2() {
|
||||||
|
SerialPrint("i", "Files", "cleanLogs2");
|
||||||
|
|
||||||
|
String dir1 = "db";
|
||||||
|
SerialPrint("i", "", getFilesList(dir1));
|
||||||
|
removeDirectory(dir1);
|
||||||
|
SerialPrint("i", "", getFilesList(dir1));
|
||||||
|
|
||||||
|
String dir2 = "lg";
|
||||||
|
SerialPrint("i", "", getFilesList(dir2));
|
||||||
|
removeDirectory(dir2);
|
||||||
|
SerialPrint("i", "", getFilesList(dir2));
|
||||||
|
}
|
||||||
|
|
||||||
//счетчик количества записей на флешь за сеанс
|
//счетчик количества записей на флешь за сеанс
|
||||||
void onFlashWrite() {
|
void onFlashWrite() {
|
||||||
flashWriteNumber++;
|
flashWriteNumber++;
|
||||||
@@ -249,49 +259,44 @@ void onFlashWrite() {
|
|||||||
|
|
||||||
// Создаем список файлов каталога, функции от Сергея Третьякова
|
// Создаем список файлов каталога, функции от Сергея Третьякова
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
String FileList(String path) {
|
String getFilesList8266(String& directory) {
|
||||||
Dir dir = FileFS.openDir(path);
|
String filesList = "";
|
||||||
path = String();
|
auto dir = FileFS.openDir(directory);
|
||||||
String output = "[";
|
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
File entry = dir.openFile("r");
|
String fname = dir.fileName();
|
||||||
if (output != "[") output += ',';
|
if (fname != "") filesList += directory + "/" + fname + ";";
|
||||||
bool isDir = false;
|
|
||||||
output += "{\"type\":\"";
|
|
||||||
output += (isDir) ? "dir" : "file";
|
|
||||||
output += "\",\"name\":\"";
|
|
||||||
output += String(entry.name()).substring(1);
|
|
||||||
output += "\"}";
|
|
||||||
entry.close();
|
|
||||||
}
|
}
|
||||||
output += "]";
|
return filesList;
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
String FileList(String path) {
|
|
||||||
File root = FileFS.open(path);
|
|
||||||
path = String();
|
|
||||||
|
|
||||||
String output = "[";
|
#if defined(ESP32)
|
||||||
|
String getFilesList32(String& directory) {
|
||||||
|
String filesList = "";
|
||||||
|
String directory = "/" + directory;
|
||||||
|
File root = FileFS.open(directory);
|
||||||
|
directory = String();
|
||||||
if (root.isDirectory()) {
|
if (root.isDirectory()) {
|
||||||
File file = root.openNextFile();
|
File file = root.openNextFile();
|
||||||
while (file) {
|
while (file) {
|
||||||
if (output != "[") {
|
String fname = file.name();
|
||||||
output += ',';
|
if (fname != "") filesList += fname + ";";
|
||||||
}
|
|
||||||
output += "{\"type\":\"";
|
|
||||||
output += (file.isDirectory()) ? "dir" : "file";
|
|
||||||
output += "\",\"name\":\"";
|
|
||||||
// output += String(file.path()).substring(1);
|
|
||||||
output += "\"}";
|
|
||||||
file = root.openNextFile();
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output += "]";
|
return filesList;
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
String getFilesList(String& directory) {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
return getFilesList8266(directory);
|
||||||
|
#endif
|
||||||
|
#if defined(ESP32)
|
||||||
|
return getFilesList32(directory);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
bool getInfo(FSInfo& info) {
|
bool getInfo(FSInfo& info) {
|
||||||
return FileFS.info(info);
|
return FileFS.info(info);
|
||||||
|
|||||||
Reference in New Issue
Block a user