diff --git a/data_esp/edit.htm.gz b/data_esp/edit.htm.gz index 5786121f..d41d10c1 100644 Binary files a/data_esp/edit.htm.gz and b/data_esp/edit.htm.gz differ diff --git a/data_esp/items/items.txt b/data_esp/items/items.txt index b75f01f0..bdacaa1a 100644 --- a/data_esp/items/items.txt +++ b/data_esp/items/items.txt @@ -31,4 +31,6 @@ 0;output-value;txtid;anydata;Вывод;Температура;order* 0;logging;crtid;chart;Графики;История;order;val[any];int[60];cnt[100]* 0;logging;crtid;chart3;Графики;История;order;val[any];int[23:30];cnt[100];st[0]* -0;uptime;uptid;anydataTime;Системные;%name%#uptime;order;int[60]* \ No newline at end of file +0;uptime;uptid;anydataTime;Системные;%name%#uptime;order;int[60]* +0;sht20;tmpid;anydataTemp;Сенсоры;Температура;1;c[1] +0;sht20;humid;anydataHum;Сенсоры;Влажность;2;c[1];int[50]* \ No newline at end of file diff --git a/data_esp/set.device.json.gz b/data_esp/set.device.json.gz index 8be82275..50db98a9 100644 Binary files a/data_esp/set.device.json.gz and b/data_esp/set.device.json.gz differ diff --git a/include/Consts.h b/include/Consts.h index 959e00ff..aa914156 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -70,6 +70,7 @@ #define EnablePwmOut #define EnableSensorAnalog #define EnableSensorBme280 +#define EnableSensorSht20 #define EnableSensorBmp280 #define EnableSensorCcs811 #define EnableSensorDallas diff --git a/include/items/ButtonInClass.h b/include/items/ButtonInClass.h index 8adab9cc..e9719874 100644 --- a/include/items/ButtonInClass.h +++ b/include/items/ButtonInClass.h @@ -20,7 +20,7 @@ class ButtonInClass : public LineParsing { void init() { if (_pin != "") { int number = numberEntering++; - buttons[number].attach(_pin.toInt()); + buttons[number].attach(_pin.toInt(), INPUT); buttons[number].interval(_db.toInt()); but[number] = true; jsonWriteStr(configOptionJson, "switch_num_" + String(number), _key); diff --git a/include/items/vSensorSHT20.h b/include/items/vSensorSHT20.h new file mode 100644 index 00000000..0f79ab0b --- /dev/null +++ b/include/items/vSensorSHT20.h @@ -0,0 +1,40 @@ +#ifdef EnableSensorSht20 +#pragma once +#include +#include "Wire.h" +#include "SHT2x.h" + +#include "Global.h" + +extern SHT2x* sht; + +class SensorSht20; + +typedef std::vector MySensorSht20Vector; + +struct paramsSht { + String key; + unsigned long interval; + float c; +}; + +class SensorSht20 { + public: + SensorSht20(const paramsSht& paramsTmp, const paramsSht& paramsHum); + ~SensorSht20(); + + void loop(); + void read(); + + private: + paramsSht _paramsTmp; + paramsSht _paramsHum; + + unsigned long prevMillis; + unsigned long difference; +}; + +extern MySensorSht20Vector* mySensorSht20; + +extern void sht20Sensor(); +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index af26cc6c..0fbb2bf6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,34 +8,20 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html - -;============================================================================================== -;To choose firmware please use one of definition: -;esp8266_1mb , esp8266_4mb , esp32_4mb , esp8266_mysensors_4mb , esp32_mysensors_4mb [platformio] default_envs = esp32_4mb - - -;data_esp => esp8266_1mb , esp8266_4mb , esp32_4mb -;data_ms => esp8266_mysensors_4mb , esp32_mysensors_4mb -;data_svelte => new web interface (in progress...) data_dir = data_esp -;============================================================================================== - [common_env_data] lib_deps_external = bblanchon/ArduinoJson @5.* knolleary/PubSubClient - - lib_deps_internal = ESP Async WebServer GyverFilters OneWire EspSoftwareSerial - [env:esp8266_4mb] build_flags = -Desp8266_4mb="esp8266_4mb" framework = arduino @@ -54,12 +40,12 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit CCS811 Library milesburton/DallasTemperature + robtillaart/SHT2x@^0.1.1 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 board_build.filesystem = littlefs - [env:esp8266_1mb] build_flags = -Desp8266_1mb="esp8266_1mb" framework = arduino @@ -78,11 +64,11 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit CCS811 Library milesburton/DallasTemperature + robtillaart/SHT2x@^0.1.1 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 - [env:esp8266_mysensors_4mb] build_flags = -Desp8266_mysensors_4mb="esp8266_mysensors_4mb" framework = arduino @@ -96,17 +82,17 @@ lib_deps = ESPAsyncUDP CTBot @2.1.6 MySensors @2.3.2 + robtillaart/SHT2x@^0.1.1 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 board_build.filesystem = littlefs - [env:esp32_4mb] build_flags = -Desp32_4mb="esp32_4mb" framework = arduino board = esp32dev -platform = espressif32 @3.3.0 +platform = espressif32 @3.3.0 lib_deps = ${common_env_data.lib_deps_external} ${common_env_data.lib_deps_internal} @@ -121,16 +107,16 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit CCS811 Library milesburton/DallasTemperature + robtillaart/SHT2x@^0.1.1 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 - [env:esp32_mysensors_4mb] build_flags = -Desp32_mysensors_4mb="esp32_mysensors_4mb" framework = arduino board = esp32dev -platform = espressif32 @3.3.0 +platform = espressif32 @3.3.0 lib_deps = ${common_env_data.lib_deps_external} ${common_env_data.lib_deps_internal} @@ -140,6 +126,7 @@ lib_deps = ESP32 AnalogWrite ESP32Servo MySensors @2.3.2 + robtillaart/SHT2x@^0.1.1 monitor_filters = esp32_exception_decoder upload_speed = 921600 -monitor_speed = 115200 \ No newline at end of file +monitor_speed = 115200 diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index e7972a03..b9c7d6ac 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -12,6 +12,7 @@ #include "items/vPwmOut.h" #include "items/vSensorAnalog.h" #include "items/vSensorBme280.h" +#include "items/vSensorSht20.h" #include "items/vSensorBmp280.h" #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" @@ -110,6 +111,10 @@ void csvCmdExecute(String& cmdStr) { } else if (order == F("bme280")) { #ifdef EnableSensorBme280 sCmd.addCommand(order.c_str(), bme280Sensor); +#endif + } else if (order == F("sht20")) { +#ifdef EnableSensorSht20 + sCmd.addCommand(order.c_str(), sht20Sensor); #endif } else if (order == F("bmp280")) { #ifdef EnableSensorBmp280 diff --git a/src/FSEditor.cpp b/src/FSEditor.cpp index 98be53cd..d7708c57 100644 --- a/src/FSEditor.cpp +++ b/src/FSEditor.cpp @@ -184,21 +184,22 @@ void FSEditor::getDirList(const String &path, String &output) { } #else void FSEditor::getDirList(const String &path, String &output) { - auto dir = _fs.open(path, FILE_READ); + File dir = _fs.open(path.c_str(), FILE_READ); dir.rewindDirectory(); - while (dir.openNextFile()) { - String fname = dir.name(); - if (!path.endsWith("/") && !fname.startsWith("/")) { - fname = "/" + fname; - } - fname = path + fname; - if (isExcluded(_fs, fname.c_str())) { - continue; - } - if (dir.isDirectory()) { - getDirList(fname, output); - continue; - } + File file; + while (file = dir.openNextFile()) { + String fname = file.name(); + //if (!path.endsWith("/") && !fname.startsWith("/")) { + // fname = "/" + fname; + //} + //fname = path + fname; + //if (isExcluded(_fs, fname.c_str())) { + // continue; + //} + //if (dir.isDirectory()) { + // getDirList(fname, output); + // continue; + //} if (output != "[") output += ','; char buf[128]; sprintf(buf, "{\"type\":\"file\",\"name\":\"%s\",\"size\":%d}", fname.c_str(), dir.size()); diff --git a/src/Init.cpp b/src/Init.cpp index 3c9b2055..29a51585 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -13,6 +13,7 @@ #include "items/vPwmOut.h" #include "items/vSensorAnalog.h" #include "items/vSensorBme280.h" +#include "items/vSensorSht20.h" #include "items/vSensorBmp280.h" #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" @@ -187,6 +188,11 @@ void clearVectors() { mySensorBme280->clear(); } #endif +#ifdef EnableSensorSht20 + if (mySensorSht20 != nullptr) { + mySensorSht20->clear(); + } +#endif #ifdef EnableSensorBmp280 if (mySensorBmp280 != nullptr) { mySensorBmp280->clear(); diff --git a/src/items/vSensorSHT20.cpp b/src/items/vSensorSHT20.cpp new file mode 100644 index 00000000..9c58b133 --- /dev/null +++ b/src/items/vSensorSHT20.cpp @@ -0,0 +1,91 @@ +#include "Consts.h" +#ifdef EnableSensorSht20 +#include "items/vSensorSht20.h" + +#include + +#include "BufferExecute.h" +#include "Class/LineParsing.h" +#include "Global.h" + +#include "Wire.h" +#include "SHT2x.h" +SHT2x* sht = nullptr; + +SensorSht20::SensorSht20(const paramsSht& paramsTmp, const paramsSht& paramsHum) { + _paramsTmp = paramsSht(paramsTmp); + _paramsHum = paramsSht(paramsHum); + + if (!sht) { + sht = new SHT2x; + } + + sht->begin(); + + uint8_t stat = sht->getStatus(); + Serial.print(stat, HEX); + Serial.println(); +} + +SensorSht20::~SensorSht20() {} + +void SensorSht20::loop() { + difference = millis() - prevMillis; + if (difference >= _paramsHum.interval) { + prevMillis = millis(); + read(); + } +} + +void SensorSht20::read() { + sht->read(); + + float tmp = sht->getTemperature(); + float hum = sht->getHumidity(); + + tmp = tmp * _paramsTmp.c; + hum = hum * _paramsHum.c; + + eventGen2(_paramsTmp.key, String(tmp)); + jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp)); + publishStatus(_paramsTmp.key, String(tmp)); + SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp)); + + eventGen2(_paramsHum.key, String(hum)); + jsonWriteStr(configLiveJson, _paramsHum.key, String(hum)); + publishStatus(_paramsHum.key, String(hum)); + SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum)); +} + +MySensorSht20Vector* mySensorSht20 = nullptr; + +void sht20Sensor() { + myLineParsing.update(); + String key = myLineParsing.gkey(); + String interval = myLineParsing.gint(); + String c = myLineParsing.gc(); + myLineParsing.clear(); + + static int enterCnt = -1; + enterCnt++; + + static paramsSht paramsTmp; + static paramsSht paramsHum; + + if (enterCnt == 0) { + paramsTmp.key = key; + paramsTmp.c = c.toFloat(); + } + + if (enterCnt == 1) { + paramsHum.key = key; + paramsHum.c = c.toFloat(); + paramsHum.interval = interval.toInt() * 1000; + + static bool firstTime = true; + if (firstTime) mySensorSht20 = new MySensorSht20Vector(); + firstTime = false; + mySensorSht20->push_back(SensorSht20(paramsTmp, paramsHum)); + } +} +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 158435c2..218cf9a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ #include "items/vLogging.h" #include "items/vSensorAnalog.h" #include "items/vSensorBme280.h" +#include "items/vSensorSht20.h" #include "items/vSensorBmp280.h" #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" @@ -173,6 +174,13 @@ void loop() { } } #endif +#ifdef EnableSensorSht20 + if (mySensorSht20 != nullptr) { + for (unsigned int i = 0; i < mySensorSht20->size(); i++) { + mySensorSht20->at(i).loop(); + } + } +#endif #ifdef EnableSensorBmp280 if (mySensorBmp280 != nullptr) { for (unsigned int i = 0; i < mySensorBmp280->size(); i++) {