This commit is contained in:
Yuri Trikoz
2020-06-22 14:01:12 +03:00
parent 092bec7dde
commit 274678f17a
20 changed files with 429 additions and 359 deletions

View File

@@ -54,6 +54,32 @@ String addFile(const String filename, const String str) {
return "Sucсess";
}
bool copyFile(const String src, const String dst, bool overwrite) {
String source = filepath(src);
String destination = filepath(dst);
if (!LittleFS.exists(source)) {
pm.error("source not exist: " + source);
return false;
}
if (LittleFS.exists(destination)) {
if (!overwrite) {
pm.error("destination already exist: " + destination);
return false;
}
LittleFS.remove(destination);
}
auto srcFile = LittleFS.open(source, "r");
auto dstFile = LittleFS.open(destination, "w");
static uint8_t buf[512];
while (srcFile.read(buf, 512)) {
dstFile.write(buf, 512);
}
srcFile.close();
dstFile.close();
return true;
}
String writeFile(const String filename, const String str) {
auto file = LittleFS.open(filepath(filename), "w");
if (!file) {

View File

@@ -35,16 +35,23 @@ String selectToMarkerPlus(String str, String found, int plus) {
return str.substring(0, p + plus);
}
String selectFromMarkerToMarker(String str, String found, int number) {
if (str.indexOf(found) == -1) return "not found"; // если строки поиск нет сразу выход
str += found; // добавим для корректного поиска
uint8_t i = 0; // Индекс перебора
String selectFromMarkerToMarker(String str, String tofind, int number) {
if (str.indexOf(tofind) == -1) {
return "not found";
}
str += tofind; // добавим для корректного поиска
uint8_t i = 0; // Индекс перебора
do {
if (i == number) return selectToMarker(str, found); // если индекс совпал с позицией законцим вернем резултат
str = deleteBeforeDelimiter(str, found); // отбросим проверенный блок до разделителя
i++; // увеличим индекс
} while (str.length() != 0); // повторим пока строка не пустая
return "not found"; // Достигли пустой строки и ничего не нашли
if (i == number) {
// если индекс совпал с позицией
return selectToMarker(str, tofind);
}
// отбросим проверенный блок до разделителя
str = deleteBeforeDelimiter(str, tofind);
i++;
} while (str.length() != 0);
return "not found";
}
uint8_t hexStringToUint8(String hex) {

View File

@@ -44,7 +44,7 @@ void startSTAMode() {
} while (keepConnecting && tries--);
if (WiFi.status() == WL_CONNECTED) {
MQTT_init();
initMQTT();
setLedStatus(LED_OFF);
} else {
startAPMode();
@@ -105,4 +105,8 @@ boolean scanWiFi(String ssid) {
}
}
return res;
}
}
boolean isNetworkActive() {
return WiFi.status() == WL_CONNECTED;
}