From 06df1f17b691356476dac9a79db46cb53a78359e Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Tue, 17 Nov 2020 01:01:42 +0300 Subject: [PATCH] Progress of renew of class --- data/items/input-digit.txt | 2 +- data/items/input-time.txt | 2 +- data/items/output-text.txt | 2 +- data/presets/alloff.c.txt | 2 +- data/presets/dal.c.txt | 4 +- data/presets/dht.c.txt | 4 +- data/presets/rel.c.txt | 4 +- data/set.device.json | 23 +++++++--- include/BufferExecute.h | 14 ------ include/Class/ScenarioClass3.h | 4 +- include/Consts.h | 6 ++- include/Global.h | 7 ++- include/Utils/WiFiUtils.h | 2 +- include/items/OutputTextClass.h | 23 ---------- include/items/PwmOutClass.h | 31 ------------- include/items/vButtonOut.h | 1 - include/items/vInOutput.h | 27 +++++++++++ include/items/vInput.h | 27 ----------- include/items/vLogging.h | 1 + include/items/vPwmOut.h | 29 ++++++++++++ src/BufferExecute.cpp | 12 +++-- src/Global.cpp | 7 ++- src/Init.cpp | 45 +++++++------------ src/Telegram.cpp | 2 +- src/UpgradeFirm.cpp | 31 +++++++------ src/Utils/WiFiUtils.cpp | 16 +++---- src/Web.cpp | 2 + src/items/OutputTextClass.cpp | 19 -------- src/items/PwmOutClass.cpp | 24 ---------- src/items/vButtonOut.cpp | 7 ++- src/items/{vInput.cpp => vInOutput.cpp} | 30 ++++++------- src/items/vPwmOut.cpp | 55 +++++++++++++++++++++++ src/main.cpp | 60 +++++++++++++++++-------- 33 files changed, 266 insertions(+), 259 deletions(-) delete mode 100644 include/items/OutputTextClass.h delete mode 100644 include/items/PwmOutClass.h create mode 100644 include/items/vInOutput.h delete mode 100644 include/items/vInput.h create mode 100644 include/items/vPwmOut.h delete mode 100644 src/items/OutputTextClass.cpp delete mode 100644 src/items/PwmOutClass.cpp rename src/items/{vInput.cpp => vInOutput.cpp} (59%) create mode 100644 src/items/vPwmOut.cpp diff --git a/data/items/input-digit.txt b/data/items/input-digit.txt index 65c39647..7df7260e 100644 --- a/data/items/input-digit.txt +++ b/data/items/input-digit.txt @@ -1 +1 @@ -0;input;id;inputDigit;Ввод;Введите#цифру;order \ No newline at end of file +0;inoutput;id;inputDigit;Ввод;Введите#цифру;order \ No newline at end of file diff --git a/data/items/input-time.txt b/data/items/input-time.txt index f5e69327..3fc078b0 100644 --- a/data/items/input-time.txt +++ b/data/items/input-time.txt @@ -1 +1 @@ -0;input;id;inputTime;Ввод;Введите#время;order \ No newline at end of file +0;inoutput;id;inputTime;Ввод;Введите#время;order \ No newline at end of file diff --git a/data/items/output-text.txt b/data/items/output-text.txt index 900658f7..65d45284 100644 --- a/data/items/output-text.txt +++ b/data/items/output-text.txt @@ -1 +1 @@ -0;output-text;id;anydata;Вывод;Сигнализация;order \ No newline at end of file +0;inoutput;id;anydata;Вывод;Сигнализация;order \ No newline at end of file diff --git a/data/presets/alloff.c.txt b/data/presets/alloff.c.txt index fe6b26ff..359a7a52 100644 --- a/data/presets/alloff.c.txt +++ b/data/presets/alloff.c.txt @@ -4,4 +4,4 @@ 0;button-out;button-out-4;toggle;Кнопки;Прихожая;4;pin[14] 0;pwm-out;pwm-out-5;range;Кнопки;Яркость;5;pin[15] 0;pwm-out;pwm-out-6;range;Кнопки;Яркость;6;pin[16] -0;output-text;output-text-7;anydata;Кнопки;Статус;7 \ No newline at end of file +0;inoutput;output-text-7;anydata;Кнопки;Статус;7 \ No newline at end of file diff --git a/data/presets/dal.c.txt b/data/presets/dal.c.txt index 9433d86e..abcd06dc 100644 --- a/data/presets/dal.c.txt +++ b/data/presets/dal.c.txt @@ -1,5 +1,5 @@ 0;dallas-temp;temp;anydataTemp;Термостат;Температура;1;pin[2];index[0];int[10] 0;logging;log;chart;Термостат;История;2;val[temp];int[60];cnt[100] -0;input;inputU;inputDigit;Термостат;Верхний#порог;3 -0;input;inputL;inputDigit;Термостат;Нижний#порог;4 +0;inoutput;inputU;inputDigit;Термостат;Верхний#порог;3 +0;inoutput;inputL;inputDigit;Термостат;Нижний#порог;4 0;button-out;button;toggle;Термостат;Нагрев;5;pin[12] \ No newline at end of file diff --git a/data/presets/dht.c.txt b/data/presets/dht.c.txt index 29195c1c..fb2c602b 100644 --- a/data/presets/dht.c.txt +++ b/data/presets/dht.c.txt @@ -1,5 +1,5 @@ 0;dht-hum;hum;anydataHum;Теплица;Влажность;1;pin[2];type[dht11];c[1] 0;logging;log;chart;Теплица;История;2;val[hum];int[60];cnt[100] -0;input;inputU;inputDigit;Теплица;Верхний#порог;3 -0;input;inputL;inputDigit;Теплица;Нижний#порог;4 +0;inoutput;inputU;inputDigit;Теплица;Верхний#порог;3 +0;inoutput;inputL;inputDigit;Теплица;Нижний#порог;4 0;button-out;button;toggle;Теплица;Полив;5;pin[12] \ No newline at end of file diff --git a/data/presets/rel.c.txt b/data/presets/rel.c.txt index faf94758..3f1ccaa1 100644 --- a/data/presets/rel.c.txt +++ b/data/presets/rel.c.txt @@ -1,4 +1,4 @@ 0;button-out;button1;toggle;Реле;Освещение;1;pin[12] 0;button-out;button2;toggle;Реле;Освещение;2;pin[13] -0;input;T1;inputTime;Реле;Введите#время#включения;3 -0;input;T2;inputTime;Реле;Введите#время#выключения;4 \ No newline at end of file +0;inoutput;T1;inputTime;Реле;Введите#время#включения;3 +0;inoutput;T2;inputTime;Реле;Введите#время#выключения;4 \ No newline at end of file diff --git a/data/set.device.json b/data/set.device.json index 8eb0b1e3..7c02e45e 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -23,15 +23,15 @@ }, { "type": "h4", - "title": "Device ID: {{chipID}}" + "title": "ID устройства: {{chipID}}" }, { "type": "h4", - "title": "IP address: {{ip}}" + "title": "IP адрес: {{ip}}" }, { "type": "h4", - "title": "Time: {{timenow}}" + "title": "Время: {{timenow}}" }, { "type": "h4", @@ -39,15 +39,26 @@ }, { "type": "h4", - "title": "WiFi Signal: {{signal}}" + "title": "Версия прошивки: {{firmware_version}}" }, { "type": "h4", - "title": "Build version: {{firmware_version}}" + "title": "Версия файловой системы: 267" }, { "type": "h4", - "title": "LittleFS version: 267" + "title": "{{signal}}" + }, + { + "type": "hr" + }, + { + "type": "text", + "title": "{{warning1}}" + }, + { + "type": "text", + "title": "{{warning2}}" }, { "type": "hr" diff --git a/include/BufferExecute.h b/include/BufferExecute.h index e77d36db..99a1ab26 100644 --- a/include/BufferExecute.h +++ b/include/BufferExecute.h @@ -9,21 +9,9 @@ extern void loopCmdExecute(); extern void addKey(String& key, String& keyNumberTable, int number); extern int getKeyNum(String& key, String& keyNumberTable); -extern void pwmOut(); -extern void pwmOutSet(); - extern void buttonIn(); extern void buttonInSet(); -extern void input(); -extern void inputDigitSet(); - -extern void inputTime(); -extern void inputTimeSet(); - -extern void textOut(); -extern void textOutSet(); - extern void analogAdc(); extern void analogReading(); @@ -56,6 +44,4 @@ extern void bmp280ReadingPress(); extern void sysUptime(); extern void uptimeReading(); -extern void logging(); - extern void impuls(); diff --git a/include/Class/ScenarioClass3.h b/include/Class/ScenarioClass3.h index 3bedf2bc..f49dcea4 100644 --- a/include/Class/ScenarioClass3.h +++ b/include/Class/ScenarioClass3.h @@ -8,7 +8,9 @@ class Scenario { public: void loop() { - + if (!jsonReadBool(configSetupJson, "scen")) { + return; + } String allBlocks = scenario; allBlocks.replace("\r\n", "\n"); allBlocks.replace("\r", "\n"); diff --git a/include/Consts.h b/include/Consts.h index 4e65e5e3..6fed021f 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -117,4 +117,8 @@ enum ConfigType_t { //15.11.2020 (SSDP OFF, UDP OFF) //RAM: [===== ] 46.1% (used 37780 bytes from 81920 bytes) -//Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes) \ No newline at end of file +//Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes) + +//17.11.2020 (SSDP OFF, UDP OFF) +//RAM: [===== ] 45.7% (used 37476 bytes from 81920 bytes) +//Flash: [===== ] 54.5% (used 569296 bytes from 1044464 bytes) \ No newline at end of file diff --git a/include/Global.h b/include/Global.h index d00d8266..b44cb8d7 100644 --- a/include/Global.h +++ b/include/Global.h @@ -75,8 +75,11 @@ extern int impuls_EnterCounter; extern String buttonOut_KeyList; extern int buttonOut_EnterCounter; //========================================= -extern String input_KeyList; -extern int input_EnterCounter; +extern String inOutput_KeyList; +extern int inOutput_EnterCounter; +//========================================= +extern String pwmOut_KeyList; +extern int pwmOut_EnterCounter; //========================================= // Sensors diff --git a/include/Utils/WiFiUtils.h b/include/Utils/WiFiUtils.h index 60ed3e7b..a6dbcc34 100644 --- a/include/Utils/WiFiUtils.h +++ b/include/Utils/WiFiUtils.h @@ -10,5 +10,5 @@ bool startAPMode(); boolean RouterFind(String ssid); -String RSSIquality(); +uint8_t RSSIquality(); diff --git a/include/items/OutputTextClass.h b/include/items/OutputTextClass.h deleted file mode 100644 index 8e3867ba..00000000 --- a/include/items/OutputTextClass.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include -#include "Class/LineParsing.h" -#include "Global.h" - -class OutputTextClass : public LineParsing { - public: - OutputTextClass() : LineParsing(){}; - - void OutputModuleStateSetDefault() { - if (_state != "") { - OutputModuleChange(_key, _state); - } - } - - void OutputModuleChange(String key, String state) { - state.replace("#", " "); - eventGen2(key, state); - jsonWriteStr(configLiveJson, key, state); - publishStatus(key, state); - } -}; -extern OutputTextClass myOutputText; \ No newline at end of file diff --git a/include/items/PwmOutClass.h b/include/items/PwmOutClass.h deleted file mode 100644 index bd6570ba..00000000 --- a/include/items/PwmOutClass.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include -#include "Class/LineParsing.h" -#include "Global.h" - -class PwmOutClass : public LineParsing { - public: - PwmOutClass() : LineParsing(){}; - - void pwmModeSet() { - if (_pin != "") { - pinMode(_pin.toInt(), INPUT); - } - } - - void pwmStateSetDefault() { - if (_state != "") { - pwmChange(_key, _pin, _state); - } - } - - void pwmChange(String key, String pin, String state) { - int pinInt = pin.toInt(); - analogWrite(pinInt, state.toInt()); - eventGen2(key, state); - jsonWriteInt(configLiveJson, key, state.toInt()); - publishStatus(key, state); - } -}; - -extern PwmOutClass myPwmOut; \ No newline at end of file diff --git a/include/items/vButtonOut.h b/include/items/vButtonOut.h index bf918f8c..3568b516 100644 --- a/include/items/vButtonOut.h +++ b/include/items/vButtonOut.h @@ -22,7 +22,6 @@ class ButtonOut { boolean _inv; String _key; - void addNewDelOldData(const String filename, size_t maxPoints, String payload); }; extern MyButtonOutVector* myButtonOut; diff --git a/include/items/vInOutput.h b/include/items/vInOutput.h new file mode 100644 index 00000000..99fe4636 --- /dev/null +++ b/include/items/vInOutput.h @@ -0,0 +1,27 @@ +#pragma once +#include + +#include "Global.h" + +class InOutput; + +typedef std::vector MyInOutputVector; + +class InOutput { + public: + + InOutput(String key, String widget); + ~InOutput(); + + void execute(String value); + + private: + + String _key; + +}; + +extern MyInOutputVector* myInOutput; + +extern void inOutput(); +extern void inOutputExecute(); diff --git a/include/items/vInput.h b/include/items/vInput.h deleted file mode 100644 index 52a6c80b..00000000 --- a/include/items/vInput.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include - -#include "Global.h" - -class Input; - -typedef std::vector MyInputVector; - -class Input { - public: - - Input(String key, String widget); - ~Input(); - - void execute(String value); - - private: - - String _key; - -}; - -extern MyInputVector* myInput; - -extern void input(); -extern void inputExecute(); diff --git a/include/items/vLogging.h b/include/items/vLogging.h index 1fb3f09c..d1060334 100644 --- a/include/items/vLogging.h +++ b/include/items/vLogging.h @@ -29,6 +29,7 @@ class LoggingClass { extern MyLoggingVector* myLogging; +extern void logging(); extern void choose_log_date_and_send(); extern void sendLogData(String file, String topic); extern void cleanLogAndData(); diff --git a/include/items/vPwmOut.h b/include/items/vPwmOut.h new file mode 100644 index 00000000..2b9ba669 --- /dev/null +++ b/include/items/vPwmOut.h @@ -0,0 +1,29 @@ +#pragma once +#include + +#include "Global.h" + +class PwmOut; + +typedef std::vector MyPwmOutVector; + +class PwmOut { + public: + + PwmOut(unsigned int pin, String key); + + ~PwmOut(); + + void execute(String state); + + private: + + unsigned int _pin; + String _key; + +}; + +extern MyPwmOutVector* myPwmOut; + +extern void pwmOut(); +extern void pwmOutExecute(); diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index db55a09c..893119b2 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -3,8 +3,9 @@ // #include "items/vSensorDallas.h" #include "items/vButtonOut.h" - - +#include "items/vPwmOut.h" +#include "items/vInOutput.h" +#include "items/vLogging.h" void loopCmdAdd(const String& cmdStr) { orderBuf += cmdStr; @@ -43,11 +44,8 @@ void csvCmdExecute(String& cmdStr) { else if (order == F("button-in")) { sCmd.addCommand(order.c_str(), buttonIn); } - else if (order == F("input")) { - sCmd.addCommand(order.c_str(), input); - } - else if (order == F("output-text")) { - sCmd.addCommand(order.c_str(), textOut); + else if (order == F("inoutput")) { + sCmd.addCommand(order.c_str(), inOutput); } else if (order == F("analog-adc")) { sCmd.addCommand(order.c_str(), analogAdc); diff --git a/src/Global.cpp b/src/Global.cpp index 9b41fb67..96f9c7de 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -46,8 +46,11 @@ int impuls_EnterCounter = -1; String buttonOut_KeyList = ""; int buttonOut_EnterCounter = -1; //========================================= -String input_KeyList = ""; -int input_EnterCounter = -1; +String inOutput_KeyList = ""; +int inOutput_EnterCounter = -1; +//========================================= +String pwmOut_KeyList = ""; +int pwmOut_EnterCounter = -1; //========================================= // Sensors diff --git a/src/Init.cpp b/src/Init.cpp index 08969c88..7972db73 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -6,7 +6,8 @@ #include "items/vImpulsOut.h" #include "items/vButtonOut.h" #include "items/vSensorDallas.h" -#include "items/vInput.h" +#include "items/vInOutput.h" +#include "items/vPwmOut.h" void loadConfig() { configSetupJson = readFile("config.json", 4096); @@ -15,6 +16,9 @@ void loadConfig() { configStoreJson = readFile("store.json", 4096); configStoreJson.replace("\r\n", ""); + jsonWriteStr(configSetupJson, "warning1", ""); + jsonWriteStr(configSetupJson, "warning2", ""); + jsonWriteStr(configSetupJson, "chipID", chipId); jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION); @@ -57,11 +61,17 @@ void Device_init() { buttonOut_KeyList = ""; buttonOut_EnterCounter = -1; //======clear input params======= - if (myInput != nullptr) { - myInput->clear(); + if (myInOutput != nullptr) { + myInOutput->clear(); } - input_KeyList = ""; - input_EnterCounter = -1; + inOutput_KeyList = ""; + inOutput_EnterCounter = -1; + //======clear pwm params======= + if (myPwmOut != nullptr) { + myPwmOut->clear(); + } + pwmOut_KeyList = ""; + pwmOut_EnterCounter = -1; //=================================== @@ -94,28 +104,3 @@ void handle_uptime() { jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime()); } -//void handle_statistics() { -// if (isNetworkActive()) { -// String urls = "http://backup.privet.lv/visitors/?"; -// //----------------------------------------------------------------- -// urls += WiFi.macAddress().c_str(); -// urls += "&"; -// //----------------------------------------------------------------- -//#ifdef ESP8266 -// urls += "iot-manager_esp8266"; -//#endif -//#ifdef ESP32 -// urls += "iot-manager_esp32"; -//#endif -// urls += "&"; -//#ifdef ESP8266 -// urls += ESP.getResetReason(); -//#endif -//#ifdef ESP32 -// urls += "Power on"; -//#endif -// urls += "&"; -// urls += String(FIRMWARE_VERSION); -// String stat = getURL(urls); -// } -//} \ No newline at end of file diff --git a/src/Telegram.cpp b/src/Telegram.cpp index 89425e5a..a26ca23e 100644 --- a/src/Telegram.cpp +++ b/src/Telegram.cpp @@ -61,7 +61,7 @@ void telegramMsgParse(String msg) { SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + "\n" + list); } else { - myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value"); + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), F("Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value")); } } diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index f5670d23..4a8889ad 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -26,23 +26,28 @@ void upgradeInit() { getLastVersion(); if (lastVersion > 0) { SerialPrint("I", "Update", "available version: " + String(lastVersion)); + if (lastVersion > FIRMWARE_VERSION) { + jsonWriteStr(configSetupJson, "warning2", F("

