From d9672d17b0708cd082eaad7c6cf16b91b0ba075c Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Mon, 21 Dec 2020 01:46:11 +0100 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=20dht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/items/items.txt | 8 +- include/BufferExecute.h | 12 --- include/Global.h | 4 +- include/items/SensorAnalogClass.h | 36 ------- include/items/SensorDhtClass.h | 160 ++++++++++++++--------------- include/items/vSensorDht.h | 63 ++++++++++++ src/BufferExecute.cpp | 6 +- src/FileSystem.cpp | 16 +-- src/Global.cpp | 3 + src/Init.cpp | 24 ++--- src/items/SensorAnalogClass.cpp | 21 ---- src/items/SensorDhtClass.cpp | 70 ++++++------- src/items/vSensorDht.cpp | 161 ++++++++++++++++++++++++++++++ src/main.cpp | 7 ++ 14 files changed, 380 insertions(+), 211 deletions(-) delete mode 100644 include/items/SensorAnalogClass.h create mode 100644 include/items/vSensorDht.h delete mode 100644 src/items/SensorAnalogClass.cpp create mode 100644 src/items/vSensorDht.cpp diff --git a/data/items/items.txt b/data/items/items.txt index 9e6be090..19622ab8 100644 --- a/data/items/items.txt +++ b/data/items/items.txt @@ -9,10 +9,10 @@ 9;0;analog-adc;id;fillgauge;Сенсоры;Аналоговый;order;pin[0];map[0,1024,0,100];c[1];int[10] 10;0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];index[0];int[10] 11;0;ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;pin[12,13];map[0,500,0,100];c[1];int[10] -12;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht11];c[1] -13;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht11];c[1] -14;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht22];c[1] -15;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht22];c[1] +12;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht11];c[1];int[10] +13;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht11];c[1];int[10] +14;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht22];c[1];int[10] +15;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht22];c[1];int[10] 16;0;bme280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1] 17;0;bme280-hum;id;anydataHum;Сенсоры;Влажность;order;addr[0x76];c[1] 18;0;bme280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1] diff --git a/include/BufferExecute.h b/include/BufferExecute.h index a236e57d..28644b59 100644 --- a/include/BufferExecute.h +++ b/include/BufferExecute.h @@ -12,19 +12,7 @@ extern int getKeyNum(String& key, String& keyNumberTable); extern void buttonIn(); extern void buttonInSet(); -extern void analogAdc(); -extern void analogReading(); -//extern void ultrasonicCm(); -//extern void ultrasonicReading(); - -extern void dallasTemp(); -extern void dallasReading(); - -extern void dhtTemp(); -extern void dhtReadingTemp(); -extern void dhtHum(); -extern void dhtReadingHum(); extern void bme280Temp(); extern void bme280ReadingTemp(); diff --git a/include/Global.h b/include/Global.h index bdd63086..db71e643 100644 --- a/include/Global.h +++ b/include/Global.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -89,6 +88,9 @@ extern int countDown_EnterCounter; extern String logging_KeyList; extern int logging_EnterCounter; //========================================= +extern int dhtTmp_EnterCounter; +extern int dhtHum_EnterCounter; +//========================================= // Sensors extern String sensorReadingMap10sec; diff --git a/include/items/SensorAnalogClass.h b/include/items/SensorAnalogClass.h deleted file mode 100644 index a4007eb4..00000000 --- a/include/items/SensorAnalogClass.h +++ /dev/null @@ -1,36 +0,0 @@ -//#pragma once -//#include -// -//#include "Class/LineParsing.h" -//#include "Global.h" -//#include "items/SensorConvertingClass.h" -// -//class SensorAnalogClass : public SensorConvertingClass { -// public: -// SensorAnalogClass() : SensorConvertingClass(){}; -// -// void SensorAnalogInit() { -// jsonWriteStr(configOptionJson, _key + "_pin", _pin); -// jsonWriteStr(configOptionJson, _key + "_map", _map); -// jsonWriteStr(configOptionJson, _key + "_с", _c); -// } -// -// int SensorAnalogRead(String key, String pin) { -// int value; -//#ifdef ESP32 -// int pinInt = pin.toInt(); -// value = analogRead(pinInt); -//#endif -//#ifdef ESP8266 -// value = analogRead(A0); -//#endif -// value = this->mapping(key, value); -// float valueFl = this->correction(key, value); -// eventGen2(key, String(valueFl)); -// jsonWriteStr(configLiveJson, key, String(valueFl)); -// publishStatus(key, String(valueFl)); -// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); -// return value; -// } -//}; -//extern SensorAnalogClass mySensorAnalog; \ No newline at end of file diff --git a/include/items/SensorDhtClass.h b/include/items/SensorDhtClass.h index 2242ed4e..43cc236e 100644 --- a/include/items/SensorDhtClass.h +++ b/include/items/SensorDhtClass.h @@ -1,80 +1,80 @@ -#pragma once -#include "Consts.h" -#ifdef SensorDhtEnabled -#include -#include "Class/LineParsing.h" -#include "Global.h" -#include "items/SensorConvertingClass.h" - -DHTesp dht; -class SensorDhtClass : public SensorConvertingClass { - public: - SensorDhtClass() : SensorConvertingClass(){}; - - void SensorDhtInit() { - if (_type == "dht11") { - dht.setup(_pin.toInt(), DHTesp::DHT11); - } - if (_type == "dht22") { - dht.setup(_pin.toInt(), DHTesp::DHT22); - } - sensorReadingMap10sec += _key + ","; - - //to do если надо будет читать несколько dht - //dhtEnterCounter++; - //jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter); - - jsonWriteStr(configOptionJson, _key + "_map", _map); - jsonWriteStr(configOptionJson, _key + "_с", _c); - } - - void SensorDhtReadTemp(String key) { - //to do если надо будет читать несколько dht - //int cnt = jsonReadInt(configOptionJson, key + "_num"); - float value; - static int counter; - if (dht.getStatus() != 0 && counter < 5) { - counter++; - //return; - } else { - counter = 0; - value = dht.getTemperature(); - if (String(value) != "nan") { - //value = this->mapping(key, value); - float valueFl = this->correction(key, value); - eventGen2(key, String(valueFl)); - jsonWriteStr(configLiveJson, key, String(valueFl)); - publishStatus(key, String(valueFl)); - SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); - } else { - Serial.println("[E] sensor '" + key); - } - } - } - - void SensorDhtReadHum(String key) { - //to do если надо будет читать несколько dht - //int cnt = jsonReadInt(configOptionJson, key + "_num"); - float value; - static int counter; - if (dht.getStatus() != 0 && counter < 5) { - counter++; - //return; - } else { - counter = 0; - value = dht.getHumidity(); - if (String(value) != "nan") { - //value = this->mapping(key, value); - float valueFl = this->correction(key, value); - eventGen2(key, String(valueFl)); - jsonWriteStr(configLiveJson, key, String(valueFl)); - publishStatus(key, String(valueFl)); - SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); - } else { - Serial.println("[E] sensor '" + key); - } - } - } -}; -extern SensorDhtClass mySensorDht; -#endif \ No newline at end of file +//#pragma once +//#include "Consts.h" +//#ifdef SensorDhtEnabled +//#include +//#include "Class/LineParsing.h" +//#include "Global.h" +//#include "items/SensorConvertingClass.h" +// +//DHTesp dht; +//class SensorDhtClass : public SensorConvertingClass { +// public: +// SensorDhtClass() : SensorConvertingClass(){}; +// +// void SensorDhtInit() { +// if (_type == "dht11") { +// dht.setup(_pin.toInt(), DHTesp::DHT11); +// } +// if (_type == "dht22") { +// dht.setup(_pin.toInt(), DHTesp::DHT22); +// } +// sensorReadingMap10sec += _key + ","; +// +// //to do если надо будет читать несколько dht +// //dhtEnterCounter++; +// //jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter); +// +// jsonWriteStr(configOptionJson, _key + "_map", _map); +// jsonWriteStr(configOptionJson, _key + "_с", _c); +// } +// +// void SensorDhtReadTemp(String key) { +// //to do если надо будет читать несколько dht +// //int cnt = jsonReadInt(configOptionJson, key + "_num"); +// float value; +// static int counter; +// if (dht.getStatus() != 0 && counter < 5) { +// counter++; +// //return; +// } else { +// counter = 0; +// value = dht.getTemperature(); +// if (String(value) != "nan") { +// //value = this->mapping(key, value); +// float valueFl = this->correction(key, value); +// eventGen2(key, String(valueFl)); +// jsonWriteStr(configLiveJson, key, String(valueFl)); +// publishStatus(key, String(valueFl)); +// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); +// } else { +// Serial.println("[E] sensor '" + key); +// } +// } +// } +// +// void SensorDhtReadHum(String key) { +// //to do если надо будет читать несколько dht +// //int cnt = jsonReadInt(configOptionJson, key + "_num"); +// float value; +// static int counter; +// if (dht.getStatus() != 0 && counter < 5) { +// counter++; +// //return; +// } else { +// counter = 0; +// value = dht.getHumidity(); +// if (String(value) != "nan") { +// //value = this->mapping(key, value); +// float valueFl = this->correction(key, value); +// eventGen2(key, String(valueFl)); +// jsonWriteStr(configLiveJson, key, String(valueFl)); +// publishStatus(key, String(valueFl)); +// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); +// } else { +// Serial.println("[E] sensor '" + key); +// } +// } +// } +//}; +//extern SensorDhtClass mySensorDht; +//#endif \ No newline at end of file diff --git a/include/items/vSensorDht.h b/include/items/vSensorDht.h new file mode 100644 index 00000000..744af653 --- /dev/null +++ b/include/items/vSensorDht.h @@ -0,0 +1,63 @@ +#pragma once +#include +#include +#include "Global.h" +#include "GyverFilters.h" + +extern DHTesp* dht; + +class SensorDht; + +typedef std::vector MySensorDhtVector; + +struct tmpParams { + unsigned long currentMillis; + unsigned long prevMillis; + unsigned long difference; + unsigned long interval; + String key; + unsigned int pin; + int map1; + int map2; + int map3; + int map4; + float c; +}; + +struct humParams { + unsigned long currentMillis; + unsigned long prevMillis; + unsigned long difference; + unsigned long interval; + String key; + unsigned int pin; + int map1; + int map2; + int map3; + int map4; + float c; +}; + +class SensorDht { + public: + SensorDht(); + ~SensorDht(); + + void loopTmp(); + void loopHum(); + + void readTmp(); + void readHum(); + + void tmpInit(const tmpParams& tmpSet); + void humInit(const humParams& humSet); + + private: + tmpParams _tmpSet; + humParams _humSet; +}; + +extern MySensorDhtVector* mySensorDht; + +extern void dhtTmp(); +extern void dhtHum(); \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index e0752de6..30bb9b85 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -10,6 +10,8 @@ #include "items/vLogging.h" #include "items/vImpulsOut.h" #include "items/vCountDown.h" +#include "items/vSensorAnalog.h" +#include "items/vSensorDht.h" void loopCmdAdd(const String& cmdStr) { if (cmdStr.endsWith(",")) { @@ -73,7 +75,7 @@ void csvCmdExecute(String& cmdStr) { } #ifdef SensorDhtEnabled else if (order == F("dht-temp")) { - sCmd.addCommand(order.c_str(), dhtTemp); + sCmd.addCommand(order.c_str(), dhtTmp); } else if (order == F("dht-hum")) { sCmd.addCommand(order.c_str(), dhtHum); @@ -84,7 +86,7 @@ void csvCmdExecute(String& cmdStr) { sCmd.addCommand(order.c_str(), bme280Temp); } else if (order == F("bme280-hum")) { - sCmd.addCommand(order.c_str(), bme280Hum); + //sCmd.addCommand(order.c_str(), bme280Hum); } else if (order == F("bme280-press")) { sCmd.addCommand(order.c_str(), bme280Press); diff --git a/src/FileSystem.cpp b/src/FileSystem.cpp index e07fb8c0..2c65f899 100644 --- a/src/FileSystem.cpp +++ b/src/FileSystem.cpp @@ -18,14 +18,14 @@ void getFSInfo() { jsonWriteStr(configSetupJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")"); - SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes)); - SerialPrint("I", F("FS"), "usedBytes=" + String(usedBytes)); - SerialPrint("I", F("FS"), "maxOpenFiles=" + String(maxOpenFiles)); - SerialPrint("I", F("FS"), "blockSize=" + String(blockSize)); - SerialPrint("I", F("FS"), "pageSize=" + String(pageSize)); - SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength)); - SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes)); - SerialPrint("I", F("FS"), "freePer=" + String(freePer)); + //SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes)); + //SerialPrint("I", F("FS"), "usedBytes=" + String(usedBytes)); + //SerialPrint("I", F("FS"), "maxOpenFiles=" + String(maxOpenFiles)); + //SerialPrint("I", F("FS"), "blockSize=" + String(blockSize)); + //SerialPrint("I", F("FS"), "pageSize=" + String(pageSize)); + //SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength)); + //SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes)); + //SerialPrint("I", F("FS"), "freePer=" + String(freePer)); } else { SerialPrint("E", F("FS"), F("FS info error")); diff --git a/src/Global.cpp b/src/Global.cpp index 93db61b1..0e98c22a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -59,6 +59,9 @@ int countDown_EnterCounter = -1; String logging_KeyList = ""; int logging_EnterCounter = -1; //========================================= +int dhtTmp_EnterCounter = -1; +int dhtHum_EnterCounter = -1; +//========================================= // Sensors String sensorReadingMap10sec; diff --git a/src/Init.cpp b/src/Init.cpp index 3a17ef50..983dbc40 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -1,16 +1,17 @@ #include "Init.h" + #include "BufferExecute.h" +#include "Class/LineParsing.h" #include "Cmd.h" #include "Global.h" -#include "Class/LineParsing.h" -#include "items/vLogging.h" -#include "items/vImpulsOut.h" #include "items/vButtonOut.h" +#include "items/vCountDown.h" +#include "items/vImpulsOut.h" +#include "items/vInOutput.h" +#include "items/vLogging.h" +#include "items/vPwmOut.h" #include "items/vSensorDallas.h" #include "items/vSensorUltrasonic.h" -#include "items/vInOutput.h" -#include "items/vPwmOut.h" -#include "items/vCountDown.h" void loadConfig() { configSetupJson = readFile("config.json", 4096); @@ -42,7 +43,6 @@ void espInit() { } void deviceInit() { - sensorReadingMap10sec = ""; //======clear dallas params====== @@ -92,14 +92,16 @@ void deviceInit() { countDown_KeyList = ""; countDown_EnterCounter = -1; //=================================== - + dhtTmp_EnterCounter = -1; + dhtHum_EnterCounter = -1; + //========================================= #ifdef LAYOUT_IN_RAM all_widgets = ""; #else removeFile(String("layout.txt")); #endif - + myLineParsing.clearErrors(); fileCmdExecute(String(DEVICE_CONFIG_FILE)); @@ -108,8 +110,7 @@ void deviceInit() { if (errors > 0) { jsonWriteStr(configSetupJson, F("warning3"), F("

