mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
@@ -4,7 +4,7 @@
|
|||||||
#define FIRMWARE_VERSION 273
|
#define FIRMWARE_VERSION 273
|
||||||
#define FLASH_SIZE_1MB true
|
#define FLASH_SIZE_1MB true
|
||||||
//===========FileSystem==============================================================================================================================================
|
//===========FileSystem==============================================================================================================================================
|
||||||
#define USE_LITTLEFS true
|
#define USE_LITTLEFS false
|
||||||
//==================================================================================================================================================================
|
//==================================================================================================================================================================
|
||||||
#define NUM_BUTTONS 6
|
#define NUM_BUTTONS 6
|
||||||
#define LED_PIN LED_BUILTIN
|
#define LED_PIN LED_BUILTIN
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <ESP8266httpUpdate.h>
|
#include <ESP8266httpUpdate.h>
|
||||||
#include "ESPAsyncTCP.h"
|
#include "ESPAsyncTCP.h"
|
||||||
#include "ESPAsyncWebServer.h"
|
#include "ESPAsyncWebServer.h"
|
||||||
#include <LittleFS.h>
|
|
||||||
#include <SPIFFSEditor.h>
|
#include <SPIFFSEditor.h>
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
//#include <FS.h>
|
#include "FileSystem.h"
|
||||||
#ifdef ESP8266
|
|
||||||
#include <LittleFS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class FSEditor : public AsyncWebHandler {
|
class FSEditor : public AsyncWebHandler {
|
||||||
private:
|
private:
|
||||||
@@ -20,7 +18,7 @@ class FSEditor : public AsyncWebHandler {
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
|
FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
|
||||||
#else
|
#else
|
||||||
FSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = LittleFS);
|
FSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = FileFS);
|
||||||
#endif
|
#endif
|
||||||
virtual bool canHandle(AsyncWebServerRequest* request) override final;
|
virtual bool canHandle(AsyncWebServerRequest* request) override final;
|
||||||
virtual void handleRequest(AsyncWebServerRequest* request) override final;
|
virtual void handleRequest(AsyncWebServerRequest* request) override final;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#define FILE_WRITE "w"
|
#define FILE_WRITE "w"
|
||||||
#define FILE_APPEND "a"
|
#define FILE_APPEND "a"
|
||||||
|
|
||||||
|
#include <FS.h>
|
||||||
|
|
||||||
#if USE_LITTLEFS
|
#if USE_LITTLEFS
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
extern FS LittleFS;
|
extern FS LittleFS;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
//#include "FS.h"
|
|
||||||
#ifdef ESP32
|
#include "FileSystem.h"
|
||||||
#include "LITTLEFS.h"
|
|
||||||
#define LittleFS LITTLEFS
|
|
||||||
#endif
|
|
||||||
#ifdef ESP8266
|
|
||||||
#include <LittleFS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class FileHelper {
|
class FileHelper {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Consts.h"
|
#include "Consts.h"
|
||||||
//#include "FS.h"
|
#include "FileSystem.h"
|
||||||
#ifdef ESP32
|
|
||||||
#include "LITTLEFS.h"
|
|
||||||
#define LittleFS LITTLEFS
|
|
||||||
#endif
|
|
||||||
#ifdef ESP8266
|
|
||||||
#include <LittleFS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Инициализация ФС
|
* Инициализация ФС
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp8266_01_1m
|
default_envs = esp8266
|
||||||
;=============================================================================================================================================
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
lib_deps_external =
|
lib_deps_external =
|
||||||
bblanchon/ArduinoJson @5.*
|
bblanchon/ArduinoJson @5.*
|
||||||
@@ -15,7 +24,7 @@ lib_deps_internal =
|
|||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
GyverFilters
|
GyverFilters
|
||||||
OneWire
|
OneWire
|
||||||
;=============================================================================================================================================
|
|
||||||
[env:esp32]
|
[env:esp32]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
@@ -32,15 +41,11 @@ upload_speed = 921600
|
|||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
extra_scripts = ./tools/littlefsbuilder.py
|
extra_scripts = ./tools/littlefsbuilder.py
|
||||||
;=============================================================================================================================================
|
|
||||||
[env:esp8266_01_1m]
|
[env:esp8266_01_1m]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
;board = esp01_1m
|
|
||||||
;board = esp12e
|
|
||||||
board_build.ldscript = eagle.flash.1m512.ld
|
board_build.ldscript = eagle.flash.1m512.ld
|
||||||
;board_build.filesystem.spiffs_blocksize = 4096
|
|
||||||
board_build.spiffs_blocksize = 4096
|
|
||||||
platform = https://github.com/platformio/platform-espressif8266.git
|
platform = https://github.com/platformio/platform-espressif8266.git
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
@@ -53,7 +58,7 @@ monitor_filters = esp8266_exception_decoder
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
;=============================================================================================================================================
|
|
||||||
[env:esp8266]
|
[env:esp8266]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
@@ -70,4 +75,3 @@ monitor_filters = esp8266_exception_decoder
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
;=============================================================================================================================================
|
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
#include "FSEditor.h"
|
#include "FSEditor.h"
|
||||||
|
|
||||||
#ifdef ESP32
|
#include "FileSystem.h"
|
||||||
#include "LITTLEFS.h"
|
|
||||||
#define LittleFS LITTLEFS
|
|
||||||
#endif
|
|
||||||
#ifdef ESP8266
|
|
||||||
#include <LittleFS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FS_MAXLENGTH_FILEPATH 32
|
#define FS_MAXLENGTH_FILEPATH 32
|
||||||
|
|
||||||
const char *excludeListFile = "/.exclude.files";
|
const char *excludeListFile = "/.exclude.files";
|
||||||
|
|
||||||
typedef struct ExcludeListS {
|
typedef struct ExcludeListS {
|
||||||
char *item;
|
char *item;
|
||||||
ExcludeListS *next;
|
ExcludeListS *next;
|
||||||
@@ -239,7 +232,7 @@ void FSEditor::handleRequest(AsyncWebServerRequest *request) {
|
|||||||
if (request->header("If-Modified-Since").equals(buildTime)) {
|
if (request->header("If-Modified-Since").equals(buildTime)) {
|
||||||
request->send(304);
|
request->send(304);
|
||||||
} else {
|
} else {
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/edit.htm", "text/html");
|
AsyncWebServerResponse *response = request->beginResponse(FileFS, "/edit.htm", "text/html");
|
||||||
// response->addHeader("Content-Encoding", "gzip");
|
// response->addHeader("Content-Encoding", "gzip");
|
||||||
response->addHeader("Last-Modified", buildTime);
|
response->addHeader("Last-Modified", buildTime);
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
@@ -25,7 +26,7 @@ void itemsListInit() {
|
|||||||
|
|
||||||
void addItem2(String param) {
|
void addItem2(String param) {
|
||||||
int num = selectToMarker(param, "-").toInt();
|
int num = selectToMarker(param, "-").toInt();
|
||||||
File configFile = LittleFS.open("/items/items.txt", "r");
|
File configFile = FileFS.open("/items/items.txt", "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -62,7 +63,7 @@ void addItem2(String param) {
|
|||||||
|
|
||||||
|
|
||||||
void addPreset2(int num) {
|
void addPreset2(int num) {
|
||||||
File configFile = LittleFS.open("/presets/presets.c.txt", "r");
|
File configFile = FileFS.open("/presets/presets.c.txt", "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,7 @@ void addPreset2(int num) {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
addFile(DEVICE_CONFIG_FILE, config);
|
addFile(DEVICE_CONFIG_FILE, config);
|
||||||
|
|
||||||
File scenFile = LittleFS.open("/presets/presets.s.txt", "r");
|
File scenFile = FileFS.open("/presets/presets.s.txt", "r");
|
||||||
if (!scenFile) {
|
if (!scenFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -160,7 +161,7 @@ uint8_t getFreePinAnalog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void delChoosingItems() {
|
void delChoosingItems() {
|
||||||
File configFile = LittleFS.open("/" + String(DEVICE_CONFIG_FILE), "r");
|
File configFile = FileFS.open("/" + String(DEVICE_CONFIG_FILE), "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
#include <LittleFS.h>
|
|
||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
|
|
||||||
enum MqttBroker {MQTT_PRIMARY, MQTT_RESERVE};
|
enum MqttBroker { MQTT_PRIMARY,
|
||||||
|
MQTT_RESERVE };
|
||||||
|
|
||||||
MqttBroker activeBroker = MQTT_PRIMARY;
|
MqttBroker activeBroker = MQTT_PRIMARY;
|
||||||
|
|
||||||
String mqttPrefix;
|
String mqttPrefix;
|
||||||
@@ -16,7 +17,7 @@ String mqttServer;
|
|||||||
String mqttUser;
|
String mqttUser;
|
||||||
uint16_t mqttPort{0};
|
uint16_t mqttPort{0};
|
||||||
uint16_t reconnectionCounter{0};
|
uint16_t reconnectionCounter{0};
|
||||||
bool primaryExist = false;
|
uint16_t fallbackCounter{0};
|
||||||
|
|
||||||
const String getParamName(const char* param, MqttBroker broker) {
|
const String getParamName(const char* param, MqttBroker broker) {
|
||||||
return String("mqtt") + param + (broker == MQTT_RESERVE ? "2" : "");
|
return String("mqtt") + param + (broker == MQTT_RESERVE ? "2" : "");
|
||||||
@@ -41,10 +42,20 @@ void mqttInit() {
|
|||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
SerialPrint("I", "WIFI", "OK");
|
SerialPrint("I", "WIFI", "OK");
|
||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
|
if (activeBroker == MQTT_RESERVE) {
|
||||||
|
// при 20 cекундных интервалах проверки, каждые 100 сек
|
||||||
|
if (fallbackCounter++ > 5) {
|
||||||
|
if (checkBrokerParams(MQTT_PRIMARY)) {
|
||||||
|
activeBroker = MQTT_PRIMARY;
|
||||||
|
fallbackCounter = 0;
|
||||||
|
mqttReconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
SerialPrint("I", "MQTT", "OK");
|
SerialPrint("I", "MQTT", "OK");
|
||||||
setLedStatus(LED_OFF);
|
setLedStatus(LED_OFF);
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
SerialPrint("E", "MQTT", "lost connection");
|
SerialPrint("E", "MQTT", "lost connection");
|
||||||
if (reconnectionCounter++ > 5) {
|
if (reconnectionCounter++ > 5) {
|
||||||
if (activeBroker == MQTT_PRIMARY) {
|
if (activeBroker == MQTT_PRIMARY) {
|
||||||
@@ -58,8 +69,7 @@ void mqttInit() {
|
|||||||
}
|
}
|
||||||
mqttConnect();
|
mqttConnect();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
SerialPrint("E", "WIFI", "Lost WiFi connection");
|
SerialPrint("E", "WIFI", "Lost WiFi connection");
|
||||||
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
||||||
startAPMode();
|
startAPMode();
|
||||||
@@ -137,8 +147,7 @@ boolean mqttConnect() {
|
|||||||
setLedStatus(LED_OFF);
|
setLedStatus(LED_OFF);
|
||||||
mqttSubscribe();
|
mqttSubscribe();
|
||||||
res = true;
|
res = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
SerialPrint("E", "MQTT", "could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
SerialPrint("E", "MQTT", "could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||||
setLedStatus(LED_FAST);
|
setLedStatus(LED_FAST);
|
||||||
}
|
}
|
||||||
@@ -166,7 +175,6 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (topicStr.indexOf("control") != -1) {
|
else if (topicStr.indexOf("control") != -1) {
|
||||||
|
|
||||||
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
|
|
||||||
String order;
|
String order;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "Upgrade.h"
|
#include "Upgrade.h"
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#include "ESP8266.h"
|
#include "ESP8266.h"
|
||||||
@@ -92,16 +94,16 @@ void upgrade_firmware(int type) {
|
|||||||
bool upgradeFS() {
|
bool upgradeFS() {
|
||||||
WiFiClient wifiClient;
|
WiFiClient wifiClient;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
Serial.println("Start upgrade LittleFS, please wait...");
|
Serial.printf("Start upgrade %s, please wait...", FS_NAME);
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
ESPhttpUpdate.rebootOnUpdate(false);
|
ESPhttpUpdate.rebootOnUpdate(false);
|
||||||
t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp8266/littlefs/littlefs.bin"));
|
t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp8266/") + FS_NAME + "/"+ FS_NAME+ ".bin");
|
||||||
#else
|
#else
|
||||||
httpUpdate.rebootOnUpdate(false);
|
httpUpdate.rebootOnUpdate(false);
|
||||||
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin"));
|
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin"));
|
||||||
#endif
|
#endif
|
||||||
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
|
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
|
||||||
SerialPrint("I", "Update", "LittleFS upgrade done!");
|
SerialPrint("I", "Update", "FS upgrade done!");
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
#include "Utils\SerialPrint.h"
|
#include "Utils\SerialPrint.h"
|
||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const String filepath(const String& filename) {
|
const String filepath(const String& filename) {
|
||||||
return filename.startsWith("/") ? filename : "/" + filename;
|
return filename.startsWith("/") ? filename : "/" + filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileSystemInit() {
|
bool fileSystemInit() {
|
||||||
if (!LittleFS.begin()) {
|
if (!FileFS.begin()) {
|
||||||
SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed"));
|
SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -19,8 +20,8 @@ bool fileSystemInit() {
|
|||||||
|
|
||||||
void removeFile(const String& filename) {
|
void removeFile(const String& filename) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
if (LittleFS.exists(path)) {
|
if (FileFS.exists(path)) {
|
||||||
if (!LittleFS.remove(path)) {
|
if (!FileFS.remove(path)) {
|
||||||
SerialPrint("I","Files","remove " + path);
|
SerialPrint("I","Files","remove " + path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -30,7 +31,7 @@ void removeFile(const String& filename) {
|
|||||||
|
|
||||||
File seekFile(const String& filename, size_t position) {
|
File seekFile(const String& filename, size_t position) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = LittleFS.open(path, "r");
|
auto file = FileFS.open(path, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
SerialPrint("[E]","Files","open " + path);
|
SerialPrint("[E]","Files","open " + path);
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ File seekFile(const String& filename, size_t position) {
|
|||||||
const String readFileString(const String& filename, const String& to_find) {
|
const String readFileString(const String& filename, const String& to_find) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
String res = "failed";
|
String res = "failed";
|
||||||
auto file = LittleFS.open(path, "r");
|
auto file = FileFS.open(path, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,7 @@ const String readFileString(const String& filename, const String& to_find) {
|
|||||||
|
|
||||||
const String addFileLn(const String& filename, const String& str) {
|
const String addFileLn(const String& filename, const String& str) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = LittleFS.open(path, "a");
|
auto file = FileFS.open(path, "a");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -66,7 +67,7 @@ const String addFileLn(const String& filename, const String& str) {
|
|||||||
|
|
||||||
const String addFile(const String& filename, const String& str) {
|
const String addFile(const String& filename, const String& str) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = LittleFS.open(path, "a");
|
auto file = FileFS.open(path, "a");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -79,19 +80,19 @@ bool copyFile(const String& src, const String& dst, bool overwrite) {
|
|||||||
String srcPath = filepath(src);
|
String srcPath = filepath(src);
|
||||||
String dstPath = filepath(dst);
|
String dstPath = filepath(dst);
|
||||||
SerialPrint("I","Files","copy " + srcPath + " to " + dstPath);
|
SerialPrint("I","Files","copy " + srcPath + " to " + dstPath);
|
||||||
if (!LittleFS.exists(srcPath)) {
|
if (!FileFS.exists(srcPath)) {
|
||||||
SerialPrint("[E]","Files","not exist: " + srcPath);
|
SerialPrint("[E]","Files","not exist: " + srcPath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (LittleFS.exists(dstPath)) {
|
if (FileFS.exists(dstPath)) {
|
||||||
if (!overwrite) {
|
if (!overwrite) {
|
||||||
SerialPrint("[E]","Files","already exist: " + dstPath);
|
SerialPrint("[E]","Files","already exist: " + dstPath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LittleFS.remove(dstPath);
|
FileFS.remove(dstPath);
|
||||||
}
|
}
|
||||||
auto srcFile = LittleFS.open(srcPath, "r");
|
auto srcFile = FileFS.open(srcPath, "r");
|
||||||
auto dstFile = LittleFS.open(dstPath, "w");
|
auto dstFile = FileFS.open(dstPath, "w");
|
||||||
|
|
||||||
uint8_t buf[512];
|
uint8_t buf[512];
|
||||||
while (srcFile.available()) {
|
while (srcFile.available()) {
|
||||||
@@ -105,7 +106,7 @@ bool copyFile(const String& src, const String& dst, bool overwrite) {
|
|||||||
|
|
||||||
const String writeFile(const String& filename, const String& str) {
|
const String writeFile(const String& filename, const String& str) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = LittleFS.open(path, "w");
|
auto file = FileFS.open(path, "w");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@ const String writeFile(const String& filename, const String& str) {
|
|||||||
|
|
||||||
const String readFile(const String& filename, size_t max_size) {
|
const String readFile(const String& filename, size_t max_size) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = LittleFS.open(path, "r");
|
auto file = FileFS.open(path, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -132,7 +133,7 @@ const String readFile(const String& filename, size_t max_size) {
|
|||||||
|
|
||||||
const String getFileSize(const String filename) {
|
const String getFileSize(const String filename) {
|
||||||
String filepath(filename);
|
String filepath(filename);
|
||||||
auto file = LittleFS.open(filepath, "r");
|
auto file = FileFS.open(filepath, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
@@ -145,13 +146,13 @@ const String getFSSizeInfo() {
|
|||||||
String res;
|
String res;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
FSInfo info;
|
FSInfo info;
|
||||||
if (LittleFS.info(info)) {
|
if (FileFS.info(info)) {
|
||||||
res = prettyBytes(info.usedBytes) + " of " + prettyBytes(info.totalBytes);
|
res = prettyBytes(info.usedBytes) + " of " + prettyBytes(info.totalBytes);
|
||||||
} else {
|
} else {
|
||||||
res = "error";
|
res = "error";
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
res = prettyBytes(LittleFS.usedBytes()) + " of " + prettyBytes(LittleFS.totalBytes());
|
res = prettyBytes(FileFS.usedBytes()) + " of " + prettyBytes(FileFS.totalBytes());
|
||||||
#endif
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,18 +16,18 @@ void init() {
|
|||||||
String login = jsonReadStr(configSetupJson, "weblogin");
|
String login = jsonReadStr(configSetupJson, "weblogin");
|
||||||
String pass = jsonReadStr(configSetupJson, "webpass");
|
String pass = jsonReadStr(configSetupJson, "webpass");
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
server.addHandler(new FSEditor(LittleFS, login, pass));
|
server.addHandler(new FSEditor(FileFS, login, pass));
|
||||||
#else
|
#else
|
||||||
server.addHandler(new FSEditor(login, pass));
|
server.addHandler(new FSEditor(login, pass));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server.serveStatic("/css/", LittleFS, "/css/").setCacheControl("max-age=600");
|
server.serveStatic("/css/", FileFS, "/css/").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/js/", LittleFS, "/js/").setCacheControl("max-age=600");
|
server.serveStatic("/js/", FileFS, "/js/").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico").setCacheControl("max-age=600");
|
server.serveStatic("/favicon.ico", FileFS, "/favicon.ico").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/icon.jpeg", LittleFS, "/icon.jpeg").setCacheControl("max-age=600");
|
server.serveStatic("/icon.jpeg", FileFS, "/icon.jpeg").setCacheControl("max-age=600");
|
||||||
server.serveStatic("/edit", LittleFS, "/edit").setCacheControl("max-age=600");
|
server.serveStatic("/edit", FileFS, "/edit").setCacheControl("max-age=600");
|
||||||
|
|
||||||
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());
|
server.serveStatic("/", FileFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());
|
||||||
|
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request));
|
SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request));
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
@@ -146,8 +148,9 @@ void sendLogData(String file, String topic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cleanLogAndData() {
|
void cleanLogAndData() {
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
auto dir = LittleFS.openDir("logs");
|
auto dir = FileFS.openDir("logs");
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
String fname = dir.fileName();
|
String fname = dir.fileName();
|
||||||
SerialPrint("I", "System", fname);
|
SerialPrint("I", "System", fname);
|
||||||
|
|||||||
Reference in New Issue
Block a user