Вышла новая версия прошивки, нажмите обновить прошивку

")); + } } }; } void getLastVersion() { if ((WiFi.status() == WL_CONNECTED)) { - #ifdef ESP8266 - String tmp = getURL( serverIP + F("/projects/iotmanager/esp8266/esp8266ver/esp8266ver.txt")); - #else - String tmp = getURL( serverIP + F("/projects/iotmanager/esp32/esp32ver/esp32ver.txt")); - #endif +#ifdef ESP8266 + String tmp = getURL(serverIP + F("/projects/iotmanager/esp8266/esp8266ver/esp8266ver.txt")); +#else + String tmp = getURL(serverIP + F("/projects/iotmanager/esp32/esp32ver/esp32ver.txt")); +#endif if (tmp == "error") { lastVersion = -1; - } else { + } + else { lastVersion = tmp.toInt(); } - } else { +} + else { lastVersion = -2; } jsonWriteInt(configSetupJson, "last_version", lastVersion); @@ -89,15 +94,15 @@ bool upgradeFS() { Serial.println("Start upgrade LittleFS, please wait..."); #ifdef ESP8266 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/littlefs/littlefs.bin")); #else 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 if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно SerialPrint("I", "Update", "LittleFS upgrade done!"); ret = true; - } +} return ret; } @@ -108,16 +113,16 @@ bool upgradeBuild() { #ifdef ESP8266 ESPhttpUpdate.rebootOnUpdate(false); - t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp8266/firmware/firmware.bin")); + t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp8266/firmware/firmware.bin")); #else httpUpdate.rebootOnUpdate(false); - HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp32/firmware/firmware.bin")); + HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp32/firmware/firmware.bin")); #endif if (retBuild == HTTP_UPDATE_OK) { //если BUILD обновился успешно SerialPrint("I", "Update", "BUILD upgrade done!"); ret = true; - } +} return ret; } diff --git a/src/Utils/WiFiUtils.cpp b/src/Utils/WiFiUtils.cpp index cac571c4..5b163c93 100644 --- a/src/Utils/WiFiUtils.cpp +++ b/src/Utils/WiFiUtils.cpp @@ -111,27 +111,27 @@ boolean isNetworkActive() { return WiFi.status() == WL_CONNECTED; } -String RSSIquality() { - String res = "not connected"; +uint8_t RSSIquality() { + uint8_t res = 0; if (WiFi.status() == WL_CONNECTED) { int rssi = WiFi.RSSI(); if (rssi >= -50) { - res = "Excellent"; + res = 6; //"Excellent"; } else if (rssi < -50 && rssi >= -60) { - res = "Very good"; + res = 5; //"Very good"; } else if (rssi < -60 && rssi >= -70) { - res = "Good"; + res = 4; //"Good"; } else if (rssi < -70 && rssi >= -80) { - res = "Low"; + res = 3; //"Low"; } else if (rssi < -80 && rssi > -100) { - res = "Very low"; + res = 2; //"Very low"; } else if (rssi <= -100) { - res = "No signal"; + res = 1; //"No signal"; } } return res; diff --git a/src/Web.cpp b/src/Web.cpp index 3c30b59d..c77e1266 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -30,6 +30,7 @@ void web_init() { } if (request->hasArg("delChoosingItems")) { + jsonWriteStr(configSetupJson, "warning1", F("

