From 54841d59cfc18e8d3793608065e8dfff1f695efc Mon Sep 17 00:00:00 2001
From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com>
Date: Sat, 10 Oct 2020 01:44:11 +0300
Subject: [PATCH] 252 added delete function in items list
---
.vscode/settings.json | 7 ++
data/items/analog-adc.txt | 2 +-
data/items/bme280-hum.txt | 2 +-
data/items/bme280-press.txt | 2 +-
data/items/bme280-temp.txt | 2 +-
data/items/bmp280-press.txt | 2 +-
data/items/bmp280-temp.txt | 2 +-
data/items/button-in.txt | 2 +-
data/items/button-out-i.txt | 1 -
data/items/button-out-np.txt | 1 -
data/items/button-out-p.txt | 1 -
data/items/button-out.inv.txt | 1 +
data/items/button-out.npin.txt | 1 +
data/items/button-out.pin.txt | 1 +
data/items/dallas-temp.txt | 2 +-
data/items/dht11-hum.txt | 2 +-
data/items/dht11-temp.txt | 2 +-
data/items/dht22-hum.txt | 2 +-
data/items/dht22-temp.txt | 2 +-
data/items/input-digit.txt | 2 +-
data/items/input-time.txt | 2 +-
data/items/modbus.txt | 2 +-
data/items/output-text.txt | 2 +-
data/items/pwm-out.txt | 2 +-
data/items/signs.json | 5 --
data/items/ultrasonic-cm.txt | 2 +-
data/set.device.json | 15 +++-
data/set.deviceold.json | 143 ---------------------------------
include/Consts.h | 4 +-
include/ItemsList.h | 2 +
src/BufferExecute.cpp | 2 +
src/ItemsList.cpp | 133 ++++++++++++++----------------
src/Web.cpp | 21 +++--
src/main.cpp | 41 +++++-----
34 files changed, 142 insertions(+), 273 deletions(-)
create mode 100644 .vscode/settings.json
delete mode 100644 data/items/button-out-i.txt
delete mode 100644 data/items/button-out-np.txt
delete mode 100644 data/items/button-out-p.txt
create mode 100644 data/items/button-out.inv.txt
create mode 100644 data/items/button-out.npin.txt
create mode 100644 data/items/button-out.pin.txt
delete mode 100644 data/items/signs.json
delete mode 100644 data/set.deviceold.json
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..cc4865fe
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,7 @@
+{
+ "files.associations": {
+ "functional": "cpp",
+ "bitset": "cpp",
+ "algorithm": "cpp"
+ }
+}
\ No newline at end of file
diff --git a/data/items/analog-adc.txt b/data/items/analog-adc.txt
index 2e9cb193..8bc0e914 100644
--- a/data/items/analog-adc.txt
+++ b/data/items/analog-adc.txt
@@ -1 +1 @@
-analog-adc;id;fillgauge;Сенсоры;Аналоговый;order;gol;map[0,1024,0,100];c[1]
\ No newline at end of file
+0;analog-adc;id;fillgauge;Сенсоры;Аналоговый;order;gol;map[0,1024,0,100];c[1]
\ No newline at end of file
diff --git a/data/items/bme280-hum.txt b/data/items/bme280-hum.txt
index 339c5ad6..c8afd255 100644
--- a/data/items/bme280-hum.txt
+++ b/data/items/bme280-hum.txt
@@ -1 +1 @@
-bme280-hum;id;anydataHum;Сенсоры;Влажность;order;addr[0x76];c[1]
\ No newline at end of file
+0;bme280-hum;id;anydataHum;Сенсоры;Влажность;order;addr[0x76];c[1]
\ No newline at end of file
diff --git a/data/items/bme280-press.txt b/data/items/bme280-press.txt
index 26bfcd02..f79973e2 100644
--- a/data/items/bme280-press.txt
+++ b/data/items/bme280-press.txt
@@ -1 +1 @@
-bme280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]
\ No newline at end of file
+0;bme280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]
\ No newline at end of file
diff --git a/data/items/bme280-temp.txt b/data/items/bme280-temp.txt
index 65cafaf9..6e5e9003 100644
--- a/data/items/bme280-temp.txt
+++ b/data/items/bme280-temp.txt
@@ -1 +1 @@
-bme280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1]
\ No newline at end of file
+0;bme280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1]
\ No newline at end of file
diff --git a/data/items/bmp280-press.txt b/data/items/bmp280-press.txt
index 8a7fa4a9..44b9e8c9 100644
--- a/data/items/bmp280-press.txt
+++ b/data/items/bmp280-press.txt
@@ -1 +1 @@
-bmp280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]
\ No newline at end of file
+0;bmp280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]
\ No newline at end of file
diff --git a/data/items/bmp280-temp.txt b/data/items/bmp280-temp.txt
index 2b6a275d..c3cb42eb 100644
--- a/data/items/bmp280-temp.txt
+++ b/data/items/bmp280-temp.txt
@@ -1 +1 @@
-bmp280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1]
\ No newline at end of file
+0;bmp280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1]
\ No newline at end of file
diff --git a/data/items/button-in.txt b/data/items/button-in.txt
index ada34b20..79d79ec9 100644
--- a/data/items/button-in.txt
+++ b/data/items/button-in.txt
@@ -1 +1 @@
-button-in;id;toggle;Кнопки;Освещение;order;pin;db[20]
\ No newline at end of file
+0;button-in;id;toggle;Кнопки;Освещение;order;pin;db[20]
\ No newline at end of file
diff --git a/data/items/button-out-i.txt b/data/items/button-out-i.txt
deleted file mode 100644
index c24ec540..00000000
--- a/data/items/button-out-i.txt
+++ /dev/null
@@ -1 +0,0 @@
-button-out;id;toggle;Кнопки;Освещение;order;pin;inv[1];st[1]
\ No newline at end of file
diff --git a/data/items/button-out-np.txt b/data/items/button-out-np.txt
deleted file mode 100644
index 4337b77f..00000000
--- a/data/items/button-out-np.txt
+++ /dev/null
@@ -1 +0,0 @@
-button-out;id;toggleSunMoon;Кнопки;Освещение;order;st[0]
\ No newline at end of file
diff --git a/data/items/button-out-p.txt b/data/items/button-out-p.txt
deleted file mode 100644
index d2a213fe..00000000
--- a/data/items/button-out-p.txt
+++ /dev/null
@@ -1 +0,0 @@
-button-out;id;toggle;Кнопки;Освещение;order;pin;st[0]
\ No newline at end of file
diff --git a/data/items/button-out.inv.txt b/data/items/button-out.inv.txt
new file mode 100644
index 00000000..fd3bdead
--- /dev/null
+++ b/data/items/button-out.inv.txt
@@ -0,0 +1 @@
+0;button-out;id;toggle;Кнопки;Освещение;order;pin;inv[1];st[1]
\ No newline at end of file
diff --git a/data/items/button-out.npin.txt b/data/items/button-out.npin.txt
new file mode 100644
index 00000000..380b815f
--- /dev/null
+++ b/data/items/button-out.npin.txt
@@ -0,0 +1 @@
+0;button-out;id;toggleSunMoon;Кнопки;Освещение;order;st[0]
\ No newline at end of file
diff --git a/data/items/button-out.pin.txt b/data/items/button-out.pin.txt
new file mode 100644
index 00000000..81310f4e
--- /dev/null
+++ b/data/items/button-out.pin.txt
@@ -0,0 +1 @@
+0;button-out;id;toggle;Кнопки;Освещение;order;pin;st[0]
\ No newline at end of file
diff --git a/data/items/dallas-temp.txt b/data/items/dallas-temp.txt
index e4c701ee..a6b87c28 100644
--- a/data/items/dallas-temp.txt
+++ b/data/items/dallas-temp.txt
@@ -1 +1 @@
-dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;c[1]
\ No newline at end of file
+0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;sal;c[1]
\ No newline at end of file
diff --git a/data/items/dht11-hum.txt b/data/items/dht11-hum.txt
index 697596e5..b7d9a820 100644
--- a/data/items/dht11-hum.txt
+++ b/data/items/dht11-hum.txt
@@ -1 +1 @@
-dht-hum;id;anydataHum;Сенсоры;Влажность;order;thd;type[dht11];c[1]
\ No newline at end of file
+0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;thd;type[dht11];c[1]
\ No newline at end of file
diff --git a/data/items/dht11-temp.txt b/data/items/dht11-temp.txt
index dcb5df39..39c5e949 100644
--- a/data/items/dht11-temp.txt
+++ b/data/items/dht11-temp.txt
@@ -1 +1 @@
-dht-temp;id;anydataTemp;Сенсоры;Температура;order;thd;type[dht11];c[1]
\ No newline at end of file
+0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;thd;type[dht11];c[1]
\ No newline at end of file
diff --git a/data/items/dht22-hum.txt b/data/items/dht22-hum.txt
index 9efa3d32..ab69cf97 100644
--- a/data/items/dht22-hum.txt
+++ b/data/items/dht22-hum.txt
@@ -1 +1 @@
-dht-hum;id;anydataHum;Сенсоры;Влажность;order;thd;type[dht22];c[1]
\ No newline at end of file
+0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;thd;type[dht22];c[1]
\ No newline at end of file
diff --git a/data/items/dht22-temp.txt b/data/items/dht22-temp.txt
index 149f9f67..d14a434d 100644
--- a/data/items/dht22-temp.txt
+++ b/data/items/dht22-temp.txt
@@ -1 +1 @@
-dht-temp;id;anydataTemp;Сенсоры;Температура;order;thd;type[dht22];c[1]
\ No newline at end of file
+0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;thd;type[dht22];c[1]
\ No newline at end of file
diff --git a/data/items/input-digit.txt b/data/items/input-digit.txt
index 8c3fbbe0..bfb99882 100644
--- a/data/items/input-digit.txt
+++ b/data/items/input-digit.txt
@@ -1 +1 @@
-input-digit;id;inputDigit;Ввод;Введите#цифру;order;st[60]
\ No newline at end of file
+0;input-digit;id;inputDigit;Ввод;Введите#цифру;order;st[60]
\ No newline at end of file
diff --git a/data/items/input-time.txt b/data/items/input-time.txt
index 821e29c3..46e49666 100644
--- a/data/items/input-time.txt
+++ b/data/items/input-time.txt
@@ -1 +1 @@
-input-time;id;inputTime;Ввод;Введите#время;order;st[10-00-00]
\ No newline at end of file
+0;input-time;id;inputTime;Ввод;Введите#время;order;st[10-00-00]
\ No newline at end of file
diff --git a/data/items/modbus.txt b/data/items/modbus.txt
index 8abc8d5b..a782395a 100644
--- a/data/items/modbus.txt
+++ b/data/items/modbus.txt
@@ -1 +1 @@
-modbus;id;anydata;Modbus;Регистр;order;addr[1];reg[0];c[1]
\ No newline at end of file
+0;modbus;id;anydata;Modbus;Регистр;order;addr[1];reg[0];c[1]
\ No newline at end of file
diff --git a/data/items/output-text.txt b/data/items/output-text.txt
index fbe97423..f96c2e26 100644
--- a/data/items/output-text.txt
+++ b/data/items/output-text.txt
@@ -1 +1 @@
-output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено#движение]
\ No newline at end of file
+0;output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено#движение]
\ No newline at end of file
diff --git a/data/items/pwm-out.txt b/data/items/pwm-out.txt
index b3ecac6e..39a42037 100644
--- a/data/items/pwm-out.txt
+++ b/data/items/pwm-out.txt
@@ -1 +1 @@
-pwm-out;id;range;Ползунки;Яркость;order;pin;st[500]
\ No newline at end of file
+0;pwm-out;id;range;Ползунки;Яркость;order;pin;st[500]
\ No newline at end of file
diff --git a/data/items/signs.json b/data/items/signs.json
deleted file mode 100644
index 7d140d4b..00000000
--- a/data/items/signs.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "more":">",
- "less":"<",
- "eq":"="
-}
\ No newline at end of file
diff --git a/data/items/ultrasonic-cm.txt b/data/items/ultrasonic-cm.txt
index 8792229c..cca50890 100644
--- a/data/items/ultrasonic-cm.txt
+++ b/data/items/ultrasonic-cm.txt
@@ -1 +1 @@
-ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;cin;map[0,500,0,100];c[1]
\ No newline at end of file
+0;ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;cin;map[0,500,0,100];c[1]
\ No newline at end of file
diff --git a/data/set.device.json b/data/set.device.json
index 0852a556..215b6f90 100644
--- a/data/set.device.json
+++ b/data/set.device.json
@@ -43,7 +43,7 @@
},
{
"type": "h4",
- "title": "LittleFS version: 251"
+ "title": "LittleFS version: 252"
},
{
"type": "hr"
@@ -55,10 +55,10 @@
"style": "display:inline",
"title": {
"#": "Выберите элемент из списка",
- "/set?addItem=button-out-p": "1.Кнопка управляющая пином",
- "/set?addItem=button-out-np": "2.Кнопка не привязанная к пину (виртуальная)",
+ "/set?addItem=button-out.pin": "1.Кнопка управляющая пином",
+ "/set?addItem=button-out.npin": "2.Кнопка виртуальная",
+ "/set?addItem=button-in": "4.Кнопка физическая",
"/set?addItem=pwm-out": "3.Широтно импульсная модуляция (pwm)",
- "/set?addItem=button-in": "4.Физическая кнопка (чтение состояния пина)",
"/set?addItem=input-digit": "5.Окно ввода цифровых значений",
"/set?addItem=input-time": "6.Окно ввода времени",
"/set?addItem=output-text": "7.Окно вывода любого текста, предупреждения, цифры",
@@ -83,6 +83,7 @@
{
"type": "csv",
"title": [
+ "checkbox",
"html",
"text",
"text",
@@ -98,6 +99,12 @@
{
"type": "hr"
},
+ {
+ "type": "link",
+ "title": "Удалить выбранные элементы",
+ "action": "javascript:{send_request(this,'/set?delChoosingItems');setTimeout(function(){location.href='/?set.device' ; }, 1000);}",
+ "class": "btn btn-block btn-default"
+ },
{
"type": "link",
"title": "Удалить все",
diff --git a/data/set.deviceold.json b/data/set.deviceold.json
deleted file mode 100644
index 340d21b7..00000000
--- a/data/set.deviceold.json
+++ /dev/null
@@ -1,143 +0,0 @@
-{
- "configs": [
- "/config.setup.json",
- "/config.option.json",
- "/config.live.json",
- "/lang/lang.ru.json"
- ],
- "class": "col-sm-offset-1 col-sm-10",
- "content": [
- {
- "type": "h5",
- "title": "{{name}}",
- "class": "alert-default"
- },
- {
- "type": "link",
- "title": "{{ButMainPage}}",
- "action": "/",
- "class": "btn btn-block btn-default"
- },
- {
- "type": "hr"
- },
- {
- "type": "h4",
- "title": "Device ID: {{chipID}}"
- },
- {
- "type": "h4",
- "title": "IP address: {{ip}}"
- },
- {
- "type": "h4",
- "title": "Time: {{time}}"
- },
- {
- "type": "h4",
- "title": "Uptime: {{uptime}}"
- },
- {
- "type": "h4",
- "title": "Build version: {{firmware_version}}"
- },
- {
- "type": "h4",
- "title": "LittleFS version: 2.3.5"
- },
- {
- "type": "hr"
- },
- {
- "type": "dropdown",
- "name": "help-url",
- "class": "btn btn-default",
- "style": "display:inline",
- "title": {
- "#": "{{SetDevPreset}}",
- "/set?preset=001": "1.Вкл. выкл. локального реле",
- "/set?preset=002": "2.Вкл. выкл. локального реле в определенное время",
- "/set?preset=003": "3.Вкл. выкл. локального реле на определенный период времени",
- "/set?preset=004": "4.Вкл. выкл. нескольких локальных реле кнопкой в приложении",
- "/set?preset=005": "5.Вкл. выкл. локального реле физической кнопкой и кнопкой в приложении параллельно (для выключателя света)",
- "/set?preset=006": "6.Вкл. выкл. нескольких удаленных реле кнопкой в приложении (нужно указать Device ID)",
- "/set?preset=007": "7.Вкл. выкл. нескольких удаленных реле физической кнопкой (нужно указать Device ID)",
- "/set?preset=008": "8.Широтно импульсная модуляция",
- "/set?preset=009": "9.Сенсор DHT11 (темп, влажность) и логгирование",
- "/set?preset=010": "10.Сенсор DHT22, DHT33, DHT44, AM2302, RHT03 (темп, влажность) и логгирование",
- "/set?preset=011": "11.Аналоговый сенсор и логгирование",
- "/set?preset=012": "12.Cенсор bmp280 (темп, давление) и логгирование",
- "/set?preset=013": "13.Cенсор bme280 (темп, давление, влажность, высота) и логгирование",
- "/set?preset=014": "14.Сенсор DS18B20 (темп) и логгирование",
- "/set?preset=015": "15.Термостат на DS18B20 с переключением в ручной режим и логгированием",
- "/set?preset=016": "16.Котроль уровня в баке (датчик расстояния) на сенсорах: JSN-SR04T, HC-SR04, HY-SRF05 и логгирование",
- "/set?preset=017": "17.Датчик движения включающий свет",
- "/set?preset=018": "18.Охранный датчик движения",
- "/set?preset=019": "19.Система управления шаговыми двигателями на основе драйвера A4988 (открытие закрытие штор)",
- "/set?preset=020": "20.Система управления сервоприводами",
- "/set?preset=021": "21.Модуль uart (serial). Двухстороняя связь с устройством через uart. Получение данных и отправка команд",
- "/set?preset=100": "22.Настройки по умолчанию"
- }
- },
- {
- "type": "h2",
- "title": "{{SetDevConf}}"
- },
- {
- "type": "file",
- "state": "dev_conf.txt",
- "style": "width:100%;height:350px",
- "title": "Сохранить",
- "action": "/set?devinit",
- "class": "btn btn-block btn-default"
- },
-
- {
- "type": "h2",
- "title": "Сценарии"
- },
- {
- "type": "checkbox",
- "name": "scen",
- "title": "Включить сценарии",
- "action": "/set?scen=[[scen]]",
- "state": "{{scen}}"
- },
- {
- "type": "file",
- "state": "dev_scen.txt",
- "style": "width:100%;height:350px",
- "title": "Сохранить",
- "action": "/set?sceninit",
- "class": "btn btn-block btn-default"
- },
- {
- "type": "link",
- "title": "Инструкция к системе автоматизации",
- "action": "https://github.com/DmitryBorisenko33/esp32-esp8266_iot-manager_modules_firmware/wiki/Instruction",
- "class": "btn btn-block btn-default"
- },
- {
- "type": "link",
- "title": "Очистить логи сенсоров",
- "action": "/set?cleanlog",
- "class": "btn btn-block btn-default"
- },
- {
- "type": "hr"
- },
- {
- "type": "h3",
- "name": "my-block",
- "style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
- "class": "hidden"
- },
- {
- "type": "button",
- "title": "Обновить прошивку устройства",
- "action": "/check",
- "response": "[[my-block]]",
- "class": "btn btn-block btn-default"
- }
- ]
-}
\ No newline at end of file
diff --git a/include/Consts.h b/include/Consts.h
index 78ddbc7d..ebab916a 100644
--- a/include/Consts.h
+++ b/include/Consts.h
@@ -2,7 +2,7 @@
//=================Firmeare=================
#define FIRMWARE_NAME "esp8266-iotm"
-#define FIRMWARE_VERSION 251
+#define FIRMWARE_VERSION 252
#define FLASH_4MB true
//=================System===================
@@ -87,6 +87,8 @@ enum notAsincActions {
do_MQTTUDP,
do_BUSSCAN,
do_MQTTPARAMSCHANGED,
+ do_deviceInit,
+ do_delChoosingItems,
do_LAST,
};
diff --git a/include/ItemsList.h b/include/ItemsList.h
index d973ff60..940db0b5 100644
--- a/include/ItemsList.h
+++ b/include/ItemsList.h
@@ -3,7 +3,9 @@
#include
#include "Global.h"
+extern void itemsListInit();
extern void addItem(String name);
+extern void delChoosingItems();
extern void delAllItems();
extern uint8_t getNewElementNumber(String file);
extern uint8_t getFreePinAll();
diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp
index aee15885..24d3e8bd 100644
--- a/src/BufferExecute.cpp
+++ b/src/BufferExecute.cpp
@@ -18,6 +18,7 @@ void fileCmdExecute(const String &filename) {
}
void csvCmdExecute(String &cmdStr) {
+
cmdStr.replace(";", " ");
cmdStr += "\r\n";
cmdStr.replace("\r\n", "\n");
@@ -25,6 +26,7 @@ void csvCmdExecute(String &cmdStr) {
int count = 0;
while (cmdStr.length()) {
String buf = selectToMarker(cmdStr, "\n");
+ buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса
count++;
if (count > 1) sCmd.readStr(buf);
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
diff --git a/src/ItemsList.cpp b/src/ItemsList.cpp
index 6a9d4592..3d6ad3b0 100644
--- a/src/ItemsList.cpp
+++ b/src/ItemsList.cpp
@@ -1,23 +1,51 @@
#include "ItemsList.h"
+#include "Class\NotAsinc.h"
+#include "Init.h"
#include "Utils\StringUtils.h"
-static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
+static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
+
+void itemsListInit() {
+ myNotAsincActions->add(
+ do_deviceInit, [&](void*) {
+ Device_init();
+ },
+ nullptr);
+
+ myNotAsincActions->add(
+ do_delChoosingItems, [&](void*) {
+ delChoosingItems();
+ Device_init();
+ },
+ nullptr);
+}
void addItem(String name) {
String item = readFile("items/" + name + ".txt", 1024);
- name = deleteToMarkerLast(name, "-");
+
+ name = deleteToMarkerLast(name, ".");
+
item.replace("id", name + "-" + String(getNewElementNumber("id.txt")));
item.replace("order", String(getNewElementNumber("order.txt")));
+
if (item.indexOf("pin") != -1) { //all cases (random pins from available)
item.replace("pin", "pin[" + String(getFreePinAll()) + "]");
- } else if (item.indexOf("gol") != -1) { //analog
+ } else
+
+ if (item.indexOf("gol") != -1) { //analog
item.replace("gol", "pin[" + String(getFreePinAnalog()) + "]");
- } else if (item.indexOf("cin") != -1) { //ultrasonic
+ } else
+
+ if (item.indexOf("cin") != -1) { //ultrasonic
item.replace("cin", "pin[" + String(getFreePinAll()) + "," + String(getFreePinAll()) + "]");
- } else if (item.indexOf("sal") != -1) { //dallas
+ } else
+
+ if (item.indexOf("sal") != -1) { //dallas
item.replace("sal", "pin[2]");
- } else if (item.indexOf("thd") != -1) { //dht11/22
+ } else
+
+ if (item.indexOf("thd") != -1) { //dht11/22
item.replace("thd", "pin[2]");
}
@@ -65,71 +93,28 @@ uint8_t getFreePinAnalog() {
#endif
}
-//void do_getJsonListFromCsv() {
-// if (getJsonListFromCsvFlag) {
-// getJsonListFromCsvFlag = false;
-// removeFile("items/items.json");
-// addFile("items/items.json", getJsonListFromCsv(DEVICE_CONFIG_FILE, 1));
-// }
-//}
-//
-//String getJsonListFromCsv(String csvFile, int colum) {
-// File configFile = LittleFS.open("/" + csvFile, "r");
-// if (!configFile) {
-// return "error";
-// }
-// configFile.seek(0, SeekSet);
-//
-// String outJson = "{}";
-//
-// int count = -1;
-//
-// while (configFile.position() != configFile.size()) {
-// count++;
-// String item = configFile.readStringUntil('\n');
-// if (count > 0) {
-// String line = selectFromMarkerToMarker(item, ";", colum);
-// jsonWriteStr(outJson, line, line);
-// }
-// }
-// configFile.close();
-// csvFile = "";
-// return outJson;
-//}
-//
-//void do_delElement() {
-// if (delElementFlag) {
-// delElementFlag = false;
-// delElement(itemsFile, itemsLine);
-// }
-//}
-//
-//void delElement(String _itemsFile, String _itemsLine) {
-// File configFile = LittleFS.open("/" + _itemsFile, "r");
-// if (!configFile) {
-// return;
-// }
-// configFile.seek(0, SeekSet);
-// String finalConf;
-// int count = -1;
-// while (configFile.position() != configFile.size()) {
-// count++;
-// String item = configFile.readStringUntil('\n');
-// Serial.print(_itemsLine);
-// Serial.print(" ");
-// Serial.println(count);
-// if (count != _itemsLine.toInt()) {
-// if (count == 0) {
-// finalConf += item;
-// } else {
-// finalConf += "\n" + item;
-// }
-// }
-// }
-// removeFile(_itemsFile);
-// addFile(_itemsFile, finalConf);
-// Serial.println(finalConf);
-// itemsFile = "";
-// itemsLine = "";
-// configFile.close();
-//}
\ No newline at end of file
+void delChoosingItems() {
+ File configFile = LittleFS.open("/" + String(DEVICE_CONFIG_FILE), "r");
+ if (!configFile) {
+ return;
+ }
+ configFile.seek(0, SeekSet);
+ String finalConf;
+ bool firstLine = true;
+ while (configFile.position() != configFile.size()) {
+ String item = configFile.readStringUntil('\n');
+ if (firstLine) {
+ finalConf += item;
+ } else {
+ int checkbox = selectToMarker(item, ";").toInt();
+ if (checkbox == 0) {
+ finalConf += "\n" + item;
+ }
+ }
+ firstLine = false;
+ }
+ removeFile(String(DEVICE_CONFIG_FILE));
+ addFile(String(DEVICE_CONFIG_FILE), finalConf);
+ Serial.println(finalConf);
+ configFile.close();
+}
\ No newline at end of file
diff --git a/src/Web.cpp b/src/Web.cpp
index d5db5b87..efd0fd02 100644
--- a/src/Web.cpp
+++ b/src/Web.cpp
@@ -14,30 +14,34 @@ bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
}
void web_init() {
-
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
//==============================set.device.json====================================================================================================
if (request->hasArg("addItem")) {
String name = request->getParam("addItem")->value();
addItem(name);
- //Device_init();
+ myNotAsincActions->make(do_deviceInit);
request->redirect("/?set.device");
}
+ if (request->hasArg("delChoosingItems")) {
+ myNotAsincActions->make(do_delChoosingItems);
+ request->send(200);
+ }
+
if (request->hasArg("delAllItems")) {
delAllItems();
- Device_init();
+ myNotAsincActions->make(do_deviceInit);
request->redirect("/?set.device");
}
if (request->hasArg("saveItems")) {
- Device_init();
+ myNotAsincActions->make(do_deviceInit);
request->redirect("/?set.device");
}
//==============================init====================================================================================================
if (request->hasArg("devinit")) {
- Device_init();
+ myNotAsincActions->make(do_deviceInit);
request->send(200);
}
@@ -134,6 +138,13 @@ void web_init() {
request->send(200);
}
+ if (request->hasArg("test")) {
+ if (request->getParam("test")->value() == "ok") {
+ Serial.println("test pass");
+ }
+ request->send(200);
+ }
+
//==============================mqtt settings=============================================
if (request->hasArg("mqttServer")) {
diff --git a/src/main.cpp b/src/main.cpp
index 6c761f93..c86c10b9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,11 +5,11 @@
#include "Class/CallBackTest.h"
#include "Class/NotAsinc.h"
#include "Class/ScenarioClass.h"
-#include "Utils/StatUtils.h"
#include "Cmd.h"
#include "Global.h"
#include "Init.h"
#include "ItemsList.h"
+#include "Utils/StatUtils.h"
#include "Utils/Timings.h"
#include "Utils\WebUtils.h"
#include "items/ButtonInClass.h"
@@ -18,7 +18,6 @@
void not_async_actions();
-
Timings metric;
boolean initialized = false;
@@ -36,62 +35,64 @@ void setup() {
myNotAsincActions = new NotAsinc(do_LAST);
myScenario = new Scenario();
- SerialPrint("I","FS","FS Init");
+ SerialPrint("I", "FS", "FS Init");
fileSystemInit();
- SerialPrint("I","Conf","Config Init");
+ SerialPrint("I", "Conf", "Config Init");
loadConfig();
- SerialPrint("I","Time","Clock Init");
+ SerialPrint("I", "Time", "Clock Init");
clock_init();
- SerialPrint("I","CMD","Commands Init");
+ SerialPrint("I", "CMD", "Commands Init");
cmd_init();
- SerialPrint("I","Sensors","Sensors Init");
+ SerialPrint("I", "Sensors", "Sensors Init");
sensorsInit();
- SerialPrint("I","Init","Init Init");
+ SerialPrint("I", "Items", "Items Init");
+ itemsListInit();
+
+ SerialPrint("I", "Init", "Init Init");
all_init();
- SerialPrint("I","WIFI","Network Init");
+ SerialPrint("I", "WIFI", "Network Init");
routerConnect();
- SerialPrint("I","Uptime","Uptime Init");
+ SerialPrint("I", "Uptime", "Uptime Init");
uptime_init();
- SerialPrint("I","Update","Updater Init");
+ SerialPrint("I", "Update", "Updater Init");
upgradeInit();
- SerialPrint("I","HTTP","HttpServer Init");
+ SerialPrint("I", "HTTP", "HttpServer Init");
HttpServer::init();
- SerialPrint("I","Web","WebAdmin Init");
+ SerialPrint("I", "Web", "WebAdmin Init");
web_init();
- SerialPrint("I","Stat","Stat Init");
+ SerialPrint("I", "Stat", "Stat Init");
initSt();
//SerialPrint("I","UDP","Udp Init");
//asyncUdpInit();
- SerialPrint("I","Bus","Bus Init");
+ SerialPrint("I", "Bus", "Bus Init");
busInit();
-
+
#ifdef SSDP_EN
- SerialPrint("I","SSDP","Ssdp Init");
+ SerialPrint("I", "SSDP", "Ssdp Init");
SsdpInit();
#endif
ts.add(
TEST, 1000 * 60, [&](void*) {
- SerialPrint("I","System",printMemoryStatus());
-
+ SerialPrint("I", "System", printMemoryStatus());
},
nullptr, true);
just_load = false;
- initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
+ initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
}
void loop() {