From 93dfa8ee834c7f8f56a3e609c36f551f7bdd2111 Mon Sep 17 00:00:00 2001 From: DmitriyTychina Date: Sun, 3 Sep 2023 19:33:40 +0300 Subject: [PATCH 01/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20=D0=B2=D0=B5=D0=B7=D0=B4=D0=B5=20isN?= =?UTF-8?q?etworkActive()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MqttClient.cpp | 2 +- src/modules/exec/HttpGet/HttpGet.cpp | 2 +- src/modules/exec/TelegramLT/TelegramLT.cpp | 2 +- src/modules/virtual/GoogleSheet/GoogleSheet.cpp | 4 ++-- src/modules/virtual/Weather/Weather.cpp | 2 +- src/utils/Statistic.cpp | 2 +- src/utils/WiFiUtils.cpp | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 4324e7c1..53e2fa5a 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -5,7 +5,7 @@ void mqttInit() { ts.add( WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL, [&](void*) { - if (WiFi.status() == WL_CONNECTED) { + if (isNetworkActive()) { SerialPrint("i", F("WIFI"), "http://" + jsonReadStr(settingsFlashJson, F("ip"))); wifiUptimeCalc(); if (mqtt.connected()) { diff --git a/src/modules/exec/HttpGet/HttpGet.cpp b/src/modules/exec/HttpGet/HttpGet.cpp index 8c53c10c..180d9099 100644 --- a/src/modules/exec/HttpGet/HttpGet.cpp +++ b/src/modules/exec/HttpGet/HttpGet.cpp @@ -10,7 +10,7 @@ public: void sendHttpPOST(String url, String msg) { - if (WiFi.status() == WL_CONNECTED) + if (isNetworkActive()) { WiFiClient client; diff --git a/src/modules/exec/TelegramLT/TelegramLT.cpp b/src/modules/exec/TelegramLT/TelegramLT.cpp index 2fb3c14a..eee738e0 100644 --- a/src/modules/exec/TelegramLT/TelegramLT.cpp +++ b/src/modules/exec/TelegramLT/TelegramLT.cpp @@ -13,7 +13,7 @@ class TelegramLT : public IoTItem { } void sendTelegramMsg(bool often, String msg) { - if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg)) { + if (isNetworkActive() && (often || !often && _prevMsg != msg)) { WiFiClient client; HTTPClient http; http.begin(client, "http://live-control.com/iotm/telegram.php"); diff --git a/src/modules/virtual/GoogleSheet/GoogleSheet.cpp b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp index 173cfe13..e04b468e 100644 --- a/src/modules/virtual/GoogleSheet/GoogleSheet.cpp +++ b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp @@ -31,7 +31,7 @@ public: void doByInterval() { - if (WiFi.status() == WL_CONNECTED) + if (isNetworkActive()) { String value = getItemValue(logid); if (value != "") @@ -55,7 +55,7 @@ public: IoTValue execute(String command, std::vector ¶m) { - if (WiFi.status() == WL_CONNECTED) + if (isNetworkActive()) { if (command == F("logGoogle")) { // Логирование определенного элемента по его идентификатору в GoogleSheet diff --git a/src/modules/virtual/Weather/Weather.cpp b/src/modules/virtual/Weather/Weather.cpp index 2ff85df4..2e39d8c7 100644 --- a/src/modules/virtual/Weather/Weather.cpp +++ b/src/modules/virtual/Weather/Weather.cpp @@ -26,7 +26,7 @@ public: { String ret; - if (WiFi.status() == WL_CONNECTED) + if (isNetworkActive()) { // char c; String payload; diff --git a/src/utils/Statistic.cpp b/src/utils/Statistic.cpp index 621e1de5..88f4f1e1 100644 --- a/src/utils/Statistic.cpp +++ b/src/utils/Statistic.cpp @@ -20,7 +20,7 @@ void updateDeviceStatus() { // jsonRead(settingsFlashJson, F("serverip"), serverIP); String url = serverIP + F("/projects/esprebootstat.php"); // SerialPrint("i", "Stat", "url " + url); - if ((WiFi.status() == WL_CONNECTED)) { + if ((isNetworkActive())) { WiFiClient client; HTTPClient http; http.begin(client, url); diff --git a/src/utils/WiFiUtils.cpp b/src/utils/WiFiUtils.cpp index 681d2c8a..00de872a 100644 --- a/src/utils/WiFiUtils.cpp +++ b/src/utils/WiFiUtils.cpp @@ -121,7 +121,7 @@ boolean RouterFind(String ssid) { uint8_t RSSIquality() { uint8_t res = 0; - if (WiFi.status() == WL_CONNECTED) { + if (isNetworkActive()) { int rssi = WiFi.RSSI(); if (rssi >= -50) { res = 6; //"Excellent"; From fbe7b1cf02c1837579ce949f6111f955efcf3764 Mon Sep 17 00:00:00 2001 From: DmitriyTychina Date: Tue, 5 Sep 2023 00:20:03 +0300 Subject: [PATCH 02/19] =?UTF-8?q?pulse()=20=D0=B2=20ButtonOut,=20+=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=87=D0=B8=D0=B5=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTItem.h | 11 +++--- src/Main.cpp | 4 +-- src/classes/IoTItem.cpp | 24 ++++++++----- .../display/NextionUpload/NextionUpload.cpp | 11 +++--- src/modules/exec/ButtonOut/ButtonOut.cpp | 36 ++++++++++++++----- src/modules/exec/ButtonOut/modinfo.json | 5 +++ src/modules/exec/Buzzer/Buzzer.cpp | 11 +----- src/modules/exec/MySensors/MySensorsGate.cpp | 5 +++ src/modules/exec/Thermostat/Thermostat.cpp | 5 +++ src/modules/sensors/AnalogAdc/AnalogAdc.cpp | 8 +---- .../sensors/ExampleModule/ExampleModule.cpp | 8 +---- src/modules/sensors/Sds011/Sds011.cpp | 21 +++++------ .../virtual/GoogleSheet/GoogleSheet.cpp | 35 +++++++++--------- src/modules/virtual/Loging/Loging.cpp | 31 ++++++++-------- .../virtual/LogingDaily/LogingDaily.cpp | 27 +++++++------- src/modules/virtual/Weather/Weather.cpp | 35 +++++++++--------- 16 files changed, 157 insertions(+), 120 deletions(-) diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index 772a3052..d727a9a1 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -11,7 +11,7 @@ struct IoTValue { class IoTItem { public: IoTItem(const String& parameters); - virtual ~IoTItem() {} + virtual ~IoTItem() {}; virtual void loop(); virtual void doByInterval(); virtual IoTValue execute(String command, std::vector& param); @@ -35,9 +35,12 @@ class IoTItem { void setInterval(long interval); void setIntFromNet(int interval); - unsigned long currentMillis; - unsigned long prevMillis; - unsigned long difference; + // unsigned long currentMillis; + // unsigned long prevMillis; + // unsigned long difference; + unsigned long nextMillis=0; // достаточно 1 переменной, надо экономить память + // задержка следующего вызова, не изменяет текущий _interval + void suspendNextDoByInt(unsigned long _delay); // 0 - force IoTValue value; // хранение основного значения, которое обновляется из сценария, execute(), loop() или doByInterval() diff --git a/src/Main.cpp b/src/Main.cpp index fccafe59..140332aa 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -10,8 +10,8 @@ IoTScenario iotScen; // объект управления сценарием String volStrForSave = ""; -unsigned long currentMillis; -unsigned long prevMillis; +// unsigned long currentMillis; // это сдесь лишнее +// unsigned long prevMillis; void elementsLoop() { // передаем управление каждому элементу конфигурации для выполнения своих функций diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 28557848..50678390 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -7,9 +7,7 @@ IoTItem::IoTItem(const String& parameters) { jsonRead(parameters, F("int"), _interval, false); - if (_interval == 0) enableDoByInt = false; // выключаем использование периодического выполнения в модуле - if (_interval > 0) _interval = _interval * 1000; // если int положителен, то считаем, что получены секунды - if (_interval < 0) _interval = _interval * -1; // если int отрицательный, то миллисекунды + setInterval(_interval); jsonRead(parameters, F("subtype"), _subtype, false); jsonRead(parameters, F("id"), _id); if (!jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1; @@ -38,12 +36,16 @@ IoTItem::IoTItem(const String& parameters) { setValue(valAsStr, false); } +void IoTItem::suspendNextDoByInt(unsigned long _delay) { // 0 - force + nextMillis = millis() + _delay; +} + void IoTItem::loop() { if (enableDoByInt) { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= _interval) { - prevMillis = millis(); + unsigned long currentMillis = millis(); // _interval должен быть < 2147483647 мс (24 суток) + if (nextMillis - currentMillis > 2147483647UL /*ULONG_MAX/2*/ ) { + nextMillis = currentMillis + _interval; + // SerialPrint(F("i"), _id, "this->doByInterval"); this->doByInterval(); } } @@ -201,7 +203,13 @@ bool IoTItem::isStrInID(const String& str) { } void IoTItem::setInterval(long interval) { - _interval = interval; + if (interval == 0) enableDoByInt = false; // выключаем использование периодического выполнения в модуле + else { + enableDoByInt = true; + if (interval > 0) _interval = interval * 1000; // если int положителен, то считаем, что получены секунды + else if (interval < 0) _interval = interval * -1; // если int отрицательный, то миллисекунды + } + // SerialPrint(F("i"), F("IoTItem"), "setInterval: " + _interval.toString); } IoTGpio* IoTItem::getGpioDriver() { diff --git a/src/modules/display/NextionUpload/NextionUpload.cpp b/src/modules/display/NextionUpload/NextionUpload.cpp index 9239d3ee..4d1f0c83 100644 --- a/src/modules/display/NextionUpload/NextionUpload.cpp +++ b/src/modules/display/NextionUpload/NextionUpload.cpp @@ -43,13 +43,16 @@ public: #if defined ESP8266 if (!http.begin(_host, 80, _url)) { -#elif defined ESP32 - if (!http.begin(String("http://") + _host + _url)) - { -#endif // Serial.println("connection failed"); SerialPrint("I", F("NextionUpdate"), "connection failed "); } +#elif defined ESP32 + if (!http.begin(String("http://") + _host + _url)) + { + // Serial.println("connection failed"); + SerialPrint("I", F("NextionUpdate"), "connection failed "); + } +#endif SerialPrint("I", F("NextionUpdate"), "Requesting file: " + (String)_url); int code = http.GET(); diff --git a/src/modules/exec/ButtonOut/ButtonOut.cpp b/src/modules/exec/ButtonOut/ButtonOut.cpp index e5f86172..288760b5 100644 --- a/src/modules/exec/ButtonOut/ButtonOut.cpp +++ b/src/modules/exec/ButtonOut/ButtonOut.cpp @@ -3,24 +3,28 @@ extern IoTGpio IoTgpio; - class ButtonOut : public IoTItem { private: - int _pin, _inv; + int _pin; + bool _inv; public: ButtonOut(String parameters): IoTItem(parameters) { jsonRead(parameters, "pin", _pin); jsonRead(parameters, "inv", _inv); _round = 0; - IoTgpio.pinMode(_pin, OUTPUT); IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD); + enableDoByInt = false; } void doByInterval() { - //value.valD = IoTgpio.analogRead(_pin); - + int val = _inv?1:0; + IoTgpio.digitalWrite(_pin, val); + // SerialPrint("I", "ButtonOut","single pulse end"); + value.valD = 0; + regEvent(0, "ButtonOut"); + enableDoByInt = false; //regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один } @@ -34,20 +38,36 @@ class ButtonOut : public IoTItem { IoTgpio.digitalWrite(_pin, value.valD); regEvent(value.valD, "ButtonOut"); } - + else if (command == "pulse") { + if (param[0].isDecimal && (param[0].valD != 0)) { + value.valD = !_inv?1:0; + enableDoByInt = true; + // SerialPrint("I", "ButtonOut","single pulse start"); + regEvent((String)(int)!_inv?1:0, "ButtonOut"); + suspendNextDoByInt(param[0].valD); + IoTgpio.digitalWrite(_pin, !_inv?1:0); + } + } return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки } void setValue(const IoTValue& Value, bool genEvent = true) { value = Value; - IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD); + if ((value.valD == !_inv?1:0) && (_interval != 0)) { + value.valD = !_inv?1:0; + enableDoByInt = true; + // SerialPrint("I", "ButtonOut","single pulse start"); + suspendNextDoByInt(_interval); + } else { + enableDoByInt = false; + } regEvent((String)(int)value.valD, "ButtonOut", false, genEvent); + IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD); } String getValue() { return (String)(int)value.valD; } - //======================================================================================================= ~ButtonOut() {}; }; diff --git a/src/modules/exec/ButtonOut/modinfo.json b/src/modules/exec/ButtonOut/modinfo.json index 35e4d5c7..e55011ef 100644 --- a/src/modules/exec/ButtonOut/modinfo.json +++ b/src/modules/exec/ButtonOut/modinfo.json @@ -39,6 +39,11 @@ "name": "change", "descr": "Инвертирует значение переключателя", "params": [] + }, + { + "name": "pulse", + "descr": "Генерирует одиночный импульс", + "params": ["Длительность (ms)"] } ] }, diff --git a/src/modules/exec/Buzzer/Buzzer.cpp b/src/modules/exec/Buzzer/Buzzer.cpp index 5668b549..656b8dc9 100644 --- a/src/modules/exec/Buzzer/Buzzer.cpp +++ b/src/modules/exec/Buzzer/Buzzer.cpp @@ -79,16 +79,7 @@ public: case 1: // for doByIntervals - if (enableDoByInt) - { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= _interval) - { - prevMillis = millis(); - this->doByInterval(); - } - } + IoTItem::loop(); break; case 2: diff --git a/src/modules/exec/MySensors/MySensorsGate.cpp b/src/modules/exec/MySensors/MySensorsGate.cpp index 717c0954..8e4aebde 100644 --- a/src/modules/exec/MySensors/MySensorsGate.cpp +++ b/src/modules/exec/MySensors/MySensorsGate.cpp @@ -3,6 +3,11 @@ #include "Arduino.h" #include "MySensorsGate.h" +// временное решение +unsigned long currentMillis; +unsigned long prevMillis; +unsigned long difference; + #ifdef MYSENSORS // callback библиотеки mysensors void receive(const MyMessage& message) { diff --git a/src/modules/exec/Thermostat/Thermostat.cpp b/src/modules/exec/Thermostat/Thermostat.cpp index bcac8274..68999c20 100644 --- a/src/modules/exec/Thermostat/Thermostat.cpp +++ b/src/modules/exec/Thermostat/Thermostat.cpp @@ -246,6 +246,11 @@ protected: pv_last = pv; } +// временное решение + unsigned long currentMillis; + unsigned long prevMillis; + unsigned long difference; + void loop() { if (enableDoByInt) diff --git a/src/modules/sensors/AnalogAdc/AnalogAdc.cpp b/src/modules/sensors/AnalogAdc/AnalogAdc.cpp index 1e90f30d..510d5723 100644 --- a/src/modules/sensors/AnalogAdc/AnalogAdc.cpp +++ b/src/modules/sensors/AnalogAdc/AnalogAdc.cpp @@ -64,13 +64,7 @@ class AnalogAdc : public IoTItem { _avgSumm = _avgSumm + IoTgpio.analogRead(_pin); _avgCount++; } - - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= _interval) { - prevMillis = millis(); - this->doByInterval(); - } + IoTItem::loop(); } ~AnalogAdc(){}; diff --git a/src/modules/sensors/ExampleModule/ExampleModule.cpp b/src/modules/sensors/ExampleModule/ExampleModule.cpp index 871fe1e7..cbcebe61 100644 --- a/src/modules/sensors/ExampleModule/ExampleModule.cpp +++ b/src/modules/sensors/ExampleModule/ExampleModule.cpp @@ -102,13 +102,7 @@ public: adc = IoTgpio.analogRead(_pin); // Блок вызова doByInterval, так как если определили loop, то сам он не вызовится - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= _interval) - { - prevMillis = millis(); - this->doByInterval(); - } + IoTItem::loop(); } ~ExampleModule_A(){}; diff --git a/src/modules/sensors/Sds011/Sds011.cpp b/src/modules/sensors/Sds011/Sds011.cpp index fb081e38..1a903d86 100644 --- a/src/modules/sensors/Sds011/Sds011.cpp +++ b/src/modules/sensors/Sds011/Sds011.cpp @@ -157,16 +157,17 @@ public: void loop() { ts_sds.update(); - if (enableDoByInt) - { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= _interval) - { - prevMillis = millis(); - this->doByInterval(); - } - } + IoTItem::loop(); + // if (enableDoByInt) + // { + // currentMillis = millis(); + // difference = currentMillis - prevMillis; + // if (difference >= _interval) + // { + // prevMillis = millis(); + // this->doByInterval(); + // } + // } } //======================================================================================================= // doByInterval() diff --git a/src/modules/virtual/GoogleSheet/GoogleSheet.cpp b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp index e04b468e..3b196c4f 100644 --- a/src/modules/virtual/GoogleSheet/GoogleSheet.cpp +++ b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp @@ -10,7 +10,7 @@ private: String scid = ""; String shname = ""; // bool init = false; - int interval = 1; + // int interval = 1; // long interval; String URL = ("http://iotmanager.org/projects/google.php?/macros/s/"); // F("https://script.google.com/macros/s/"); String urlFinal; @@ -24,8 +24,11 @@ public: jsonRead(parameters, F("logid"), logid); jsonRead(parameters, F("scid"), scid); jsonRead(parameters, F("shname"), shname); - jsonRead(parameters, F("int"), interval); - interval = interval * 1000 * 60; // так как у нас в минутах + // jsonRead(parameters, F("int"), interval); + long interval; + jsonRead(parameters, F("int"), interval); // в минутах + setInterval(interval * 60); + // interval = interval * 1000 * 60; // так как у нас в минутах urlFinal = URL + scid + F("/exec?") + F("sheet=") + shname; } @@ -39,19 +42,19 @@ public: } } - void loop() - { - if (enableDoByInt) - { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= interval) - { - prevMillis = millis(); - this->doByInterval(); - } - } - } + // void loop() + // { + // if (enableDoByInt) + // { + // currentMillis = millis(); + // difference = currentMillis - prevMillis; + // if (difference >= interval) + // { + // prevMillis = millis(); + // this->doByInterval(); + // } + // } + // } IoTValue execute(String command, std::vector ¶m) { diff --git a/src/modules/virtual/Loging/Loging.cpp b/src/modules/virtual/Loging/Loging.cpp index 9671632e..fa8d4c48 100644 --- a/src/modules/virtual/Loging/Loging.cpp +++ b/src/modules/virtual/Loging/Loging.cpp @@ -23,7 +23,7 @@ class Loging : public IoTItem { String prevDate = ""; bool firstTimeInit = true; - long interval; + // long interval; public: Loging(String parameters) : IoTItem(parameters) { @@ -34,8 +34,9 @@ class Loging : public IoTItem { points = 300; SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300"); } - jsonRead(parameters, F("int"), interval); - interval = interval * 1000 * 60; // приводим к милисекундам + long interval; + jsonRead(parameters, F("int"), interval); // в минутах + setInterval(interval * 60); //jsonRead(parameters, F("keepdays"), keepdays, false); // создадим экземпляр класса даты @@ -303,18 +304,18 @@ class Loging : public IoTItem { return ""; } - void loop() { - if (enableDoByInt) { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= interval) { - prevMillis = millis(); - if (interval != 0) { - this->doByInterval(); - } - } - } - } + // void loop() { + // if (enableDoByInt) { + // currentMillis = millis(); + // difference = currentMillis - prevMillis; + // if (difference >= interval) { + // prevMillis = millis(); + // if (interval != 0) { + // this->doByInterval(); + // } + // } + // } + // } void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) { String userDate = getItemValue(id + "-date"); diff --git a/src/modules/virtual/LogingDaily/LogingDaily.cpp b/src/modules/virtual/LogingDaily/LogingDaily.cpp index 6e7e87b4..bc5556b6 100644 --- a/src/modules/virtual/LogingDaily/LogingDaily.cpp +++ b/src/modules/virtual/LogingDaily/LogingDaily.cpp @@ -25,7 +25,7 @@ class LogingDaily : public IoTItem { String prevDate = ""; bool firstTimeInit = true; - long interval; + // long interval; public: LogingDaily(String parameters) : IoTItem(parameters) { @@ -40,8 +40,9 @@ class LogingDaily : public IoTItem { points = 365; SerialPrint("E", F("LogingDaily"), "'" + id + "' user set more points than allowed, value reset to 365"); } - jsonRead(parameters, F("int"), interval); - interval = interval * 1000 * 60; // приводим к милисекундам + long interval; + jsonRead(parameters, F("int"), interval); // в минутах + setInterval(interval * 60); } void doByInterval() { @@ -225,16 +226,16 @@ class LogingDaily : public IoTItem { return ""; } - void loop() { - if (enableDoByInt) { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= interval) { - prevMillis = millis(); - this->doByInterval(); - } - } - } + // void loop() { + // if (enableDoByInt) { + // currentMillis = millis(); + // difference = currentMillis - prevMillis; + // if (difference >= interval) { + // prevMillis = millis(); + // this->doByInterval(); + // } + // } + // } // просто максимальное количество точек int calculateMaxCount() { diff --git a/src/modules/virtual/Weather/Weather.cpp b/src/modules/virtual/Weather/Weather.cpp index 2e39d8c7..9cadadeb 100644 --- a/src/modules/virtual/Weather/Weather.cpp +++ b/src/modules/virtual/Weather/Weather.cpp @@ -11,15 +11,16 @@ class Weather : public IoTItem private: String _location; String _param; - long interval; + // long interval; public: Weather(String parameters) : IoTItem(parameters) { _location = jsonReadStr(parameters, "location"); _param = jsonReadStr(parameters, "param"); - jsonRead(parameters, F("int"), interval); - interval = interval * 1000 * 60 * 60; // интервал проверки погоды в часах + long interval; + jsonRead(parameters, F("int"), interval); // интервал проверки погоды в часах + setInterval(interval * 60 * 60); } void getWeather() @@ -113,19 +114,21 @@ public: regEvent(value.valS, "Weather"); } } - void loop() - { - if (enableDoByInt) - { - currentMillis = millis(); - difference = currentMillis - prevMillis; - if (difference >= interval) - { - prevMillis = millis(); - this->doByInterval(); - } - } - } + + // void loop() + // { + // if (enableDoByInt) + // { + // currentMillis = millis(); + // difference = currentMillis - prevMillis; + // if (difference >= interval) + // { + // prevMillis = millis(); + // this->doByInterval(); + // } + // } + // } + IoTValue execute(String command, std::vector ¶m) { if (command == "get") From 2def3f2825d65d2fbf9744eabad390dce887d0f9 Mon Sep 17 00:00:00 2001 From: DmitriyTychina Date: Tue, 5 Sep 2023 00:43:18 +0300 Subject: [PATCH 03/19] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20change()=20=D0=B2=20ButtonOut=20=D1=81=20=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20"inv"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/ButtonOut/ButtonOut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/exec/ButtonOut/ButtonOut.cpp b/src/modules/exec/ButtonOut/ButtonOut.cpp index 288760b5..65b8e42f 100644 --- a/src/modules/exec/ButtonOut/ButtonOut.cpp +++ b/src/modules/exec/ButtonOut/ButtonOut.cpp @@ -34,8 +34,8 @@ class ButtonOut : public IoTItem { // param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22 if (command == "change") { - value.valD = 1 - IoTgpio.digitalRead(_pin); - IoTgpio.digitalWrite(_pin, value.valD); + value.valD = 1 - (int)value.valD; + IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD); regEvent(value.valD, "ButtonOut"); } else if (command == "pulse") { From 848bbaab968c6bd6e66155e99493e7ee3896d6f0 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:59:30 +0200 Subject: [PATCH 04/19] migration --- data_svelte/items.json | 201 +++++++++++++++++++------------------ data_svelte/myProfile.json | 2 +- myProfile.json | 2 +- platformio.ini | 2 +- src/modules/API.cpp | 8 +- 5 files changed, 111 insertions(+), 104 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 969ff47f..7b798e49 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -192,19 +192,7 @@ "header": "sensors" }, { - "name": "13. A02 Дальность", - "type": "Reading", - "subtype": "A02Distance", - "id": "dist", - "widget": "anydataCm", - "page": "Сенсоры", - "descr": "Дальность", - "int": 5, - "round": 1, - "num": 13 - }, - { - "name": "14. Acs712 Ток", + "name": "13. Acs712 Ток", "type": "Reading", "subtype": "Acs712", "id": "amp", @@ -219,11 +207,11 @@ "sens": 100, "adczero": 512, "btn-setZero": "nil", - "num": 14 + "num": 13 }, { "global": 0, - "name": "15. AHTXX Температура", + "name": "14. AHTXX Температура", "type": "Reading", "subtype": "AhtXXt", "id": "Temp20", @@ -234,11 +222,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 15 + "num": 14 }, { "global": 0, - "name": "16. AHTXX Влажность", + "name": "15. AHTXX Влажность", "type": "Reading", "subtype": "AhtXXh", "id": "Hum20", @@ -249,11 +237,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 16 + "num": 15 }, { "global": 0, - "name": "17. Аналоговый сенсор", + "name": "16. Аналоговый сенсор", "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -267,11 +255,11 @@ "pin": 0, "int": 15, "avgSteps": 1, - "num": 17 + "num": 16 }, { "global": 0, - "name": "18. BME280 Температура", + "name": "17. BME280 Температура", "type": "Reading", "subtype": "Bme280t", "id": "Tmp3", @@ -281,11 +269,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 18 + "num": 17 }, { "global": 0, - "name": "19. BME280 Давление", + "name": "18. BME280 Давление", "type": "Reading", "subtype": "Bme280p", "id": "Press3", @@ -295,11 +283,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 19 + "num": 18 }, { "global": 0, - "name": "20. BME280 Влажность", + "name": "19. BME280 Влажность", "type": "Reading", "subtype": "Bme280h", "id": "Hum3", @@ -309,11 +297,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 20 + "num": 19 }, { "global": 0, - "name": "21. BME280 Tочка росы", + "name": "20. BME280 Tочка росы", "type": "Reading", "subtype": "Bme280dp", "id": "Dew3", @@ -323,11 +311,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 21 + "num": 20 }, { "global": 0, - "name": "22. BMP280 Температура", + "name": "21. BMP280 Температура", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -337,11 +325,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 22 + "num": 21 }, { "global": 0, - "name": "23. BMP280 Давление", + "name": "22. BMP280 Давление", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -351,11 +339,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 23 + "num": 22 }, { "global": 0, - "name": "24. DHT11 Температура", + "name": "23. DHT11 Температура", "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -365,11 +353,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 24 + "num": 23 }, { "global": 0, - "name": "25. DHT11 Влажность", + "name": "24. DHT11 Влажность", "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -379,11 +367,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 25 + "num": 24 }, { "global": 0, - "name": "26. DS18B20 Температура", + "name": "25. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -395,11 +383,11 @@ "index": 0, "addr": "", "round": 1, - "num": 26 + "num": 25 }, { "global": 0, - "name": "27. Аналоговый счетчик импульсов", + "name": "26. Аналоговый счетчик импульсов", "type": "Writing", "subtype": "Impulse", "id": "impulse", @@ -412,11 +400,11 @@ "pinMode": "INPUT", "debounceDelay": 3, "multiply": 1, - "num": 27 + "num": 26 }, { "global": 0, - "name": "28. PZEM 004t Напряжение", + "name": "27. PZEM 004t Напряжение", "type": "Reading", "subtype": "Pzem004v", "id": "v", @@ -426,11 +414,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 28 + "num": 27 }, { "global": 0, - "name": "29. PZEM 004t Сила тока", + "name": "28. PZEM 004t Сила тока", "type": "Reading", "subtype": "Pzem004a", "id": "a", @@ -440,11 +428,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 29 + "num": 28 }, { "global": 0, - "name": "30. PZEM 004t Мощность", + "name": "29. PZEM 004t Мощность", "type": "Reading", "subtype": "Pzem004w", "id": "w", @@ -454,11 +442,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 30 + "num": 29 }, { "global": 0, - "name": "31. PZEM 004t Энергия", + "name": "30. PZEM 004t Энергия", "type": "Reading", "subtype": "Pzem004wh", "id": "wh", @@ -468,11 +456,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 31 + "num": 30 }, { "global": 0, - "name": "32. PZEM 004t Частота", + "name": "31. PZEM 004t Частота", "type": "Reading", "subtype": "Pzem004hz", "id": "hz", @@ -482,11 +470,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 32 + "num": 31 }, { "global": 0, - "name": "33. PZEM 004t Косинус", + "name": "32. PZEM 004t Косинус", "type": "Reading", "subtype": "Pzem004pf", "id": "pf", @@ -496,11 +484,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 33 + "num": 32 }, { "global": 0, - "name": "34. PZEM настройка", + "name": "33. PZEM настройка", "type": "Reading", "subtype": "Pzem004cmd", "id": "set", @@ -512,11 +500,11 @@ "changeaddr": 0, "setaddr": "0x01", "reset": 0, - "num": 34 + "num": 33 }, { "global": 0, - "name": "35. Часы реального времени", + "name": "34. Часы реального времени", "type": "Reading", "subtype": "RTC", "id": "rtc", @@ -532,11 +520,11 @@ "int": 5, "btn-setUTime": "0", "btn-setSysTime": "nil", - "num": 35 + "num": 34 }, { - "name": "36. (S8) Cенсор качества воздуха", - "num": 36, + "name": "35. (S8) Cенсор качества воздуха", + "num": 35, "type": "Reading", "subtype": "S8co", "id": "s8co", @@ -550,7 +538,7 @@ }, { "global": 0, - "name": "37. Sht20 Температура", + "name": "36. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -559,11 +547,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 37 + "num": 36 }, { "global": 0, - "name": "38. Sht20 Влажность", + "name": "37. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -572,11 +560,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 38 + "num": 37 }, { "global": 0, - "name": "39. Sht30 Температура", + "name": "38. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -585,11 +573,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 39 + "num": 38 }, { "global": 0, - "name": "40. Sht30 Влажность", + "name": "39. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -598,12 +586,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 40 + "num": 39 }, { "global": 0, - "name": "41. HC-SR04 Ультразвуковой дальномер", - "num": 41, + "name": "40. HC-SR04 Ультразвуковой дальномер", + "num": 40, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -615,7 +603,7 @@ "int": 5 }, { - "name": "42. UART", + "name": "41. UART", "type": "Reading", "subtype": "UART", "page": "", @@ -627,14 +615,14 @@ "line": 2, "speed": 9600, "eventFormat": 0, - "num": 42 + "num": 41 }, { "header": "executive_devices" }, { "global": 0, - "name": "43. Кнопка подключенная к пину", + "name": "42. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -649,11 +637,11 @@ "debounceDelay": 50, "fixState": 0, "inv": 0, - "num": 43 + "num": 42 }, { "global": 0, - "name": "44. Управление пином", + "name": "43. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -664,11 +652,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 44 + "num": 43 }, { "global": 0, - "name": "45. Пассивный звуковой извещатель", + "name": "44. Пассивный звуковой извещатель", "type": "Writing", "subtype": "Buzzer", "id": "buzzer", @@ -687,11 +675,11 @@ "cycle": 0, "indication": 1, "val": 0, - "num": 45 + "num": 44 }, { "global": 0, - "name": "46. Энкодер", + "name": "45. Энкодер", "type": "Writing", "subtype": "Encoder", "id": "enc", @@ -704,11 +692,11 @@ "step": 1, "stepOnPress": 5, "pins": "4,5,2", - "num": 46 + "num": 45 }, { "global": 0, - "name": "47. Сервопривод", + "name": "46. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -719,11 +707,11 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 47 + "num": 46 }, { "global": 0, - "name": "48. Расширитель портов Mcp23017", + "name": "47. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -733,11 +721,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 48 + "num": 47 }, { "global": 0, - "name": "49. MP3 плеер", + "name": "48. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -747,11 +735,11 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 49 + "num": 48 }, { "global": 0, - "name": "50. Сенсорная кнопка", + "name": "49. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -765,11 +753,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 50 + "num": 49 }, { "global": 0, - "name": "51. Расширитель портов Pcf8574", + "name": "50. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -779,27 +767,29 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 51 + "num": 50 }, { "global": 0, - "name": "52. PWM ESP8266", + "name": "51. PWM ESP32", "type": "Writing", - "subtype": "Pwm8266", + "subtype": "Pwm32", "id": "pwm", "widget": "range", "page": "Кнопки", "descr": "PWM", "int": 0, - "pin": 15, + "pin": 2, "freq": 5000, + "ledChannel": 2, + "PWM_resolution": 10, "val": 0, "apin": -1, - "num": 52 + "num": 51 }, { "global": 0, - "name": "53. Телеграм-Лайт", + "name": "52. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -808,14 +798,14 @@ "descr": "", "token": "", "chatID": "", - "num": 53 + "num": 52 }, { "header": "screens" }, { "global": 0, - "name": "54. LCD экран 2004", + "name": "53. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -828,10 +818,10 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 54 + "num": 53 }, { - "name": "55. LCD экран 1602", + "name": "54. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -844,6 +834,23 @@ "id2show": "", "prefix": "", "postfix": "", + "num": 54 + }, + { + "global": 0, + "name": "55. Smi2_m", + "type": "Writing", + "subtype": "Smi2_m", + "id": "Smi", + "widget": "", + "page": "Дисплеи", + "descr": "", + "int": 2, + "pin": 4, + "id2show": "id датчика", + "baud": "9600", + "rx": "16", + "tx": "17", "num": 55 }, { diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 3ea1cffd..7daba96d 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -24,7 +24,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp8266_4mb", + "default_envs": "esp32_4mb", "comments_default_envs": "choose from: esp8266_4mb or esp32_4mb or esp32s2_4mb or esp8266_1mb or esp8266_1mb_ota or esp8285_1mb or esp8285_1mb_ota", "envs": [ { diff --git a/myProfile.json b/myProfile.json index 3ea1cffd..7daba96d 100644 --- a/myProfile.json +++ b/myProfile.json @@ -24,7 +24,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp8266_4mb", + "default_envs": "esp32_4mb", "comments_default_envs": "choose from: esp8266_4mb or esp32_4mb or esp32s2_4mb or esp8266_1mb or esp8266_1mb_ota or esp8285_1mb or esp8285_1mb_ota", "envs": [ { diff --git a/platformio.ini b/platformio.ini index fdfd75eb..e11eabf9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,5 @@ [platformio] -default_envs = esp8266_4mb +default_envs = esp32_4mb data_dir = data_svelte [common_env_data] diff --git a/src/modules/API.cpp b/src/modules/API.cpp index f40b7c13..522512e8 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -7,7 +7,6 @@ void* getAPI_Timer(String subtype, String params); void* getAPI_Variable(String subtype, String params); void* getAPI_VariableColor(String subtype, String params); void* getAPI_VButton(String subtype, String params); -void* getAPI_A02Distance(String subtype, String params); void* getAPI_Acs712(String subtype, String params); void* getAPI_AhtXX(String subtype, String params); void* getAPI_AnalogAdc(String subtype, String params); @@ -32,9 +31,10 @@ void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mp3(String subtype, String params); void* getAPI_Multitouch(String subtype, String params); void* getAPI_Pcf8574(String subtype, String params); -void* getAPI_Pwm8266(String subtype, String params); +void* getAPI_Pwm32(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); +void* getAPI_Smi2_m(String subtype, String params); void* getAPI_TM16XX(String subtype, String params); void* getAPI(String subtype, String params) { @@ -46,7 +46,6 @@ if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VariableColor(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; -if ((tmpAPI = getAPI_A02Distance(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; @@ -71,9 +70,10 @@ if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI; -if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Pwm32(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_Smi2_m(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI; return nullptr; } \ No newline at end of file From d4bdcc13ff32ab1bf52ba6399548021c7ff2e2ee Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:02:14 +0200 Subject: [PATCH 05/19] 8266 --- data_svelte/items.json | 201 ++++++++++++++++++------------------- data_svelte/myProfile.json | 2 +- myProfile.json | 2 +- platformio.ini | 2 +- src/modules/API.cpp | 8 +- 5 files changed, 104 insertions(+), 111 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 7b798e49..969ff47f 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -192,7 +192,19 @@ "header": "sensors" }, { - "name": "13. Acs712 Ток", + "name": "13. A02 Дальность", + "type": "Reading", + "subtype": "A02Distance", + "id": "dist", + "widget": "anydataCm", + "page": "Сенсоры", + "descr": "Дальность", + "int": 5, + "round": 1, + "num": 13 + }, + { + "name": "14. Acs712 Ток", "type": "Reading", "subtype": "Acs712", "id": "amp", @@ -207,11 +219,11 @@ "sens": 100, "adczero": 512, "btn-setZero": "nil", - "num": 13 + "num": 14 }, { "global": 0, - "name": "14. AHTXX Температура", + "name": "15. AHTXX Температура", "type": "Reading", "subtype": "AhtXXt", "id": "Temp20", @@ -222,11 +234,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 14 + "num": 15 }, { "global": 0, - "name": "15. AHTXX Влажность", + "name": "16. AHTXX Влажность", "type": "Reading", "subtype": "AhtXXh", "id": "Hum20", @@ -237,11 +249,11 @@ "addr": "0x38", "shtType": 1, "round": 1, - "num": 15 + "num": 16 }, { "global": 0, - "name": "16. Аналоговый сенсор", + "name": "17. Аналоговый сенсор", "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -255,11 +267,11 @@ "pin": 0, "int": 15, "avgSteps": 1, - "num": 16 + "num": 17 }, { "global": 0, - "name": "17. BME280 Температура", + "name": "18. BME280 Температура", "type": "Reading", "subtype": "Bme280t", "id": "Tmp3", @@ -269,11 +281,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 17 + "num": 18 }, { "global": 0, - "name": "18. BME280 Давление", + "name": "19. BME280 Давление", "type": "Reading", "subtype": "Bme280p", "id": "Press3", @@ -283,11 +295,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 18 + "num": 19 }, { "global": 0, - "name": "19. BME280 Влажность", + "name": "20. BME280 Влажность", "type": "Reading", "subtype": "Bme280h", "id": "Hum3", @@ -297,11 +309,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 19 + "num": 20 }, { "global": 0, - "name": "20. BME280 Tочка росы", + "name": "21. BME280 Tочка росы", "type": "Reading", "subtype": "Bme280dp", "id": "Dew3", @@ -311,11 +323,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 20 + "num": 21 }, { "global": 0, - "name": "21. BMP280 Температура", + "name": "22. BMP280 Температура", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -325,11 +337,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 21 + "num": 22 }, { "global": 0, - "name": "22. BMP280 Давление", + "name": "23. BMP280 Давление", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -339,11 +351,11 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 22 + "num": 23 }, { "global": 0, - "name": "23. DHT11 Температура", + "name": "24. DHT11 Температура", "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -353,11 +365,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 23 + "num": 24 }, { "global": 0, - "name": "24. DHT11 Влажность", + "name": "25. DHT11 Влажность", "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -367,11 +379,11 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 24 + "num": 25 }, { "global": 0, - "name": "25. DS18B20 Температура", + "name": "26. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -383,11 +395,11 @@ "index": 0, "addr": "", "round": 1, - "num": 25 + "num": 26 }, { "global": 0, - "name": "26. Аналоговый счетчик импульсов", + "name": "27. Аналоговый счетчик импульсов", "type": "Writing", "subtype": "Impulse", "id": "impulse", @@ -400,11 +412,11 @@ "pinMode": "INPUT", "debounceDelay": 3, "multiply": 1, - "num": 26 + "num": 27 }, { "global": 0, - "name": "27. PZEM 004t Напряжение", + "name": "28. PZEM 004t Напряжение", "type": "Reading", "subtype": "Pzem004v", "id": "v", @@ -414,11 +426,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 27 + "num": 28 }, { "global": 0, - "name": "28. PZEM 004t Сила тока", + "name": "29. PZEM 004t Сила тока", "type": "Reading", "subtype": "Pzem004a", "id": "a", @@ -428,11 +440,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 28 + "num": 29 }, { "global": 0, - "name": "29. PZEM 004t Мощность", + "name": "30. PZEM 004t Мощность", "type": "Reading", "subtype": "Pzem004w", "id": "w", @@ -442,11 +454,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 29 + "num": 30 }, { "global": 0, - "name": "30. PZEM 004t Энергия", + "name": "31. PZEM 004t Энергия", "type": "Reading", "subtype": "Pzem004wh", "id": "wh", @@ -456,11 +468,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 30 + "num": 31 }, { "global": 0, - "name": "31. PZEM 004t Частота", + "name": "32. PZEM 004t Частота", "type": "Reading", "subtype": "Pzem004hz", "id": "hz", @@ -470,11 +482,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 31 + "num": 32 }, { "global": 0, - "name": "32. PZEM 004t Косинус", + "name": "33. PZEM 004t Косинус", "type": "Reading", "subtype": "Pzem004pf", "id": "pf", @@ -484,11 +496,11 @@ "int": 15, "addr": "0xF8", "round": 1, - "num": 32 + "num": 33 }, { "global": 0, - "name": "33. PZEM настройка", + "name": "34. PZEM настройка", "type": "Reading", "subtype": "Pzem004cmd", "id": "set", @@ -500,11 +512,11 @@ "changeaddr": 0, "setaddr": "0x01", "reset": 0, - "num": 33 + "num": 34 }, { "global": 0, - "name": "34. Часы реального времени", + "name": "35. Часы реального времени", "type": "Reading", "subtype": "RTC", "id": "rtc", @@ -520,11 +532,11 @@ "int": 5, "btn-setUTime": "0", "btn-setSysTime": "nil", - "num": 34 + "num": 35 }, { - "name": "35. (S8) Cенсор качества воздуха", - "num": 35, + "name": "36. (S8) Cенсор качества воздуха", + "num": 36, "type": "Reading", "subtype": "S8co", "id": "s8co", @@ -538,7 +550,7 @@ }, { "global": 0, - "name": "36. Sht20 Температура", + "name": "37. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -547,11 +559,11 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 36 + "num": 37 }, { "global": 0, - "name": "37. Sht20 Влажность", + "name": "38. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -560,11 +572,11 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 37 + "num": 38 }, { "global": 0, - "name": "38. Sht30 Температура", + "name": "39. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -573,11 +585,11 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 38 + "num": 39 }, { "global": 0, - "name": "39. Sht30 Влажность", + "name": "40. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -586,12 +598,12 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 39 + "num": 40 }, { "global": 0, - "name": "40. HC-SR04 Ультразвуковой дальномер", - "num": 40, + "name": "41. HC-SR04 Ультразвуковой дальномер", + "num": 41, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -603,7 +615,7 @@ "int": 5 }, { - "name": "41. UART", + "name": "42. UART", "type": "Reading", "subtype": "UART", "page": "", @@ -615,14 +627,14 @@ "line": 2, "speed": 9600, "eventFormat": 0, - "num": 41 + "num": 42 }, { "header": "executive_devices" }, { "global": 0, - "name": "42. Кнопка подключенная к пину", + "name": "43. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -637,11 +649,11 @@ "debounceDelay": 50, "fixState": 0, "inv": 0, - "num": 42 + "num": 43 }, { "global": 0, - "name": "43. Управление пином", + "name": "44. Управление пином", "type": "Writing", "subtype": "ButtonOut", "needSave": 0, @@ -652,11 +664,11 @@ "int": 0, "inv": 0, "pin": 2, - "num": 43 + "num": 44 }, { "global": 0, - "name": "44. Пассивный звуковой извещатель", + "name": "45. Пассивный звуковой извещатель", "type": "Writing", "subtype": "Buzzer", "id": "buzzer", @@ -675,11 +687,11 @@ "cycle": 0, "indication": 1, "val": 0, - "num": 44 + "num": 45 }, { "global": 0, - "name": "45. Энкодер", + "name": "46. Энкодер", "type": "Writing", "subtype": "Encoder", "id": "enc", @@ -692,11 +704,11 @@ "step": 1, "stepOnPress": 5, "pins": "4,5,2", - "num": 45 + "num": 46 }, { "global": 0, - "name": "46. Сервопривод", + "name": "47. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -707,11 +719,11 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 46 + "num": 47 }, { "global": 0, - "name": "47. Расширитель портов Mcp23017", + "name": "48. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -721,11 +733,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 47 + "num": 48 }, { "global": 0, - "name": "48. MP3 плеер", + "name": "49. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -735,11 +747,11 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 48 + "num": 49 }, { "global": 0, - "name": "49. Сенсорная кнопка", + "name": "50. Сенсорная кнопка", "type": "Writing", "subtype": "Multitouch", "id": "impulse", @@ -753,11 +765,11 @@ "pinMode": "INPUT", "debounceDelay": 50, "PWMDelay": 500, - "num": 49 + "num": 50 }, { "global": 0, - "name": "50. Расширитель портов Pcf8574", + "name": "51. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -767,29 +779,27 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 50 + "num": 51 }, { "global": 0, - "name": "51. PWM ESP32", + "name": "52. PWM ESP8266", "type": "Writing", - "subtype": "Pwm32", + "subtype": "Pwm8266", "id": "pwm", "widget": "range", "page": "Кнопки", "descr": "PWM", "int": 0, - "pin": 2, + "pin": 15, "freq": 5000, - "ledChannel": 2, - "PWM_resolution": 10, "val": 0, "apin": -1, - "num": 51 + "num": 52 }, { "global": 0, - "name": "52. Телеграм-Лайт", + "name": "53. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -798,14 +808,14 @@ "descr": "", "token": "", "chatID": "", - "num": 52 + "num": 53 }, { "header": "screens" }, { "global": 0, - "name": "53. LCD экран 2004", + "name": "54. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -818,10 +828,10 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 53 + "num": 54 }, { - "name": "54. LCD экран 1602", + "name": "55. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -834,23 +844,6 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 54 - }, - { - "global": 0, - "name": "55. Smi2_m", - "type": "Writing", - "subtype": "Smi2_m", - "id": "Smi", - "widget": "", - "page": "Дисплеи", - "descr": "", - "int": 2, - "pin": 4, - "id2show": "id датчика", - "baud": "9600", - "rx": "16", - "tx": "17", "num": 55 }, { diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 7daba96d..3ea1cffd 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -24,7 +24,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp32_4mb", + "default_envs": "esp8266_4mb", "comments_default_envs": "choose from: esp8266_4mb or esp32_4mb or esp32s2_4mb or esp8266_1mb or esp8266_1mb_ota or esp8285_1mb or esp8285_1mb_ota", "envs": [ { diff --git a/myProfile.json b/myProfile.json index 7daba96d..3ea1cffd 100644 --- a/myProfile.json +++ b/myProfile.json @@ -24,7 +24,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp32_4mb", + "default_envs": "esp8266_4mb", "comments_default_envs": "choose from: esp8266_4mb or esp32_4mb or esp32s2_4mb or esp8266_1mb or esp8266_1mb_ota or esp8285_1mb or esp8285_1mb_ota", "envs": [ { diff --git a/platformio.ini b/platformio.ini index e11eabf9..fdfd75eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,5 @@ [platformio] -default_envs = esp32_4mb +default_envs = esp8266_4mb data_dir = data_svelte [common_env_data] diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 522512e8..f40b7c13 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -7,6 +7,7 @@ void* getAPI_Timer(String subtype, String params); void* getAPI_Variable(String subtype, String params); void* getAPI_VariableColor(String subtype, String params); void* getAPI_VButton(String subtype, String params); +void* getAPI_A02Distance(String subtype, String params); void* getAPI_Acs712(String subtype, String params); void* getAPI_AhtXX(String subtype, String params); void* getAPI_AnalogAdc(String subtype, String params); @@ -31,10 +32,9 @@ void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mp3(String subtype, String params); void* getAPI_Multitouch(String subtype, String params); void* getAPI_Pcf8574(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_Lcd2004(String subtype, String params); -void* getAPI_Smi2_m(String subtype, String params); void* getAPI_TM16XX(String subtype, String params); void* getAPI(String subtype, String params) { @@ -46,6 +46,7 @@ if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VariableColor(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_A02Distance(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; @@ -70,10 +71,9 @@ if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(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_Lcd2004(subtype, params)) != nullptr) return tmpAPI; -if ((tmpAPI = getAPI_Smi2_m(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI; return nullptr; } \ No newline at end of file From fe9789fc52dcd935f068531d6cfafb1f6a86e9b5 Mon Sep 17 00:00:00 2001 From: DmitriyTychina Date: Wed, 20 Sep 2023 13:02:27 +0300 Subject: [PATCH 06/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B0=20=D0=B2=20=D1=80=D0=B5=D0=B6?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=20AP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/WsServer.h | 3 ++- include/utils/WiFiUtils.h | 4 ++-- src/WsServer.cpp | 8 +++++++- src/utils/SerialPrint.cpp | 8 ++++---- src/utils/WiFiUtils.cpp | 10 +++++++--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/WsServer.h b/include/WsServer.h index c9de7fe2..eed0ac78 100644 --- a/include/WsServer.h +++ b/include/WsServer.h @@ -20,4 +20,5 @@ void periodicWsSend(); void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize); void sendStringToWs(const String& header, String& payload, int client_id); -void sendDeviceList(uint8_t num); \ No newline at end of file +void sendDeviceList(uint8_t num); +int getNumWSClients(); \ No newline at end of file diff --git a/include/utils/WiFiUtils.h b/include/utils/WiFiUtils.h index 89bec1f4..7959fdc3 100644 --- a/include/utils/WiFiUtils.h +++ b/include/utils/WiFiUtils.h @@ -3,8 +3,8 @@ #include "Global.h" #include "MqttClient.h" -// boolean isNetworkActive(); -inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;}; +boolean isNetworkActive(); +uint8_t getNumAPClients(); void routerConnect(); bool startAPMode(); boolean RouterFind(String ssid); diff --git a/src/WsServer.cpp b/src/WsServer.cpp index 7dd5c8ed..2fbdaf85 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -414,7 +414,9 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St } void sendStringToWs(const String& header, String& payload, int client_id) { - if (!(WiFi.softAPgetStationNum() || isNetworkActive())) { + if ((!getNumAPClients() && !isNetworkActive()) || !getNumWSClients()) { + // standWebSocket.disconnect(); // это и ниже надо сделать при - + // standWebSocket.close(); // - отключении AP И WiFi(STA), надо менять ядро WiFi. Сейчас не закрывается сессия клиента при пропаже AP И WiFi(STA) return; } @@ -446,3 +448,7 @@ void sendDeviceList(uint8_t num) { SerialPrint("i", "FS", "flash list"); } } + +int getNumWSClients() { + return standWebSocket.connectedClients(false); +} \ No newline at end of file diff --git a/src/utils/SerialPrint.cpp b/src/utils/SerialPrint.cpp index 4b3d1434..879405da 100644 --- a/src/utils/SerialPrint.cpp +++ b/src/utils/SerialPrint.cpp @@ -11,11 +11,11 @@ void SerialPrint(const String& errorLevel, const String& module, const String& m tosend += msg; Serial.println(tosend); - if (isNetworkActive()) { - if (jsonReadInt(settingsFlashJson, F("log")) != 0) { - sendStringToWs(F("corelg"), tosend, -1); - } + // if (isNetworkActive()) { // все проверки происходят в sendStringToWs() + if (jsonReadInt(settingsFlashJson, F("log")) != 0) { + sendStringToWs(F("corelg"), tosend, -1); } + // } if (errorLevel == "E") { cleanString(tosend); diff --git a/src/utils/WiFiUtils.cpp b/src/utils/WiFiUtils.cpp index 681d2c8a..25c0e331 100644 --- a/src/utils/WiFiUtils.cpp +++ b/src/utils/WiFiUtils.cpp @@ -115,9 +115,13 @@ boolean RouterFind(String ssid) { return res; } -// boolean isNetworkActive() { -// return WiFi.status() == WL_CONNECTED; -// } +boolean isNetworkActive() { + return WiFi.status() == WL_CONNECTED; +} + +uint8_t getNumAPClients() { + return WiFi.softAPgetStationNum(); +} uint8_t RSSIquality() { uint8_t res = 0; From 6cd40fceee1675f69263fd5c308a926e3221ac66 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:47:57 +0200 Subject: [PATCH 07/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B8=D0=B4=D0=B6=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 2 +- data_svelte/widgets.json | 2 +- data_svelte_lite/widgets copy.json | 308 ------------------------- data_svelte_lite/widgets.json | 2 +- src/modules/exec/IoTServo/modinfo.json | 2 +- 5 files changed, 4 insertions(+), 312 deletions(-) delete mode 100644 data_svelte_lite/widgets copy.json diff --git a/data_svelte/items.json b/data_svelte/items.json index 969ff47f..3a180753 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -712,7 +712,7 @@ "type": "Writing", "subtype": "IoTServo", "id": "servo", - "widget": "range", + "widget": "rangeServo", "page": "servo", "descr": "угол", "int": 1, diff --git a/data_svelte/widgets.json b/data_svelte/widgets.json index ba91a71f..504fcac4 100644 --- a/data_svelte/widgets.json +++ b/data_svelte/widgets.json @@ -246,7 +246,7 @@ "debounce": 500 }, { - "name": "range", + "name": "rangeServo", "label": "Ползунок (Servo)", "widget": "range", "descrColor": "red", diff --git a/data_svelte_lite/widgets copy.json b/data_svelte_lite/widgets copy.json deleted file mode 100644 index ba91a71f..00000000 --- a/data_svelte_lite/widgets copy.json +++ /dev/null @@ -1,308 +0,0 @@ -[ - { - "name": "anydataRed", - "label": "Сообщение1", - "widget": "anydata", - "icon": "body", - "color": "red", - "descrColor": "red" - }, - { - "name": "anydataDgr", - "label": "Сообщение2", - "widget": "anydata", - "after": "", - "color": "red", - "icon": "walk" - }, - { - "name": "anydataDef", - "label": "Текст", - "widget": "anydata", - "after": "", - "icon": "" - }, - { - "name": "anydataVlt", - "label": "Вольты", - "widget": "anydata", - "after": "V", - "icon": "speedometer" - }, - { - "name": "anydataAmp", - "label": "Амперы", - "widget": "anydata", - "after": "A", - "icon": "speedometer" - }, - { - "name": "anydataWt", - "label": "Ватты", - "widget": "anydata", - "after": "Wt", - "icon": "speedometer", - "color": [ - { - "level": 0, - "value": "" - }, - { - "level": 200, - "value": "#009933" - }, - { - "level": 2000, - "value": "#FF9900" - }, - { - "level": 4000, - "value": "red" - } - ] - }, - { - "name": "anydataWth", - "label": "Энергия", - "widget": "anydata", - "after": "kWh", - "icon": "speedometer" - }, - { - "name": "anydataHtz", - "label": "Герцы", - "widget": "anydata", - "after": "Hz", - "icon": "speedometer" - }, - { - "name": "anydataTmp", - "label": "Температура", - "widget": "anydata", - "after": "°С", - "icon": "thermometer", - "font": "OCR A Std", - "color": [ - { - "level": -20, - "value": "#0000CC" - }, - { - "level": -10, - "value": "#0000CC" - }, - { - "level": 0, - "value": "#0000CC" - }, - { - "level": 12, - "value": "#3366FF" - }, - { - "level": 16, - "value": "#33CCFF" - }, - { - "level": 18, - "value": "#009933" - }, - { - "level": 30, - "value": "#FF9900" - }, - { - "level": 40, - "value": "red" - } - ] - }, - { - "name": "anydataMm", - "label": "Давление", - "widget": "anydata", - "after": "mm", - "icon": "speedometer" - }, - { - "name": "anydataHum", - "label": "Влажность", - "widget": "anydata", - "after": "%", - "icon": "water", - "color": "#88AADF" - }, - { - "name": "anydataTm", - "label": "Время", - "widget": "anydata", - "after": "", - "icon": "speedometer" - }, - { - "name": "button", - "label": "Кнопка", - "widget": "btn", - "size": "large", - "color": "green", - "send": "test" - }, - { - "name": "toggle", - "label": "Переключатель", - "widget": "toggle", - "icon": "", - "iconOff": "" - }, - { - "name": "chart1", - "label": "График без точек", - "widget": "chart", - "dateFormat": "HH:mm", - "maxCount": 86400, - "pointRadius": 0 - }, - { - "name": "chart2", - "label": "График с точками", - "widget": "chart", - "maxCount": 86400, - "dateFormat": "HH:mm" - }, - { - "name": "chart3", - "label": "График Дневной", - "widget": "chart", - "dateFormat": "DD.MM.YYYY", - "maxCount": 86400, - "type": "bar" - }, - { - "name": "fillgauge", - "label": "Бочка", - "widget": "fillgauge", - "circleColor": "#00FFFF", - "textColor": "#FFFFFF", - "waveTextColor": "#000000", - "waveColor": "#00FFFF" - }, - { - "name": "inputDate", - "label": "Ввод даты", - "widget": "input", - "size": "small", - "color": "orange", - "type": "date" - }, - { - "name": "inputDgt", - "label": "Ввод числа", - "widget": "input", - "color": "blue", - "type": "number" - }, - { - "name": "inputTxt", - "label": "Ввод текста", - "widget": "input", - "size": "small", - "color": "orange", - "type": "text" - }, - { - "name": "inputTm", - "label": "Ввод времени", - "widget": "input", - "color": "blue", - "type": "time" - }, - { - "name": "progressLine", - "label": "Статус линия", - "widget": "progress-line", - "icon": "sunny", - "max": "100", - "stroke": "10" - }, - { - "name": "progressRound", - "label": "Статус круг", - "widget": "progress-round", - "max": "100", - "stroke": "20", - "color": "#45ccce", - "background": "#777", - "semicircle": "1" - }, - { - "name": "range", - "label": "Ползунок", - "widget": "range", - "descrColor": "red", - "after": "%", - "k": 0.0977, - "min": 0, - "max": 100, - "debounce": 500 - }, - { - "name": "range", - "label": "Ползунок (Servo)", - "widget": "range", - "descrColor": "red", - "after": "%", - "k": 1, - "min": 0, - "max": 180, - "debounce": 500 - }, - { - "name": "select", - "label": "Выпадающий", - "widget": "select", - "options": [ - "Выключен", - "Включен" - ], - "status": 0 - }, - { - "name": "anydataPpm", - "label": "PPM", - "widget": "anydata", - "after": "ppm", - "icon": "speedometer" - }, - { - "name": "anydatamAmp", - "label": "миллиАмперы", - "widget": "anydata", - "after": "mAmp", - "icon": "speedometer" - }, - { - "name": "anydatamVlt", - "label": "миллиВольты", - "widget": "anydata", - "after": "mVlt", - "icon": "speedometer" - }, - { - "name": "anydatamWt", - "label": "миллиВатты", - "widget": "anydata", - "after": "mWt", - "icon": "speedometer" - }, - { - "name": "anydataCm", - "label": "Сантиметры", - "widget": "anydata", - "after": "cm", - "icon": "speedometer" - }, - { - "name": "nil", - "label": "Без виджета" - } -] \ No newline at end of file diff --git a/data_svelte_lite/widgets.json b/data_svelte_lite/widgets.json index ba91a71f..504fcac4 100644 --- a/data_svelte_lite/widgets.json +++ b/data_svelte_lite/widgets.json @@ -246,7 +246,7 @@ "debounce": 500 }, { - "name": "range", + "name": "rangeServo", "label": "Ползунок (Servo)", "widget": "range", "descrColor": "red", diff --git a/src/modules/exec/IoTServo/modinfo.json b/src/modules/exec/IoTServo/modinfo.json index 1eefb041..1bb4f300 100644 --- a/src/modules/exec/IoTServo/modinfo.json +++ b/src/modules/exec/IoTServo/modinfo.json @@ -7,7 +7,7 @@ "type": "Writing", "subtype": "IoTServo", "id": "servo", - "widget": "range", + "widget": "rangeServo", "page": "servo", "descr": "угол", "int": 1, From 11c7e50f835abe55ade98ce4da9d064582fcd00a Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:15:31 +0200 Subject: [PATCH 08/19] =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=B4=D1=83=D1=81?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/widgets.json | 2 +- data_svelte_lite/widgets.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data_svelte/widgets.json b/data_svelte/widgets.json index 504fcac4..8a758af7 100644 --- a/data_svelte/widgets.json +++ b/data_svelte/widgets.json @@ -250,7 +250,7 @@ "label": "Ползунок (Servo)", "widget": "range", "descrColor": "red", - "after": "%", + "after": "°", "k": 1, "min": 0, "max": 180, diff --git a/data_svelte_lite/widgets.json b/data_svelte_lite/widgets.json index 504fcac4..8a758af7 100644 --- a/data_svelte_lite/widgets.json +++ b/data_svelte_lite/widgets.json @@ -250,7 +250,7 @@ "label": "Ползунок (Servo)", "widget": "range", "descrColor": "red", - "after": "%", + "after": "°", "k": 1, "min": 0, "max": 180, From 97288a1f21ed87b998e2b10b42d7addf8607f2ff Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:48:23 +0200 Subject: [PATCH 09/19] =?UTF-8?q?=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=20oled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 31 +++- data_svelte/myProfile.json | 6 + myProfile.json | 6 + platformio.ini | 2 + src/modules/API.cpp | 2 + src/modules/display/Oled128/Oled128.cpp | 199 +++++++++++++++++++++++ src/modules/display/Oled128/modinfo.json | 86 ++++++++++ 7 files changed, 326 insertions(+), 6 deletions(-) create mode 100644 src/modules/display/Oled128/Oled128.cpp create mode 100644 src/modules/display/Oled128/modinfo.json diff --git a/data_svelte/items.json b/data_svelte/items.json index 3a180753..2730d052 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -810,12 +810,31 @@ "chatID": "", "num": 53 }, + { + "header": "Экраны" + }, + { + "name": "54. OLED экран 128*64", + "type": "Reading", + "subtype": "Oled128", + "id": "oled", + "widget": "", + "page": "", + "descr": "T", + "descr1": "C", + "int": 1, + "addr": "0x3C", + "coord": "0,10", + "id2show": "id датчика", + "shrift": "2", + "num": 54 + }, { "header": "screens" }, { "global": 0, - "name": "54. LCD экран 2004", + "name": "55. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -828,10 +847,10 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 54 + "num": 55 }, { - "name": "55. LCD экран 1602", + "name": "56. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -844,11 +863,11 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 55 + "num": 56 }, { "global": 0, - "name": "56. 7 сегментный дисплей TM16XX", + "name": "57. 7 сегментный дисплей TM16XX", "type": "Writing", "subtype": "TM16XX", "id": "tm", @@ -864,6 +883,6 @@ "intensity": "5", "on": "1", "id2show": "", - "num": 56 + "num": 57 } ] \ No newline at end of file diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 3ea1cffd..436647c6 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -368,6 +368,12 @@ "active": false } ], + "Экраны": [ + { + "path": "src/modules/display/Oled128", + "active": true + } + ], "screens": [ { "path": "src/modules/display/DwinI", diff --git a/myProfile.json b/myProfile.json index 3ea1cffd..436647c6 100644 --- a/myProfile.json +++ b/myProfile.json @@ -368,6 +368,12 @@ "active": false } ], + "Экраны": [ + { + "path": "src/modules/display/Oled128", + "active": true + } + ], "screens": [ { "path": "src/modules/display/DwinI", diff --git a/platformio.ini b/platformio.ini index fdfd75eb..ad8c7641 100644 --- a/platformio.ini +++ b/platformio.ini @@ -410,6 +410,7 @@ lib_deps = adafruit/Adafruit BusIO @ ^1.13.2 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit BusIO @ ^1.13.2 + gyverlibs/GyverOLED @ 1.4 https://github.com/robotclass/RobotClass_LiquidCrystal_I2C marcoschwartz/LiquidCrystal_I2C@^1.1.4 https://github.com/maxint-rd/TM16xx @@ -449,6 +450,7 @@ build_src_filter = + + + + + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index f40b7c13..5ca6bc50 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -34,6 +34,7 @@ void* getAPI_Multitouch(String subtype, String params); void* getAPI_Pcf8574(String subtype, String params); void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); +void* getAPI_Oled128(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); void* getAPI_TM16XX(String subtype, String params); @@ -73,6 +74,7 @@ if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(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_Oled128(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI; return nullptr; diff --git a/src/modules/display/Oled128/Oled128.cpp b/src/modules/display/Oled128/Oled128.cpp new file mode 100644 index 00000000..67caf4cd --- /dev/null +++ b/src/modules/display/Oled128/Oled128.cpp @@ -0,0 +1,199 @@ + + +#include "Global.h" +#include "classes/IoTItem.h" + +#include + + + +#include +//GyverOLED oled; +//GyverOLED oled; +//GyverOLED oled; +//GyverOLED oled; +//GyverOLED oled; +GyverOLED oled; + + +class Oled128 : public IoTItem { + private: + unsigned int _x; + unsigned int _y; + + unsigned int _k; + + int _shrift; + + String _id2show; + String _descr; + String _descr1; + + int _prevStrSize; + + bool _isShow = true; // экран показывает + + + + public: + Oled128(String parameters) : IoTItem(parameters) { + + String addr, size, xy, k ; + _prevStrSize = 0; + + + + jsonRead(parameters, "addr", addr); + if (addr == "") { + //scanI2C(); + return; + } + + + jsonRead(parameters, "coord", xy); + _x = selectFromMarkerToMarker(xy, ",", 0).toInt(); + _y = selectFromMarkerToMarker(xy, ",", 1).toInt(); + + jsonRead(parameters, "descr", _descr); + jsonRead(parameters, "id2show", _id2show); + jsonRead(parameters, "descr1", _descr1); + //jsonRead(parameters, "scale", _k); + jsonRead(parameters, "shrift", _shrift); + + // Wire.begin(2,0); // Инициализация шины I2C для модуля E01 + + oled.init(); // инициализация экрана + + } + + void doByInterval() { + + + + printBlankStr(_prevStrSize); + + + String tmpStr = ""; + + //if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show); + if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1; + else tmpStr = getItemValue(_id2show); + + //oled.setScale(2); + + oled.setScale(_shrift); + + oled.setCursorXY(_x, _y); + + oled.print(tmpStr); + + oled.update(); + + _prevStrSize = tmpStr.length(); + + + } + + IoTValue execute(String command, std::vector ¶m) { // будет возможным использовать, когда сценарии запустятся + + + + if (command == "scroll") { + String tmpStr = ""; + oled.clear(); + uint32_t tmr = millis(); + oled.autoPrintln(false); + int val = 128; + for (;;) { + //oled.clear(); // ЗАКОММЕНТИРУЙ, ЕСЛИ ВКЛЮЧЕН БУФЕР + //oled.setScale(2); + + oled.setScale(_shrift); + + oled.setCursor(val, _y); + + + oled.print(tmpStr); + oled.update(); + val--; + if (millis() - tmr > 5000);// return; + + + _isShow = true; + } + + } + + else if (command == "stopscroll") { + + + + _isShow = true; + // display->backlight(); + // else if (command == "noDisplay") { + // display->noDisplay(); + // _isShow = false; + } + else if (command == "display") { + // display.display(); + _isShow = true; + } else if (command == "toggle") { + if (_isShow) { + // display->noDisplay(); + _isShow = false; + } else { + // display.display(); + _isShow = true; + } + } else if (command == "x") { + if (param.size()) { + _x = param[0].valD; + } + } else if (command == "y") { + if (param.size()) { + _y = param[0].valD; + } + } else if (command == "descr") { + if (param.size()) { + _descr = param[0].valS; + } + } else if (command == "descr1") { + if (param.size()) { + _descr1 = param[0].valS; + } + } else if (command == "id2show") { + if (param.size()) { + _id2show = param[0].valS; + } + } + + doByInterval(); + return {}; + + } + + //печать пустой строки нужной длинны для затирания предыдущего значения на экране + void printBlankStr(int strSize) { + String tmpStr = ""; + for (int i = 0; i < strSize; i++) tmpStr += " "; + + // oled.setScale(2); + + oled.setScale(_shrift); + + oled.setCursorXY(_x, _y); + + oled.print(tmpStr); + } + + + ~Oled128(){}; +}; + +void *getAPI_Oled128(String subtype, String param) { + if (subtype == F("Oled128")) { + return new Oled128(param); + } else { + return nullptr; + } +} \ No newline at end of file diff --git a/src/modules/display/Oled128/modinfo.json b/src/modules/display/Oled128/modinfo.json new file mode 100644 index 00000000..409f46da --- /dev/null +++ b/src/modules/display/Oled128/modinfo.json @@ -0,0 +1,86 @@ +{ + "menuSection": "Экраны", + "configItem": [ + { + "name": "OLED экран 128*64", + "type": "Reading", + "subtype": "Oled128", + "id": "oled", + "widget": "", + "page": "", + "descr": "T", + "descr1": "C", + "int": 1, + "addr": "0x3C", + "coord": "0,10", + "id2show": "id датчика", + "shrift": "2" + } + ], + "about": { + "authorName": "Serghei Crasnicov", + "authorContact": "https://t.me/Serghei63", + "authorGit": "https://github.com/Serghei63", + "specialThanks": "Ilya Belyakov @Biveraxe", + "moduleName": "Oled128", + "moduleVersion": "1.0", + "moduleDesc": "Позволяет выводить на матричные Oled экраны по указанным позициям значения других элементов конфигурации.", + "usedRam": 15, + "propInfo": { + "int": "Период времени в секундах обновления информации на экране по конкретному элементу.", + "addr": "Адрес устройства на шине, обычно 0x3c.", + "coord": "Координата позиции для вывода данных элемента конфигурации.", + "id2show": "id элемента конфигурации.", + "shrift": "Шрифт текста от 1 до 4 " + }, + "funcInfo": [ + { + "name": "x", + "descr": "Устанавливает первую координату", + "params": [ + "Номер строки первого символа" + ] + }, + { + "name": "y", + "descr": "Устанавливает вторую координату", + "params": [ + "Номер столбца первого символа" + ] + }, + { + "name": "descr", + "descr": "Задает приставку слева от значения, если none значит пусто", + "params": [ + "Строка" + ] + }, + { + "name": "descr1", + "descr": "Задает приставку справа от значения. Если descr none , то не выводится", + "params": [ + "Строка" + ] + }, + { + "name": "id2show", + "descr": "Задает ИД элемента, значение которого хотим отображать на экране", + "params": [ + "Имя элемента конфигурации" + ] + } + ] + }, + "defActive": true, + "usedLibs": { + "esp32_4mb": [ + "gyverlibs/GyverOLED @ 1.4" + ], + "esp32_16mb": [ + "gyverlibs/GyverOLED @ 1.4" + ], + "esp8266_4mb": [ + "gyverlibs/GyverOLED @ 1.4" + ] + } +} \ No newline at end of file From 0eb6494772c1ede3f473b46449cd8ceddd66dd49 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:52:10 +0200 Subject: [PATCH 10/19] =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/display/Oled128/modinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/display/Oled128/modinfo.json b/src/modules/display/Oled128/modinfo.json index 409f46da..53cdeb0e 100644 --- a/src/modules/display/Oled128/modinfo.json +++ b/src/modules/display/Oled128/modinfo.json @@ -71,7 +71,7 @@ } ] }, - "defActive": true, + "defActive": false, "usedLibs": { "esp32_4mb": [ "gyverlibs/GyverOLED @ 1.4" From 7c0ffe7af595124f5fb7dd5c92f552a80d996bc0 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 15:55:47 +0200 Subject: [PATCH 11/19] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 28 ++++++---------------------- data_svelte/myProfile.json | 2 +- myProfile.json | 2 +- myProfileDef.json | 6 ++++++ platformio.ini | 2 -- src/modules/API.cpp | 2 -- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 2730d052..339ee7e9 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -813,28 +813,12 @@ { "header": "Экраны" }, - { - "name": "54. OLED экран 128*64", - "type": "Reading", - "subtype": "Oled128", - "id": "oled", - "widget": "", - "page": "", - "descr": "T", - "descr1": "C", - "int": 1, - "addr": "0x3C", - "coord": "0,10", - "id2show": "id датчика", - "shrift": "2", - "num": 54 - }, { "header": "screens" }, { "global": 0, - "name": "55. LCD экран 2004", + "name": "54. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -847,10 +831,10 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 55 + "num": 54 }, { - "name": "56. LCD экран 1602", + "name": "55. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -863,11 +847,11 @@ "id2show": "", "prefix": "", "postfix": "", - "num": 56 + "num": 55 }, { "global": 0, - "name": "57. 7 сегментный дисплей TM16XX", + "name": "56. 7 сегментный дисплей TM16XX", "type": "Writing", "subtype": "TM16XX", "id": "tm", @@ -883,6 +867,6 @@ "intensity": "5", "on": "1", "id2show": "", - "num": 57 + "num": 56 } ] \ No newline at end of file diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 436647c6..b864c59a 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -371,7 +371,7 @@ "Экраны": [ { "path": "src/modules/display/Oled128", - "active": true + "active": false } ], "screens": [ diff --git a/myProfile.json b/myProfile.json index 436647c6..b864c59a 100644 --- a/myProfile.json +++ b/myProfile.json @@ -371,7 +371,7 @@ "Экраны": [ { "path": "src/modules/display/Oled128", - "active": true + "active": false } ], "screens": [ diff --git a/myProfileDef.json b/myProfileDef.json index 3ea1cffd..b864c59a 100644 --- a/myProfileDef.json +++ b/myProfileDef.json @@ -368,6 +368,12 @@ "active": false } ], + "Экраны": [ + { + "path": "src/modules/display/Oled128", + "active": false + } + ], "screens": [ { "path": "src/modules/display/DwinI", diff --git a/platformio.ini b/platformio.ini index ad8c7641..fdfd75eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -410,7 +410,6 @@ lib_deps = adafruit/Adafruit BusIO @ ^1.13.2 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 adafruit/Adafruit BusIO @ ^1.13.2 - gyverlibs/GyverOLED @ 1.4 https://github.com/robotclass/RobotClass_LiquidCrystal_I2C marcoschwartz/LiquidCrystal_I2C@^1.1.4 https://github.com/maxint-rd/TM16xx @@ -450,7 +449,6 @@ build_src_filter = + + + - + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 5ca6bc50..f40b7c13 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -34,7 +34,6 @@ void* getAPI_Multitouch(String subtype, String params); void* getAPI_Pcf8574(String subtype, String params); void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); -void* getAPI_Oled128(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); void* getAPI_TM16XX(String subtype, String params); @@ -74,7 +73,6 @@ if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(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_Oled128(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI; return nullptr; From 44fab264ebc3134bf09b865d89a2cf9199a2388e Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:02:07 +0200 Subject: [PATCH 12/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 3 --- data_svelte/myProfile.json | 10 ++++------ myProfile.json | 10 ++++------ src/modules/display/Oled128/modinfo.json | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 339ee7e9..3a180753 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -810,9 +810,6 @@ "chatID": "", "num": 53 }, - { - "header": "Экраны" - }, { "header": "screens" }, diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index b864c59a..cbb608ac 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -368,12 +368,6 @@ "active": false } ], - "Экраны": [ - { - "path": "src/modules/display/Oled128", - "active": false - } - ], "screens": [ { "path": "src/modules/display/DwinI", @@ -387,6 +381,10 @@ "path": "src/modules/display/NextionUpload", "active": false }, + { + "path": "src/modules/display/Oled128", + "active": false + }, { "path": "src/modules/display/Smi2_m", "active": true diff --git a/myProfile.json b/myProfile.json index b864c59a..cbb608ac 100644 --- a/myProfile.json +++ b/myProfile.json @@ -368,12 +368,6 @@ "active": false } ], - "Экраны": [ - { - "path": "src/modules/display/Oled128", - "active": false - } - ], "screens": [ { "path": "src/modules/display/DwinI", @@ -387,6 +381,10 @@ "path": "src/modules/display/NextionUpload", "active": false }, + { + "path": "src/modules/display/Oled128", + "active": false + }, { "path": "src/modules/display/Smi2_m", "active": true diff --git a/src/modules/display/Oled128/modinfo.json b/src/modules/display/Oled128/modinfo.json index 53cdeb0e..3c3c73ac 100644 --- a/src/modules/display/Oled128/modinfo.json +++ b/src/modules/display/Oled128/modinfo.json @@ -1,5 +1,5 @@ { - "menuSection": "Экраны", + "menuSection": "screens", "configItem": [ { "name": "OLED экран 128*64", From 0b83a72dc4d512685819c914b302fe7efeada6cb Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:02:58 +0200 Subject: [PATCH 13/19] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myProfileDef.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/myProfileDef.json b/myProfileDef.json index b864c59a..cbb608ac 100644 --- a/myProfileDef.json +++ b/myProfileDef.json @@ -368,12 +368,6 @@ "active": false } ], - "Экраны": [ - { - "path": "src/modules/display/Oled128", - "active": false - } - ], "screens": [ { "path": "src/modules/display/DwinI", @@ -387,6 +381,10 @@ "path": "src/modules/display/NextionUpload", "active": false }, + { + "path": "src/modules/display/Oled128", + "active": false + }, { "path": "src/modules/display/Smi2_m", "active": true From fc3dfc389fbe165d9db60fb273d8c7093c96d0c2 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:27:58 +0200 Subject: [PATCH 14/19] SSD1306_128x64 --- src/modules/display/Oled128/Oled128.cpp | 141 ++++++++++-------------- 1 file changed, 58 insertions(+), 83 deletions(-) diff --git a/src/modules/display/Oled128/Oled128.cpp b/src/modules/display/Oled128/Oled128.cpp index 67caf4cd..91ebee55 100644 --- a/src/modules/display/Oled128/Oled128.cpp +++ b/src/modules/display/Oled128/Oled128.cpp @@ -1,20 +1,15 @@ - - #include "Global.h" #include "classes/IoTItem.h" -#include - - - #include -//GyverOLED oled; -//GyverOLED oled; -//GyverOLED oled; -//GyverOLED oled; -//GyverOLED oled; -GyverOLED oled; +GyverOLED oled; + +// GyverOLED oled; +// GyverOLED oled; +// GyverOLED oled; +// GyverOLED oled; +// GyverOLED oled; class Oled128 : public IoTItem { private: @@ -28,28 +23,22 @@ class Oled128 : public IoTItem { String _id2show; String _descr; String _descr1; - + int _prevStrSize; - bool _isShow = true; // экран показывает - - + bool _isShow = true; // экран показывает public: Oled128(String parameters) : IoTItem(parameters) { - - String addr, size, xy, k ; + String addr, size, xy, k; _prevStrSize = 0; - - jsonRead(parameters, "addr", addr); if (addr == "") { - //scanI2C(); + // scanI2C(); return; } - jsonRead(parameters, "coord", xy); _x = selectFromMarkerToMarker(xy, ",", 0).toInt(); _y = selectFromMarkerToMarker(xy, ",", 1).toInt(); @@ -57,92 +46,80 @@ class Oled128 : public IoTItem { jsonRead(parameters, "descr", _descr); jsonRead(parameters, "id2show", _id2show); jsonRead(parameters, "descr1", _descr1); - //jsonRead(parameters, "scale", _k); + // jsonRead(parameters, "scale", _k); jsonRead(parameters, "shrift", _shrift); // Wire.begin(2,0); // Инициализация шины I2C для модуля E01 - oled.init(); // инициализация экрана - + oled.init(); // инициализация экрана } void doByInterval() { + printBlankStr(_prevStrSize); - + String tmpStr = ""; - printBlankStr(_prevStrSize); - - - String tmpStr = ""; - - //if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show); - if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1; - else tmpStr = getItemValue(_id2show); + // if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show); + if (_descr != "none") + tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1; + else + tmpStr = getItemValue(_id2show); - //oled.setScale(2); + // oled.setScale(2); - oled.setScale(_shrift); + oled.setScale(_shrift); - oled.setCursorXY(_x, _y); + oled.setCursorXY(_x, _y); - oled.print(tmpStr); + oled.print(tmpStr); - oled.update(); + oled.update(); - _prevStrSize = tmpStr.length(); - - + _prevStrSize = tmpStr.length(); } IoTValue execute(String command, std::vector ¶m) { // будет возможным использовать, когда сценарии запустятся - - if (command == "scroll") { - String tmpStr = ""; - oled.clear(); - uint32_t tmr = millis(); - oled.autoPrintln(false); - int val = 128; - for (;;) { - //oled.clear(); // ЗАКОММЕНТИРУЙ, ЕСЛИ ВКЛЮЧЕН БУФЕР - //oled.setScale(2); + String tmpStr = ""; + oled.clear(); + uint32_t tmr = millis(); + oled.autoPrintln(false); + int val = 128; + for (;;) { + // oled.clear(); // ЗАКОММЕНТИРУЙ, ЕСЛИ ВКЛЮЧЕН БУФЕР + // oled.setScale(2); - oled.setScale(_shrift); + oled.setScale(_shrift); - oled.setCursor(val, _y); - + oled.setCursor(val, _y); - oled.print(tmpStr); + oled.print(tmpStr); oled.update(); - val--; - if (millis() - tmr > 5000);// return; + val--; + if (millis() - tmr > 5000) + ; // return; + _isShow = true; + } - _isShow = true; - } - } - + else if (command == "stopscroll") { - - - _isShow = true; - // display->backlight(); - // else if (command == "noDisplay") { - // display->noDisplay(); - // _isShow = false; - } - else if (command == "display") { - // display.display(); + // display->backlight(); + // else if (command == "noDisplay") { + // display->noDisplay(); + // _isShow = false; + } else if (command == "display") { + // display.display(); _isShow = true; } else if (command == "toggle") { if (_isShow) { - // display->noDisplay(); + // display->noDisplay(); _isShow = false; - } else { - // display.display(); + } else { + // display.display(); _isShow = true; } } else if (command == "x") { @@ -160,7 +137,7 @@ class Oled128 : public IoTItem { } else if (command == "descr1") { if (param.size()) { _descr1 = param[0].valS; - } + } } else if (command == "id2show") { if (param.size()) { _id2show = param[0].valS; @@ -169,24 +146,22 @@ class Oled128 : public IoTItem { doByInterval(); return {}; - } - //печать пустой строки нужной длинны для затирания предыдущего значения на экране + // печать пустой строки нужной длинны для затирания предыдущего значения на экране void printBlankStr(int strSize) { String tmpStr = ""; for (int i = 0; i < strSize; i++) tmpStr += " "; - // oled.setScale(2); + // oled.setScale(2); - oled.setScale(_shrift); + oled.setScale(_shrift); - oled.setCursorXY(_x, _y); + oled.setCursorXY(_x, _y); - oled.print(tmpStr); + oled.print(tmpStr); } - ~Oled128(){}; }; From 082496997c70d67965391029cc89a853b67425c7 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:32:49 +0200 Subject: [PATCH 15/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D0=BC=20=D0=B1=D0=B0=D0=B3=20=D0=BA=D0=B5?= =?UTF-8?q?=D1=88=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20-=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2=D0=B5=D0=B1=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B7=D0=B8=D1=82=D1=81=D1=8F=20=D0=BE=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D1=8C=20=D0=B1=D1=8B=D1=81=D1=82=D1=80=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/StandWebServer.cpp | 504 +++++++++++++++++------------------------ 1 file changed, 204 insertions(+), 300 deletions(-) diff --git a/src/StandWebServer.cpp b/src/StandWebServer.cpp index 5f899613..62751073 100644 --- a/src/StandWebServer.cpp +++ b/src/StandWebServer.cpp @@ -7,24 +7,21 @@ String unsupportedFiles = String(); static const char TEXT_PLAIN[] PROGMEM = "text/plain"; static const char FS_INIT_ERROR[] PROGMEM = "FS INIT ERROR"; static const char FILE_NOT_FOUND[] PROGMEM = "FileNotFound"; -//static bool fsOK; -//const char* fsName = "LittleFS"; +// static bool fsOK; +// const char* fsName = "LittleFS"; -void standWebServerInit() -{ +void standWebServerInit() { // Кэшировать файлы для быстрой работы - HTTP.serveStatic("/bundle.js", FileFS, "/", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/bundle.css", FileFS, "/", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/bundle.js.gz", FileFS, "/", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/bundle.css.gz", FileFS, "/", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/favicon.png", FileFS, "/", "max-age=31536000"); // кеширование на 1 год + HTTP.serveStatic("/build/bundle.js", FileFS, "/build/bundle.js.gz", "max-age=31536000"); // кеширование на 1 год + HTTP.serveStatic("/build/bundle.css", FileFS, "/build/bundle.css.gz", "max-age=31536000"); // кеширование на 1 год + HTTP.serveStatic("/favicon.ico", FileFS, "/favicon.ico", "max-age=31536000"); // кеширование на 1 год // HTTP.on("/devicelist.json", HTTP_GET, []() { // HTTP.send(200, "application/json", devListHeapJson); // }); - HTTP.on("/settings.h.json", HTTP_GET, []() { - HTTP.send(200, "application/json", settingsFlashJson); - }); + // HTTP.on("/settings.h.json", HTTP_GET, []() { + // HTTP.send(200, "application/json", settingsFlashJson); + //}); // HTTP.on("/settings.f.json", HTTP_GET, []() { // HTTP.send(200, "application/json", readFile(F("settings.json"), 20000)); // }); @@ -46,21 +43,19 @@ void standWebServerInit() // HTTP.send(200, "text/plain", "ok"); // }); - HTTP.on("/set", HTTP_GET, []() { if (HTTP.hasArg(F("routerssid")) && WiFi.getMode() == WIFI_AP) { - jsonWriteStr(settingsFlashJson, F("routerssid"), HTTP.arg(F("routerssid"))); - syncSettingsFlashJson(); - HTTP.send(200, "text/plain", "ok"); - } + jsonWriteStr(settingsFlashJson, F("routerssid"), HTTP.arg(F("routerssid"))); + syncSettingsFlashJson(); + HTTP.send(200, "text/plain", "ok"); + } if (HTTP.hasArg(F("routerpass")) && WiFi.getMode() == WIFI_AP) { - jsonWriteStr(settingsFlashJson, F("routerpass"), HTTP.arg(F("routerpass"))); - syncSettingsFlashJson(); - HTTP.send(200, "text/plain", "ok"); - } - - }); + jsonWriteStr(settingsFlashJson, F("routerpass"), HTTP.arg(F("routerpass"))); + syncSettingsFlashJson(); + HTTP.send(200, "text/plain", "ok"); + } + }); // Добавляем функцию Update для перезаписи прошивки по WiFi при 1М(256K FileFS) и выше // httpUpdater.setup(&HTTP); @@ -101,39 +96,33 @@ void standWebServerInit() //////////////////////////////// // Utils to return HTTP codes, and determine content-type -void replyOK() -{ +void replyOK() { HTTP.send(200, FPSTR(TEXT_PLAIN), ""); } -void replyOKWithMsg(String msg) -{ +void replyOKWithMsg(String msg) { HTTP.send(200, FPSTR(TEXT_PLAIN), msg); } -void replyNotFound(String msg) -{ +void replyNotFound(String msg) { HTTP.send(404, FPSTR(TEXT_PLAIN), msg); } -void replyBadRequest(String msg) -{ -// DBG_OUTPUT_PORT.println(msg); +void replyBadRequest(String msg) { + // DBG_OUTPUT_PORT.println(msg); HTTP.send(400, FPSTR(TEXT_PLAIN), msg + "\r\n"); } -void replyServerError(String msg) -{ -// DBG_OUTPUT_PORT.println(msg); +void replyServerError(String msg) { + // DBG_OUTPUT_PORT.println(msg); HTTP.send(500, FPSTR(TEXT_PLAIN), msg + "\r\n"); } /* Return the FS type, status and size info */ -void handleStatus() -{ -// DBG_OUTPUT_PORT.println("handleStatus"); +void handleStatus() { + // DBG_OUTPUT_PORT.println("handleStatus"); String json; json.reserve(128); @@ -141,22 +130,22 @@ void handleStatus() json += FS_NAME; json += "\", \"isOk\":"; - #ifdef ESP8266 +#ifdef ESP8266 FSInfo fs_info; - FileFS.info(fs_info); - json += F("\"true\", \"totalBytes\":\""); - json += fs_info.totalBytes; - json += F("\", \"usedBytes\":\""); - json += fs_info.usedBytes; - json += "\""; -#endif + FileFS.info(fs_info); + json += F("\"true\", \"totalBytes\":\""); + json += fs_info.totalBytes; + json += F("\", \"usedBytes\":\""); + json += fs_info.usedBytes; + json += "\""; +#endif #ifdef ESP32 - json += F("\"true\", \"totalBytes\":\""); - json += String(FileFS.totalBytes()); - json += F("\", \"usedBytes\":\""); - json += String(FileFS.usedBytes()); - json += "\""; + json += F("\"true\", \"totalBytes\":\""); + json += String(FileFS.totalBytes()); + json += F("\", \"usedBytes\":\""); + json += String(FileFS.usedBytes()); + json += "\""; #endif json += F(",\"unsupportedFiles\":\""); @@ -168,74 +157,66 @@ void handleStatus() #ifdef ESP32 String getContentType(String filename) { - if (HTTP.hasArg("download")) { - return "application/octet-stream"; - } else if (filename.endsWith(".htm")) { - return "text/html"; - } else if (filename.endsWith(".html")) { - return "text/html"; - } else if (filename.endsWith(".css")) { - return "text/css"; - } else if (filename.endsWith(".js")) { - return "application/javascript"; - } else if (filename.endsWith(".png")) { - return "image/png"; - } else if (filename.endsWith(".gif")) { - return "image/gif"; - } else if (filename.endsWith(".jpg")) { - return "image/jpeg"; - } else if (filename.endsWith(".ico")) { - return "image/x-icon"; - } else if (filename.endsWith(".xml")) { - return "text/xml"; - } else if (filename.endsWith(".pdf")) { - return "application/x-pdf"; - } else if (filename.endsWith(".zip")) { - return "application/x-zip"; - } else if (filename.endsWith(".gz")) { - return "application/x-gzip"; - } - return "text/plain"; + if (HTTP.hasArg("download")) { + return "application/octet-stream"; + } else if (filename.endsWith(".htm")) { + return "text/html"; + } else if (filename.endsWith(".html")) { + return "text/html"; + } else if (filename.endsWith(".css")) { + return "text/css"; + } else if (filename.endsWith(".js")) { + return "application/javascript"; + } else if (filename.endsWith(".png")) { + return "image/png"; + } else if (filename.endsWith(".gif")) { + return "image/gif"; + } else if (filename.endsWith(".jpg")) { + return "image/jpeg"; + } else if (filename.endsWith(".ico")) { + return "image/x-icon"; + } else if (filename.endsWith(".xml")) { + return "text/xml"; + } else if (filename.endsWith(".pdf")) { + return "application/x-pdf"; + } else if (filename.endsWith(".zip")) { + return "application/x-zip"; + } else if (filename.endsWith(".gz")) { + return "application/x-gzip"; + } + return "text/plain"; } #endif /* Read the given file from the filesystem and stream it back to the client */ -bool handleFileRead(String path) -{ -// DBG_OUTPUT_PORT.println(String("handleFileRead: ") + path); - if (path.endsWith("/")) - { +bool handleFileRead(String path) { + // DBG_OUTPUT_PORT.println(String("handleFileRead: ") + path); + if (path.endsWith("/")) { path += "index.html"; } String contentType; - if (HTTP.hasArg("download")) - { + if (HTTP.hasArg("download")) { contentType = F("application/octet-stream"); - } - else - { -#ifdef ESP32 + } else { +#ifdef ESP32 contentType = getContentType(path); #endif #ifdef ESP8266 contentType = mime::getContentType(path); -#endif +#endif } - if (!FileFS.exists(path)) - { + if (!FileFS.exists(path)) { // File not found, try gzip version path = path + ".gz"; } - if (FileFS.exists(path)) - { + if (FileFS.exists(path)) { File file = FileFS.open(path, "r"); - if (HTTP.streamFile(file, contentType) != file.size()) - { - // DBG_OUTPUT_PORT.println("Sent less data than expected!"); + if (HTTP.streamFile(file, contentType) != file.size()) { + // DBG_OUTPUT_PORT.println("Sent less data than expected!"); } file.close(); return true; @@ -248,90 +229,69 @@ bool handleFileRead(String path) As some FS (e.g. LittleFS) delete the parent folder when the last child has been removed, return the path of the closest parent still existing */ -String lastExistingParent(String path) -{ - while (!path.isEmpty() && !FileFS.exists(path)) - { - if (path.lastIndexOf('/') > 0) - { +String lastExistingParent(String path) { + while (!path.isEmpty() && !FileFS.exists(path)) { + if (path.lastIndexOf('/') > 0) { path = path.substring(0, path.lastIndexOf('/')); - } - else - { - path = String(); // No slash => the top folder does not exist + } else { + path = String(); // No slash => the top folder does not exist } } -// DBG_OUTPUT_PORT.println(String("Last existing parent: ") + path); + // DBG_OUTPUT_PORT.println(String("Last existing parent: ") + path); return path; } /* Handle a file upload request */ -void handleFileUpload() -{ - if (HTTP.uri() != "/edit") - { +void handleFileUpload() { + if (HTTP.uri() != "/edit") { return; } HTTPUpload &upload = HTTP.upload(); - if (upload.status == UPLOAD_FILE_START) - { + if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; // Make sure paths always start with "/" - if (!filename.startsWith("/")) - { + if (!filename.startsWith("/")) { filename = "/" + filename; } -// DBG_OUTPUT_PORT.println(String("handleFileUpload Name: ") + filename); + // DBG_OUTPUT_PORT.println(String("handleFileUpload Name: ") + filename); uploadFile = FileFS.open(filename, "w"); - if (!uploadFile) - { + if (!uploadFile) { return replyServerError(F("CREATE FAILED")); } -// DBG_OUTPUT_PORT.println(String("Upload: START, filename: ") + filename); - } - else if (upload.status == UPLOAD_FILE_WRITE) - { - if (uploadFile) - { + // DBG_OUTPUT_PORT.println(String("Upload: START, filename: ") + filename); + } else if (upload.status == UPLOAD_FILE_WRITE) { + if (uploadFile) { size_t bytesWritten = uploadFile.write(upload.buf, upload.currentSize); - if (bytesWritten != upload.currentSize) - { + if (bytesWritten != upload.currentSize) { return replyServerError(F("WRITE FAILED")); } } -// DBG_OUTPUT_PORT.println(String("Upload: WRITE, Bytes: ") + upload.currentSize); - } - else if (upload.status == UPLOAD_FILE_END) - { - if (uploadFile) - { + // DBG_OUTPUT_PORT.println(String("Upload: WRITE, Bytes: ") + upload.currentSize); + } else if (upload.status == UPLOAD_FILE_END) { + if (uploadFile) { uploadFile.close(); } -// DBG_OUTPUT_PORT.println(String("Upload: END, Size: ") + upload.totalSize); + // DBG_OUTPUT_PORT.println(String("Upload: END, Size: ") + upload.totalSize); } } - #ifdef ESP8266 -void deleteRecursive(String path) -{ +void deleteRecursive(String path) { File file = FileFS.open(path, "r"); bool isDir = file.isDirectory(); file.close(); // If it's a plain file, delete it - if (!isDir) - { + if (!isDir) { FileFS.remove(path); return; } Dir dir = FileFS.openDir(path); - while (dir.next()) - { + while (dir.next()) { deleteRecursive(path + '/' + dir.fileName()); - } + } // Then delete the folder itself FileFS.rmdir(path); @@ -339,41 +299,37 @@ void deleteRecursive(String path) #endif #ifdef ESP32 -struct treename{ - uint8_t type; - char *name; +struct treename { + uint8_t type; + char *name; }; +void deleteRecursive(String path) { + fs::File dir = FileFS.open(path); -void deleteRecursive( String path ){ - fs::File dir = FileFS.open( path ); - - if(!dir.isDirectory()){ - Serial.printf("%s is a file\n", path); - dir.close(); - Serial.printf( "result of removing file %s: %d\n", path, FileFS.remove( path ) ); - return; + if (!dir.isDirectory()) { + Serial.printf("%s is a file\n", path); + dir.close(); + Serial.printf("result of removing file %s: %d\n", path, FileFS.remove(path)); + return; } - + Serial.printf("%s is a directory\n", path); - + fs::File entry, nextentry; - - while ( entry = dir.openNextFile() ){ - -if ( entry.isDirectory() ){ - deleteRecursive( entry.path() ); - } else{ - String tmpname = path+"/"+strdup( entry.name() ); // buffer file name - entry.close(); - Serial.printf( "result of removing file %s: %d\n", tmpname, FileFS.remove( tmpname ) ); - } - + + while (entry = dir.openNextFile()) { + if (entry.isDirectory()) { + deleteRecursive(entry.path()); + } else { + String tmpname = path + "/" + strdup(entry.name()); // buffer file name + entry.close(); + Serial.printf("result of removing file %s: %d\n", tmpname, FileFS.remove(tmpname)); + } } - dir.close(); - Serial.printf( "result of removing directory %s: %d\n", path, FileFS.rmdir( path ) ); - + dir.close(); + Serial.printf("result of removing directory %s: %d\n", path, FileFS.rmdir(path)); } #endif /* @@ -383,23 +339,18 @@ if ( entry.isDirectory() ){ Delete file | parent of deleted file, or remaining ancestor Delete folder | parent of deleted folder, or remaining ancestor */ -void handleFileDelete() -{ +void handleFileDelete() { String path = HTTP.arg(0); - if (path.isEmpty() || path == "/") - { + if (path.isEmpty() || path == "/") { return replyBadRequest("BAD PATH"); } -// DBG_OUTPUT_PORT.println(String("handleFileDelete: ") + path); - if (!FileFS.exists(path)) - { + // DBG_OUTPUT_PORT.println(String("handleFileDelete: ") + path); + if (!FileFS.exists(path)) { return replyNotFound(FPSTR(FILE_NOT_FOUND)); } deleteRecursive(path); - - replyOKWithMsg(lastExistingParent(path)); } @@ -414,93 +365,72 @@ void handleFileDelete() Rename folder | parent of source folder Move folder | parent of source folder, or remaining ancestor */ -void handleFileCreate() -{ +void handleFileCreate() { String path = HTTP.arg("path"); - if (path.isEmpty()) - { + if (path.isEmpty()) { return replyBadRequest(F("PATH ARG MISSING")); } #ifdef USE_SPIFFS - if (checkForUnsupportedPath(path).length() > 0) - { + if (checkForUnsupportedPath(path).length() > 0) { return replyServerError(F("INVALID FILENAME")); } #endif - if (path == "/") - { + if (path == "/") { return replyBadRequest("BAD PATH"); } - if (FileFS.exists(path)) - { + if (FileFS.exists(path)) { return replyBadRequest(F("PATH FILE EXISTS")); } String src = HTTP.arg("src"); - if (src.isEmpty()) - { + if (src.isEmpty()) { // No source specified: creation -// DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path); - if (path.endsWith("/")) - { + // DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path); + if (path.endsWith("/")) { // Create a folder path.remove(path.length() - 1); - if (!FileFS.mkdir(path)) - { + if (!FileFS.mkdir(path)) { return replyServerError(F("MKDIR FAILED")); } - } - else - { + } else { // Create a file File file = FileFS.open(path, "w"); - if (file) - { -#ifdef ESP8266 + if (file) { +#ifdef ESP8266 file.write((const char *)0); #endif #ifdef ESP32 file.write(0); -#endif +#endif file.close(); - } - else - { + } else { return replyServerError(F("CREATE FAILED")); } } - if (path.lastIndexOf('/') > -1) - { + if (path.lastIndexOf('/') > -1) { path = path.substring(0, path.lastIndexOf('/')); } replyOKWithMsg(path); - } - else - { + } else { // Source specified: rename - if (src == "/") - { + if (src == "/") { return replyBadRequest("BAD SRC"); } - if (!FileFS.exists(src)) - { + if (!FileFS.exists(src)) { return replyBadRequest(F("SRC FILE NOT FOUND")); } -// DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path + " from " + src); + // DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path + " from " + src); - if (path.endsWith("/")) - { + if (path.endsWith("/")) { path.remove(path.length() - 1); } - if (src.endsWith("/")) - { + if (src.endsWith("/")) { src.remove(src.length() - 1); } - if (!FileFS.rename(src, path)) - { + if (!FileFS.rename(src, path)) { return replyServerError(F("RENAME FAILED")); } replyOKWithMsg(lastExistingParent(src)); @@ -512,26 +442,22 @@ void handleFileCreate() Also demonstrates the use of chunked responses. */ #ifdef ESP8266 -void handleFileList() -{ - if (!HTTP.hasArg("dir")) - { +void handleFileList() { + if (!HTTP.hasArg("dir")) { return replyBadRequest(F("DIR ARG MISSING")); } String path = HTTP.arg("dir"); - if (path != "/" && !FileFS.exists(path)) - { + if (path != "/" && !FileFS.exists(path)) { return replyBadRequest("BAD PATH"); } -// DBG_OUTPUT_PORT.println(String("handleFileList: ") + path); + // DBG_OUTPUT_PORT.println(String("handleFileList: ") + path); Dir dir = FileFS.openDir(path); path.clear(); // use HTTP/1.1 Chunked response to avoid building a huge temporary string - if (!HTTP.chunkedResponseModeStart(200, "text/json")) - { + if (!HTTP.chunkedResponseModeStart(200, "text/json")) { HTTP.send(505, F("text/html"), F("HTTP1.1 required")); return; } @@ -539,47 +465,36 @@ void handleFileList() // use the same string for every line String output; output.reserve(64); - while (dir.next()) - { + while (dir.next()) { #ifdef USE_SPIFFS String error = checkForUnsupportedPath(dir.fileName()); - if (error.length() > 0) - { -// DBG_OUTPUT_PORT.println(String("Ignoring ") + error + dir.fileName()); + if (error.length() > 0) { + // DBG_OUTPUT_PORT.println(String("Ignoring ") + error + dir.fileName()); continue; } #endif - if (output.length()) - { + if (output.length()) { // send string from previous iteration // as an HTTP chunk HTTP.sendContent(output); output = ','; - } - else - { + } else { output = '['; } output += "{\"type\":\""; - if (dir.isDirectory()) - { + if (dir.isDirectory()) { output += "dir"; - } - else - { + } else { output += F("file\",\"size\":\""); output += dir.fileSize(); } output += F("\",\"name\":\""); // Always return names without leading "/" - if (dir.fileName()[0] == '/') - { + if (dir.fileName()[0] == '/') { output += &(dir.fileName()[1]); - } - else - { + } else { output += dir.fileName(); } @@ -595,65 +510,57 @@ void handleFileList() #ifdef ESP32 void handleFileList() { - if (!HTTP.hasArg("dir")) { - HTTP.send(500, "text/plain", "BAD ARGS"); - return; - } + if (!HTTP.hasArg("dir")) { + HTTP.send(500, "text/plain", "BAD ARGS"); + return; + } - String path = HTTP.arg("dir"); -// DBG_OUTPUT_PORT.println("handleFileList: " + path); + String path = HTTP.arg("dir"); + // DBG_OUTPUT_PORT.println("handleFileList: " + path); + File root = FileFS.open(path); + path = String(); - File root = FileFS.open(path); - path = String(); + String output = "["; + if (root.isDirectory()) { + File file = root.openNextFile(); + while (file) { + if (output != "[") { + output += ','; + } + output += "{\"type\":\""; + // output += (file.isDirectory()) ? "dir" : "file"; + if (file.isDirectory()) { + output += "dir"; + } else { + output += F("file\",\"size\":\""); + output += file.size(); + } - String output = "["; - if(root.isDirectory()){ - File file = root.openNextFile(); - while(file){ - if (output != "[") { - output += ','; - } - output += "{\"type\":\""; - // output += (file.isDirectory()) ? "dir" : "file"; - if (file.isDirectory()) - { - output += "dir"; - } - else - { - output += F("file\",\"size\":\""); - output += file.size(); - } - - output += "\",\"name\":\""; + output += "\",\"name\":\""; output += String(file.name()); - output += "\"}"; - file = root.openNextFile(); - } - } - output += "]"; - HTTP.send(200, "text/json", output); - + output += "\"}"; + file = root.openNextFile(); + } + } + output += "]"; + HTTP.send(200, "text/json", output); } #endif - /* The "Not Found" handler catches all URI not explicitly declared in code First try to find and return the requested file from the filesystem, and if it fails, return a 404 page with debug information */ -void handleNotFound() -{ +void handleNotFound() { #ifdef ESP8266 - String uri = ESP8266WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks + String uri = ESP8266WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks #endif #ifdef ESP32 - String uri = WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks + String uri = WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks #endif - if (handleFileRead(uri)) - { + if (handleFileRead(uri)) { return; } @@ -667,8 +574,7 @@ void handleNotFound() message += F("\nArguments: "); message += HTTP.args(); message += '\n'; - for (uint8_t i = 0; i < HTTP.args(); i++) - { + for (uint8_t i = 0; i < HTTP.args(); i++) { message += F(" NAME:"); message += HTTP.argName(i); message += F("\n VALUE:"); @@ -678,7 +584,7 @@ void handleNotFound() message += "path="; message += HTTP.arg("path"); message += '\n'; -// DBG_OUTPUT_PORT.print(message); + // DBG_OUTPUT_PORT.print(message); return replyNotFound(message); } @@ -689,10 +595,8 @@ void handleNotFound() embedded in the program code. Otherwise, fails with a 404 page with debug information */ -void handleGetEdit() -{ - if (handleFileRead(F("/edit.htm"))) - { +void handleGetEdit() { + if (handleFileRead(F("/edit.htm"))) { return; } From 1a239f1f02ee00362464e852f64b5861cf4e7d5d Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:59:37 +0200 Subject: [PATCH 16/19] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=B5=D1=88=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/StandWebServer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/StandWebServer.cpp b/src/StandWebServer.cpp index 62751073..6a23378f 100644 --- a/src/StandWebServer.cpp +++ b/src/StandWebServer.cpp @@ -12,9 +12,10 @@ static const char FILE_NOT_FOUND[] PROGMEM = "FileNotFound"; void standWebServerInit() { // Кэшировать файлы для быстрой работы - HTTP.serveStatic("/build/bundle.js", FileFS, "/build/bundle.js.gz", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/build/bundle.css", FileFS, "/build/bundle.css.gz", "max-age=31536000"); // кеширование на 1 год - HTTP.serveStatic("/favicon.ico", FileFS, "/favicon.ico", "max-age=31536000"); // кеширование на 1 год + // если указана директория то все файлы будут отмечены как Directory Request Handler + // если указан файл то он будет отмечен как File Request Handler + HTTP.serveStatic("/build", FileFS, "/build", "max-age=31536000"); // кеширование на 1 год + HTTP.serveStatic("/favicon.ico", FileFS, "/favicon.ico", "max-age=31536000"); // кеширование на 1 год // HTTP.on("/devicelist.json", HTTP_GET, []() { // HTTP.send(200, "application/json", devListHeapJson); From 37cd897257793e371668b9bb7fff98e49aefe9f2 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:05:09 +0200 Subject: [PATCH 17/19] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/myProfile.json | 10 ++++++++-- myProfile.json | 10 ++++++++-- myProfileDef.json | 23 +++++++++++++++++++++-- platformio.ini | 1 + 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 20bdcdf8..d98d0798 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -3,8 +3,14 @@ "name": "IoTmanagerVer4", "apssid": "IoTmanager", "appass": "", - "routerssid": ["iot","wifi"], - "routerpass": ["hostel3333","pswd"], + "routerssid": [ + "iot", + "wifi" + ], + "routerpass": [ + "hostel3333", + "pswd" + ], "timezone": 2, "ntp": "pool.ntp.org", "weblogin": "admin", diff --git a/myProfile.json b/myProfile.json index 20bdcdf8..d98d0798 100644 --- a/myProfile.json +++ b/myProfile.json @@ -3,8 +3,14 @@ "name": "IoTmanagerVer4", "apssid": "IoTmanager", "appass": "", - "routerssid": ["iot","wifi"], - "routerpass": ["hostel3333","pswd"], + "routerssid": [ + "iot", + "wifi" + ], + "routerpass": [ + "hostel3333", + "pswd" + ], "timezone": 2, "ntp": "pool.ntp.org", "weblogin": "admin", diff --git a/myProfileDef.json b/myProfileDef.json index cbb608ac..d98d0798 100644 --- a/myProfileDef.json +++ b/myProfileDef.json @@ -3,8 +3,14 @@ "name": "IoTmanagerVer4", "apssid": "IoTmanager", "appass": "", - "routerssid": "iot", - "routerpass": "hostel3333", + "routerssid": [ + "iot", + "wifi" + ], + "routerpass": [ + "hostel3333", + "pswd" + ], "timezone": 2, "ntp": "pool.ntp.org", "weblogin": "admin", @@ -32,6 +38,11 @@ "firmware": "0x00000", "littlefs": "0x300000" }, + { + "name": "esp8266_16mb", + "firmware": "0x00000", + "littlefs": "0x200000" + }, { "name": "esp32_4mb", "boot_app0": "0xe000", @@ -40,6 +51,14 @@ "partitions": "0x8000", "littlefs": "0x290000" }, + { + "name": "esp32_16mb", + "boot_app0": "0xe000", + "bootloader_qio_80m": "0x1000", + "firmware": "0x10000", + "partitions": "0x8000", + "littlefs": "0x910000" + }, { "name": "esp8266_1mb", "firmware": "0x00000000", diff --git a/platformio.ini b/platformio.ini index 154841cb..72fb7ea9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -459,6 +459,7 @@ lib_deps = marcoschwartz/LiquidCrystal_I2C@^1.1.4 https://github.com/maxint-rd/TM16xx adafruit/Adafruit GFX Library @ ^1.11.5 + adafruit/Adafruit BusIO @ ^1.13.2 build_src_filter = + + From d391bbbd63cf97eebb05789c998ade95de78ebcd Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:27:56 +0200 Subject: [PATCH 18/19] =?UTF-8?q?wifi=20=D0=BF=D0=BE=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BC=D1=83=20=D0=BF=D0=BE=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myProfile.json | 10 ++-------- myProfileDef.json | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/myProfile.json b/myProfile.json index d98d0798..0170a5e1 100644 --- a/myProfile.json +++ b/myProfile.json @@ -3,14 +3,8 @@ "name": "IoTmanagerVer4", "apssid": "IoTmanager", "appass": "", - "routerssid": [ - "iot", - "wifi" - ], - "routerpass": [ - "hostel3333", - "pswd" - ], + "routerssid": "iot", + "routerpass": "hostel3333", "timezone": 2, "ntp": "pool.ntp.org", "weblogin": "admin", diff --git a/myProfileDef.json b/myProfileDef.json index d98d0798..0170a5e1 100644 --- a/myProfileDef.json +++ b/myProfileDef.json @@ -3,14 +3,8 @@ "name": "IoTmanagerVer4", "apssid": "IoTmanager", "appass": "", - "routerssid": [ - "iot", - "wifi" - ], - "routerpass": [ - "hostel3333", - "pswd" - ], + "routerssid": "iot", + "routerpass": "hostel3333", "timezone": 2, "ntp": "pool.ntp.org", "weblogin": "admin", From 137a5a43b89c24cb4f98c2de17cad35435d0bf30 Mon Sep 17 00:00:00 2001 From: Mit4el Date: Mon, 2 Oct 2023 23:16:29 +0300 Subject: [PATCH 19/19] bugfix ExternalMqtt --- src/MqttClient.cpp | 9 ++++++--- src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index cfc5e8c2..48697b8c 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -121,13 +121,16 @@ void mqttSubscribe() { } void mqttSubscribeExternal(String topic, bool usePrefix) { - SerialPrint("i", F("MQTT"), ("subscribed external" + topic).c_str()); + // SerialPrint("i", F("MQTT"), mqttRootDevice); + String _sb_topic = topic; if (usePrefix) { - mqtt.subscribe((mqttPrefix + topic).c_str()); + _sb_topic = mqttPrefix + "/" + topic; } - mqtt.subscribe(topic.c_str()); + mqtt.subscribe(_sb_topic.c_str()); + + SerialPrint("i", F("MQTT"), ("subscribed external " + _sb_topic).c_str()); } void mqttCallback(char* topic, uint8_t* payload, size_t length) { diff --git a/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp b/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp index 91da0b9c..a37add87 100644 --- a/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp +++ b/src/modules/sensors/ExternalMQTT/ExternalMQTT.cpp @@ -17,6 +17,7 @@ private: bool _isJson; bool _addPrefix; bool _debug; + bool sendOk = false; public: ExternalMQTT(String parameters) : IoTItem(parameters) @@ -26,10 +27,12 @@ public: jsonRead(parameters, F("red"), red); jsonRead(parameters, F("offline"), offline); _topic = jsonReadStr(parameters, "topic"); - _isJson = jsonReadBool(parameters, "isJson"); - _addPrefix = jsonReadBool(parameters, "addPrefix"); - _debug = jsonReadBool(parameters, "debug"); + jsonRead(parameters, "isJson", _isJson); + jsonRead(parameters, "addPrefix", _addPrefix); + jsonRead(parameters, "debug", _debug); dataFromNode = false; + if (mqttIsConnect()) + sendOk = true; mqttSubscribeExternal(_topic, _addPrefix); } char *TimeToString(unsigned long t) @@ -58,6 +61,7 @@ public: { return; } + if (_isJson) { DynamicJsonDocument doc(JSON_BUFFER_SIZE); @@ -106,6 +110,11 @@ public: { _minutesPassed++; setNewWidgetAttributes(); + if (mqttIsConnect() && !sendOk) + { + sendOk = true; + mqttSubscribeExternal(_topic, _addPrefix); + } } void onMqttWsAppConnectEvent() {