Требуется перезагрузка

")); myNotAsyncActions->make(do_delChoosingItems); request->send(200); } @@ -37,6 +38,7 @@ void web_init() { if (request->hasArg("delAllItems")) { delAllItems(); cleanLogAndData(); + jsonWriteStr(configSetupJson, "warning1", F("

Требуется перезагрузка

")); request->redirect("/?set.device"); } diff --git a/src/items/OutputTextClass.cpp b/src/items/OutputTextClass.cpp deleted file mode 100644 index f86de77d..00000000 --- a/src/items/OutputTextClass.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "BufferExecute.h" -#include "items/OutputTextClass.h" -//===============================================Модуль вывода текста============================================ -//output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено.движение] -//=============================================================================================================== -OutputTextClass myOutputText; -void textOut() { - myOutputText.update(); - String key = myOutputText.gkey(); - sCmd.addCommand(key.c_str(), textOutSet); - myOutputText.OutputModuleStateSetDefault(); - myOutputText.clear(); -} - -void textOutSet() { - String key = sCmd.order(); - String state = sCmd.next(); - myOutputText.OutputModuleChange(key, state); -} \ No newline at end of file diff --git a/src/items/PwmOutClass.cpp b/src/items/PwmOutClass.cpp deleted file mode 100644 index 44ece25c..00000000 --- a/src/items/PwmOutClass.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "BufferExecute.h" -#include "items/PwmOutClass.h" -//==========================================Модуль управления ШИМ=================================================== -//pwm-out volume range Кнопки Свет 1 pin[12] st[500] -//================================================================================================================== -PwmOutClass myPwmOut; -void pwmOut() { - myPwmOut.update(); - String key = myPwmOut.gkey(); - String pin = myPwmOut.gpin(); - String inv = myPwmOut.ginv(); - sCmd.addCommand(key.c_str(), pwmOutSet); - jsonWriteStr(configOptionJson, key + "_pin", pin); - myPwmOut.pwmModeSet(); - myPwmOut.pwmStateSetDefault(); - myPwmOut.clear(); -} - -void pwmOutSet() { - String key = sCmd.order(); - String state = sCmd.next(); - String pin = jsonReadStr(configOptionJson, key + "_pin"); - myPwmOut.pwmChange(key, pin, state); -} \ No newline at end of file diff --git a/src/items/vButtonOut.cpp b/src/items/vButtonOut.cpp index a45b7c9f..15790687 100644 --- a/src/items/vButtonOut.cpp +++ b/src/items/vButtonOut.cpp @@ -1,11 +1,10 @@ #include "items/vButtonOut.h" - -#include - #include "Class/LineParsing.h" #include "Global.h" #include "BufferExecute.h" -//this class save date to flash + +#include +//this class save data to flash ButtonOut::ButtonOut(unsigned int pin, boolean inv, String key) { _pin = pin; _inv = inv; diff --git a/src/items/vInput.cpp b/src/items/vInOutput.cpp similarity index 59% rename from src/items/vInput.cpp rename to src/items/vInOutput.cpp index 76589d94..c842ac62 100644 --- a/src/items/vInput.cpp +++ b/src/items/vInOutput.cpp @@ -1,4 +1,4 @@ -#include "items/vInput.h" +#include "items/vInOutput.h" #include @@ -6,7 +6,7 @@ #include "Global.h" #include "BufferExecute.h" //this class save date to flash -Input::Input(String key, String widget) { +InOutput::InOutput(String key, String widget) { _key = key; String value = jsonReadStr(configStoreJson, key); @@ -21,43 +21,43 @@ Input::Input(String key, String widget) { this->execute(value); } -Input::~Input() {} +InOutput::~InOutput() {} -void Input::execute(String value) { +void InOutput::execute(String value) { eventGen2(_key, value); jsonWriteStr(configStoreJson, _key, value); saveStore(); publishStatus(_key, value); } -MyInputVector* myInput = nullptr; +MyInOutputVector* myInOutput = nullptr; -void input() { +void inOutput() { myLineParsing.update(); String widget = myLineParsing.gfile(); String key = myLineParsing.gkey(); myLineParsing.clear(); - input_EnterCounter++; - addKey(key, input_KeyList, input_EnterCounter); + inOutput_EnterCounter++; + addKey(key, inOutput_KeyList, inOutput_EnterCounter); static bool firstTime = true; - if (firstTime) myInput = new MyInputVector(); + if (firstTime) myInOutput = new MyInOutputVector(); firstTime = false; - myInput->push_back(Input(key, widget)); + myInOutput->push_back(InOutput(key, widget)); - sCmd.addCommand(key.c_str(), inputExecute); + sCmd.addCommand(key.c_str(), inOutputExecute); } -void inputExecute() { +void inOutputExecute() { String key = sCmd.order(); String value = sCmd.next(); - int number = getKeyNum(key, input_KeyList); + int number = getKeyNum(key, inOutput_KeyList); - if (myInput != nullptr) { + if (myInOutput != nullptr) { if (number != -1) { - myInput->at(number).execute(value); + myInOutput->at(number).execute(value); } } } diff --git a/src/items/vPwmOut.cpp b/src/items/vPwmOut.cpp new file mode 100644 index 00000000..f2346c27 --- /dev/null +++ b/src/items/vPwmOut.cpp @@ -0,0 +1,55 @@ +#include "items/vPwmOut.h" +#include "Class/LineParsing.h" +#include "Global.h" +#include "BufferExecute.h" + +#include +//this class save data to flash +PwmOut::PwmOut(unsigned int pin, String key) { + _pin = pin; + _key = key; + pinMode(_pin, OUTPUT); + int state = jsonReadInt(configStoreJson, key); + this->execute(String(state)); +} +PwmOut::~PwmOut() {} + +void PwmOut::execute(String state) { + analogWrite(_pin, state.toInt()); + eventGen2(_key, state); + jsonWriteInt(configStoreJson, _key, state.toInt()); + saveStore(); + publishStatus(_key, state); +} + +MyPwmOutVector* myPwmOut = nullptr; + +void pwmOut() { + myLineParsing.update(); + String key = myLineParsing.gkey(); + String pin = myLineParsing.gpin(); + myLineParsing.clear(); + + pwmOut_EnterCounter++; + addKey(key, pwmOut_KeyList, pwmOut_EnterCounter); + + static bool firstTime = true; + if (firstTime) myPwmOut = new MyPwmOutVector(); + firstTime = false; + myPwmOut->push_back(PwmOut(pin.toInt(), key)); + + sCmd.addCommand(key.c_str(), pwmOutExecute); +} + +void pwmOutExecute() { + String key = sCmd.order(); + String state = sCmd.next(); + + int number = getKeyNum(key, pwmOut_KeyList); + + if (myPwmOut != nullptr) { + if (number != -1) { + myPwmOut->at(number).execute(state); + } + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 64165406..7b4e9b07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ void setup() { Serial.begin(115200); Serial.flush(); Serial.println(); - Serial.println("--------------started----------------"); + Serial.println(F("--------------started----------------")); setChipId(); @@ -40,57 +40,57 @@ void setup() { myScenario = new Scenario(); fileSystemInit(); - SerialPrint("I", "FS", "FS Init"); + SerialPrint("I", F("FS"), F("FS Init")); loadConfig(); - SerialPrint("I", "Conf", "Config Init"); + SerialPrint("I", F("Conf"), F("Config Init")); clock_init(); - SerialPrint("I", "Time", "Clock Init"); + SerialPrint("I", F("Time"), F("Clock Init")); handle_time_init(); - SerialPrint("I", "Time", "Handle time init("); + SerialPrint("I", F("Time"), F("Handle time init")); sensorsInit(); - SerialPrint("I", "Sensors", "Sensors Init"); + SerialPrint("I", F("Sensors"), F("Sensors Init")); itemsListInit(); - SerialPrint("I", "Items", "Items Init"); + SerialPrint("I", F("Items"), F("Items Init")); all_init(); - SerialPrint("I", "Init", "Init Init"); + SerialPrint("I", F("Init"), F("Init Init")); routerConnect(); - SerialPrint("I", "WIFI", "Network Init"); + SerialPrint("I", F("WIFI"), F("Network Init")); telegramInit(); - SerialPrint("I", "Telegram", "Telegram Init"); + SerialPrint("I", F("Telegram"), F("Telegram Init")); uptime_init(); - SerialPrint("I", "Uptime", "Uptime Init"); + SerialPrint("I", F("Uptime"), F("Uptime Init")); upgradeInit(); - SerialPrint("I", "Update", "Updater Init"); + SerialPrint("I", F("Update"), F("Updater Init")); HttpServer::init(); - SerialPrint("I", "HTTP", "HttpServer Init"); + SerialPrint("I", F("HTTP"), F("HttpServer Init")); web_init(); - SerialPrint("I", "Web", "WebAdmin Init"); + SerialPrint("I", F("Web"), F("WebAdmin Init")); initSt(); - SerialPrint("I", "Stat", "Stat Init"); + SerialPrint("I", F("Stat"), F("Stat Init")); #ifdef UDP_ENABLED - SerialPrint("I", "UDP", "Udp Init"); + SerialPrint("I", F("UDP"), "Udp Init"); asyncUdpInit(); #endif - SerialPrint("I", "Bus", "Bus Init"); + SerialPrint("I", F("Bus"), F("Bus Init")); busInit(); #ifdef SSDP_ENABLED - SerialPrint("I", "SSDP", "Ssdp Init"); + SerialPrint("I", F("SSDP"), F("Ssdp Init")); SsdpInit(); #endif @@ -99,7 +99,29 @@ void setup() { ts.add( TEST, 1000 * 60, [&](void*) { SerialPrint("I", "System", printMemoryStatus()); - jsonWriteStr(configSetupJson, "signal", RSSIquality()); + switch (RSSIquality()) { + case 0: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: не подключено к роутеру")); + break; + case 1: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: нет сигнала")); + break; + case 2: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: очень низкий")); + break; + case 3: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: низкий")); + break; + case 4: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: хороший")); + break; + case 5: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: очень хороший")); + break; + case 6: + jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: отличный")); + break; + } }, nullptr, true);