From 99134cb6fde32efe887df308405a6f6d8aff65cd Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Thu, 24 Dec 2020 01:41:15 +0100 Subject: [PATCH] dht working --- data/items/items.txt | 12 +++++------- include/items/vSensorDht.h | 7 +++---- src/BufferExecute.cpp | 7 ++----- src/items/vSensorDht.cpp | 6 +++--- src/main.cpp | 13 ++++++------- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/data/items/items.txt b/data/items/items.txt index f9d180b4..8f11e97e 100644 --- a/data/items/items.txt +++ b/data/items/items.txt @@ -9,10 +9,10 @@ 0;analog-adc;id;fillgauge;Сенсоры;Аналоговый;order;pin[0];map[0,1024,0,100];c[1];int[10]* 0;dallas-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];index[0];int[10]* 0;ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;pin[12,13];map[0,500,0,100];c[1];int[10]* -0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht11];c[1];int[10] -0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht11];c[1];int[10]* -0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht22];c[1];int[10] -0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht22];c[1];int[10]* +0;dht;dhtTmp;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht11];c[1];int[10] +0;dht;dhtHum;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht11];c[1];int[10]* +0;dht;dhtTmp;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht22];c[1];int[10] +0;dht;dhtHum;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht22];c[1];int[10]* 0;bme280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1] 0;bme280-hum;id;anydataHum;Сенсоры;Влажность;order;addr[0x76];c[1] 0;bme280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]* @@ -22,6 +22,4 @@ 0;count-down;id;anydata;Таймер;Обратный#отчет;order* 0;inoutput;id;anydata;Вывод;Вывод#uart;order* 0;logging;id;chart;Графики;История;order;val[any];int[60];cnt[100]* -0;uptime;id;anydataTime;Системные;%name%#uptime;order* - - +0;uptime;id;anydataTime;Системные;%name%#uptime;order* \ No newline at end of file diff --git a/include/items/vSensorDht.h b/include/items/vSensorDht.h index b3848c84..dc86d285 100644 --- a/include/items/vSensorDht.h +++ b/include/items/vSensorDht.h @@ -31,13 +31,12 @@ class SensorDht { params _paramsTmp; params _paramsHum; - unsigned int interval; - + unsigned int _interval; + unsigned long prevMillis; unsigned long difference; }; extern MySensorDhtVector* mySensorDht; -extern void dhtTmp(); -extern void dhtHum(); \ No newline at end of file +extern void dhtSensor(); \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 11cd2a00..5ac53b74 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -74,11 +74,8 @@ void csvCmdExecute(String& cmdStr) { sCmd.addCommand(order.c_str(), dallas); } #ifdef SensorDhtEnabled - else if (order == F("dht-temp")) { - //sCmd.addCommand(order.c_str(), dhtTmp); - } - else if (order == F("dht-hum")) { - //sCmd.addCommand(order.c_str(), dhtHum); + else if (order == F("dht")) { + sCmd.addCommand(order.c_str(), dhtSensor); } #endif #ifdef SensorBme280Enabled diff --git a/src/items/vSensorDht.cpp b/src/items/vSensorDht.cpp index 18b22f09..64851f51 100644 --- a/src/items/vSensorDht.cpp +++ b/src/items/vSensorDht.cpp @@ -18,15 +18,15 @@ SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) { dht->setup(_paramsTmp.pin, DHTesp::DHT11); - interval = _paramsTmp.interval < _paramsHum.interval ? _paramsTmp.interval : _paramsHum.interval; - interval = interval + dht->getMinimumSamplingPeriod(); + _interval = _paramsTmp.interval < _paramsHum.interval ? _paramsTmp.interval : _paramsHum.interval; + _interval = _interval + dht->getMinimumSamplingPeriod(); } SensorDht::~SensorDht() {} void SensorDht::loop() { difference = millis() - prevMillis; - if (difference >= interval) { + if (difference >= _interval) { prevMillis = millis(); readTmpHum(); } diff --git a/src/main.cpp b/src/main.cpp index 350eca5c..4ae6557e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,8 @@ #include "items/vLogging.h" #include "items/vSensorAnalog.h" #include "items/vSensorDallas.h" -#include "items/vSensorUltrasonic.h" #include "items/vSensorDht.h" +#include "items/vSensorUltrasonic.h" void not_async_actions(); @@ -135,10 +135,9 @@ 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(); - // } - //} + if (mySensorDht != nullptr) { + for (unsigned int i = 0; i < mySensorDht->size(); i++) { + mySensorDht->at(i).loop(); + } + } } \ No newline at end of file