Обнаружен неверный номер пина

")); - } - else { + } else { jsonWriteStr(configSetupJson, F("warning3"), ""); } @@ -135,4 +136,3 @@ void uptime_init() { void handle_uptime() { jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime()); } - diff --git a/src/items/SensorAnalogClass.cpp b/src/items/SensorAnalogClass.cpp deleted file mode 100644 index e8dcc9dd..00000000 --- a/src/items/SensorAnalogClass.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//#include "BufferExecute.h" -//#include "items/SensorAnalogClass.h" -//#ifdef ANALOG_ENABLED -////==============================================Модуль аналогового сенсора=========================================================================================== -////=================================================================================================================================================================== -//SensorAnalogClass mySensorAnalog; -//void analogAdc() { -// mySensorAnalog.update(); -// String key = mySensorAnalog.gkey(); -// sCmd.addCommand(key.c_str(), analogReading); -// sensorReadingMap10sec += key + ","; -// mySensorAnalog.SensorAnalogInit(); -// mySensorAnalog.clear(); -//} -// -//void analogReading() { -// String key = sCmd.order(); -// String pin = jsonReadStr(configOptionJson, key + "_pin"); -// mySensorAnalog.SensorAnalogRead(key, pin); -//} -//#endif \ No newline at end of file diff --git a/src/items/SensorDhtClass.cpp b/src/items/SensorDhtClass.cpp index d0c2e41c..c6f89671 100644 --- a/src/items/SensorDhtClass.cpp +++ b/src/items/SensorDhtClass.cpp @@ -1,35 +1,35 @@ -#include "Consts.h" -#ifdef SensorDhtEnabled -#include "items/SensorDhtClass.h" -#include "BufferExecute.h" -//=========================================DHT Sensor================================================================== -//dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1] -//dht-hum;id;anydata;Сенсоры;Влажность;order;pin;type[dht11];c[1] -//========================================================================================================================================= -SensorDhtClass mySensorDht; -void dhtTemp() { - mySensorDht.update(); - String key = mySensorDht.gkey(); - sCmd.addCommand(key.c_str(), dhtReadingTemp); - mySensorDht.SensorDhtInit(); - mySensorDht.clear(); -} -void dhtReadingTemp() { - String key = sCmd.order(); - mySensorDht.SensorDhtReadTemp(key); -} - - - -void dhtHum() { - mySensorDht.update(); - String key = mySensorDht.gkey(); - sCmd.addCommand(key.c_str(), dhtReadingHum); - mySensorDht.SensorDhtInit(); - mySensorDht.clear(); -} -void dhtReadingHum() { - String key = sCmd.order(); - mySensorDht.SensorDhtReadHum(key); -} -#endif \ No newline at end of file +//#include "Consts.h" +//#ifdef SensorDhtEnabled +//#include "items/SensorDhtClass.h" +//#include "BufferExecute.h" +////=========================================DHT Sensor================================================================== +////dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1] +////dht-hum;id;anydata;Сенсоры;Влажность;order;pin;type[dht11];c[1] +////========================================================================================================================================= +//SensorDhtClass mySensorDht; +//void dhtTemp() { +// mySensorDht.update(); +// String key = mySensorDht.gkey(); +// sCmd.addCommand(key.c_str(), dhtReadingTemp); +// mySensorDht.SensorDhtInit(); +// mySensorDht.clear(); +//} +//void dhtReadingTemp() { +// String key = sCmd.order(); +// mySensorDht.SensorDhtReadTemp(key); +//} +// +// +// +//void dhtHum() { +// mySensorDht.update(); +// String key = mySensorDht.gkey(); +// sCmd.addCommand(key.c_str(), dhtReadingHum); +// mySensorDht.SensorDhtInit(); +// mySensorDht.clear(); +//} +//void dhtReadingHum() { +// String key = sCmd.order(); +// mySensorDht.SensorDhtReadHum(key); +//} +//#endif \ No newline at end of file diff --git a/src/items/vSensorDht.cpp b/src/items/vSensorDht.cpp new file mode 100644 index 00000000..2aa10f24 --- /dev/null +++ b/src/items/vSensorDht.cpp @@ -0,0 +1,161 @@ +#include "items/vSensorDht.h" + +#include + +#include "BufferExecute.h" +#include "Class/LineParsing.h" +#include "Global.h" + +DHTesp* dht = nullptr; + +SensorDht::SensorDht() {} + +SensorDht::~SensorDht() {} + +void SensorDht::tmpInit(const tmpParams& tmpSet) { + _tmpSet = tmpParams(tmpSet); + if (!dht) { + dht = new DHTesp(); + } + dht->setup(_tmpSet.pin, DHTesp::DHT11); +} + +void SensorDht::humInit(const humParams& humSet) { + _humSet = humParams(humSet); + if (!dht) { + dht = new DHTesp(); + } + dht->setup(_tmpSet.pin, DHTesp::DHT11); +} + +void SensorDht::loopTmp() { + _tmpSet.currentMillis = millis(); + _tmpSet.difference = _tmpSet.currentMillis - _tmpSet.prevMillis; + if (_tmpSet.difference >= _tmpSet.interval) { + _tmpSet.prevMillis = millis(); + readTmp(); + } +} + +void SensorDht::loopHum() { + _humSet.currentMillis = millis(); + _humSet.difference = _humSet.currentMillis - _humSet.prevMillis; + if (_humSet.difference >= _humSet.interval) { + _humSet.prevMillis = millis(); + readHum(); + } +} + +void SensorDht::readTmp() { + float value; + static int counter; + if (dht->getStatus() != 0 && counter < 5) { + counter++; + SerialPrint("E", "Sensor", "Disconnected"); + } else { + counter = 0; + value = dht->getTemperature(); + if (String(value) != "nan") { + //value = map(value, _tmpSet.map1, _tmpSet.map2, _tmpSet.map3, _tmpSet.map4); + value = value * _tmpSet.c; + eventGen2(_tmpSet.key, String(value)); + jsonWriteStr(configLiveJson, _tmpSet.key, String(value)); + publishStatus(_tmpSet.key, String(value)); + SerialPrint("I", "Sensor", "'" + _tmpSet.key + "' data: " + String(value)); + } else { + SerialPrint("E", "Sensor", "'" + _tmpSet.key + "' data: " + String(value)); + } + } +} + +void SensorDht::readHum() { + float value; + static int counter; + if (dht->getStatus() != 0 && counter < 5) { + counter++; + SerialPrint("E", "Sensor", "Disconnected"); + } else { + counter = 0; + value = dht->getHumidity(); + if (String(value) != "nan") { + //value = map(value, _humSet.map1, _humSet.map2, _humSet.map3, _humSet.map4); + value = value * _humSet.c; + eventGen2(_humSet.key, String(value)); + jsonWriteStr(configLiveJson, _humSet.key, String(value)); + publishStatus(_humSet.key, String(value)); + SerialPrint("I", "Sensor", "'" + _humSet.key + "' data: " + String(value)); + } else { + SerialPrint("E", "Sensor", "'" + _humSet.key + "' data: " + String(value)); + } + } +} + +MySensorDhtVector* mySensorDht = nullptr; + +void dhtTmp() { + myLineParsing.update(); + String interval = myLineParsing.gint(); + String pin = myLineParsing.gpin(); + String key = myLineParsing.gkey(); + String map = myLineParsing.gmap(); + String c = myLineParsing.gc(); + myLineParsing.clear(); + + int map1 = selectFromMarkerToMarker(map, ",", 0).toInt(); + int map2 = selectFromMarkerToMarker(map, ",", 1).toInt(); + int map3 = selectFromMarkerToMarker(map, ",", 2).toInt(); + int map4 = selectFromMarkerToMarker(map, ",", 3).toInt(); + + tmpParams buf; + + buf.interval = interval.toInt() * 1000; + buf.key = key; + buf.pin = pin.toInt(); + buf.map1 = map1; + buf.map2 = map2; + buf.map3 = map3; + buf.map4 = map4; + buf.c = c.toFloat(); + + dhtTmp_EnterCounter++; + + static bool firstTime = true; + if (firstTime) mySensorDht = new MySensorDhtVector(); + firstTime = false; + mySensorDht->push_back(SensorDht()); + mySensorDht->at(dhtTmp_EnterCounter).tmpInit(buf); +} + +void dhtHum() { + myLineParsing.update(); + String interval = myLineParsing.gint(); + String pin = myLineParsing.gpin(); + String key = myLineParsing.gkey(); + String map = myLineParsing.gmap(); + String c = myLineParsing.gc(); + myLineParsing.clear(); + + int map1 = selectFromMarkerToMarker(map, ",", 0).toInt(); + int map2 = selectFromMarkerToMarker(map, ",", 1).toInt(); + int map3 = selectFromMarkerToMarker(map, ",", 2).toInt(); + int map4 = selectFromMarkerToMarker(map, ",", 3).toInt(); + + humParams buf; + + buf.interval = interval.toInt() * 1000; + buf.key = key; + buf.pin = pin.toInt(); + buf.map1 = map1; + buf.map2 = map2; + buf.map3 = map3; + buf.map4 = map4; + buf.c = c.toFloat(); + + dhtHum_EnterCounter++; + + static bool firstTime = true; + if (firstTime) mySensorDht = new MySensorDhtVector(); + firstTime = false; + mySensorDht->push_back(SensorDht()); + mySensorDht->at(dhtHum_EnterCounter).humInit(buf); +} diff --git a/src/main.cpp b/src/main.cpp index d4673839..b9981f51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ #include "items/vSensorAnalog.h" #include "items/vSensorDallas.h" #include "items/vSensorUltrasonic.h" +#include "items/vSensorDht.h" void not_async_actions(); @@ -134,4 +135,10 @@ void loop() { mySensorAnalog->at(i).loop(); } } + if (mySensorDht != nullptr) { + for (unsigned int i = 0; i < mySensorDht->size(); i++) { + mySensorDht->at(i).loopTmp(); + mySensorDht->at(i).loopHum(); + } + } } \ No newline at end of file