mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
переписан dht
This commit is contained in:
@@ -9,10 +9,10 @@
|
|||||||
9;0;analog-adc;id;fillgauge;Сенсоры;Аналоговый;order;pin[0];map[0,1024,0,100];c[1];int[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]
|
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]
|
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]
|
12;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht11];c[1];int[10]
|
||||||
13;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht11];c[1]
|
13;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht11];c[1];int[10]
|
||||||
14;0;dht-hum;id;anydataHum;Сенсоры;Влажность;order;pin[2];type[dht22];c[1]
|
14;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht22];c[1];int[10]
|
||||||
15;0;dht-temp;id;anydataTemp;Сенсоры;Температура;order;pin[2];type[dht22];c[1]
|
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]
|
16;0;bme280-temp;id;anydataTemp;Сенсоры;Температура;order;addr[0x76];c[1]
|
||||||
17;0;bme280-hum;id;anydataHum;Сенсоры;Влажность;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]
|
18;0;bme280-press;id;anydataPress;Сенсоры;Давление;order;addr[0x76];c[1]
|
||||||
|
|||||||
@@ -12,19 +12,7 @@ extern int getKeyNum(String& key, String& keyNumberTable);
|
|||||||
extern void buttonIn();
|
extern void buttonIn();
|
||||||
extern void buttonInSet();
|
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 bme280Temp();
|
||||||
extern void bme280ReadingTemp();
|
extern void bme280ReadingTemp();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <Bounce2.h>
|
#include <Bounce2.h>
|
||||||
#include <DHTesp.h>
|
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
@@ -89,6 +88,9 @@ extern int countDown_EnterCounter;
|
|||||||
extern String logging_KeyList;
|
extern String logging_KeyList;
|
||||||
extern int logging_EnterCounter;
|
extern int logging_EnterCounter;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
extern int dhtTmp_EnterCounter;
|
||||||
|
extern int dhtHum_EnterCounter;
|
||||||
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
extern String sensorReadingMap10sec;
|
extern String sensorReadingMap10sec;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
//#pragma once
|
|
||||||
//#include <Arduino.h>
|
|
||||||
//
|
|
||||||
//#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;
|
|
||||||
@@ -1,80 +1,80 @@
|
|||||||
#pragma once
|
//#pragma once
|
||||||
#include "Consts.h"
|
//#include "Consts.h"
|
||||||
#ifdef SensorDhtEnabled
|
//#ifdef SensorDhtEnabled
|
||||||
#include <Arduino.h>
|
//#include <Arduino.h>
|
||||||
#include "Class/LineParsing.h"
|
//#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
//#include "Global.h"
|
||||||
#include "items/SensorConvertingClass.h"
|
//#include "items/SensorConvertingClass.h"
|
||||||
|
//
|
||||||
DHTesp dht;
|
//DHTesp dht;
|
||||||
class SensorDhtClass : public SensorConvertingClass {
|
//class SensorDhtClass : public SensorConvertingClass {
|
||||||
public:
|
// public:
|
||||||
SensorDhtClass() : SensorConvertingClass(){};
|
// SensorDhtClass() : SensorConvertingClass(){};
|
||||||
|
//
|
||||||
void SensorDhtInit() {
|
// void SensorDhtInit() {
|
||||||
if (_type == "dht11") {
|
// if (_type == "dht11") {
|
||||||
dht.setup(_pin.toInt(), DHTesp::DHT11);
|
// dht.setup(_pin.toInt(), DHTesp::DHT11);
|
||||||
}
|
// }
|
||||||
if (_type == "dht22") {
|
// if (_type == "dht22") {
|
||||||
dht.setup(_pin.toInt(), DHTesp::DHT22);
|
// dht.setup(_pin.toInt(), DHTesp::DHT22);
|
||||||
}
|
// }
|
||||||
sensorReadingMap10sec += _key + ",";
|
// sensorReadingMap10sec += _key + ",";
|
||||||
|
//
|
||||||
//to do если надо будет читать несколько dht
|
// //to do если надо будет читать несколько dht
|
||||||
//dhtEnterCounter++;
|
// //dhtEnterCounter++;
|
||||||
//jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
// //jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||||
|
//
|
||||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void SensorDhtReadTemp(String key) {
|
// void SensorDhtReadTemp(String key) {
|
||||||
//to do если надо будет читать несколько dht
|
// //to do если надо будет читать несколько dht
|
||||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
// //int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||||
float value;
|
// float value;
|
||||||
static int counter;
|
// static int counter;
|
||||||
if (dht.getStatus() != 0 && counter < 5) {
|
// if (dht.getStatus() != 0 && counter < 5) {
|
||||||
counter++;
|
// counter++;
|
||||||
//return;
|
// //return;
|
||||||
} else {
|
// } else {
|
||||||
counter = 0;
|
// counter = 0;
|
||||||
value = dht.getTemperature();
|
// value = dht.getTemperature();
|
||||||
if (String(value) != "nan") {
|
// if (String(value) != "nan") {
|
||||||
//value = this->mapping(key, value);
|
// //value = this->mapping(key, value);
|
||||||
float valueFl = this->correction(key, value);
|
// float valueFl = this->correction(key, value);
|
||||||
eventGen2(key, String(valueFl));
|
// eventGen2(key, String(valueFl));
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||||
publishStatus(key, String(valueFl));
|
// publishStatus(key, String(valueFl));
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||||
} else {
|
// } else {
|
||||||
Serial.println("[E] sensor '" + key);
|
// Serial.println("[E] sensor '" + key);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void SensorDhtReadHum(String key) {
|
// void SensorDhtReadHum(String key) {
|
||||||
//to do если надо будет читать несколько dht
|
// //to do если надо будет читать несколько dht
|
||||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
// //int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||||
float value;
|
// float value;
|
||||||
static int counter;
|
// static int counter;
|
||||||
if (dht.getStatus() != 0 && counter < 5) {
|
// if (dht.getStatus() != 0 && counter < 5) {
|
||||||
counter++;
|
// counter++;
|
||||||
//return;
|
// //return;
|
||||||
} else {
|
// } else {
|
||||||
counter = 0;
|
// counter = 0;
|
||||||
value = dht.getHumidity();
|
// value = dht.getHumidity();
|
||||||
if (String(value) != "nan") {
|
// if (String(value) != "nan") {
|
||||||
//value = this->mapping(key, value);
|
// //value = this->mapping(key, value);
|
||||||
float valueFl = this->correction(key, value);
|
// float valueFl = this->correction(key, value);
|
||||||
eventGen2(key, String(valueFl));
|
// eventGen2(key, String(valueFl));
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||||
publishStatus(key, String(valueFl));
|
// publishStatus(key, String(valueFl));
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||||
} else {
|
// } else {
|
||||||
Serial.println("[E] sensor '" + key);
|
// Serial.println("[E] sensor '" + key);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
//};
|
||||||
extern SensorDhtClass mySensorDht;
|
//extern SensorDhtClass mySensorDht;
|
||||||
#endif
|
//#endif
|
||||||
63
include/items/vSensorDht.h
Normal file
63
include/items/vSensorDht.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <DHTesp.h>
|
||||||
|
#include "Global.h"
|
||||||
|
#include "GyverFilters.h"
|
||||||
|
|
||||||
|
extern DHTesp* dht;
|
||||||
|
|
||||||
|
class SensorDht;
|
||||||
|
|
||||||
|
typedef std::vector<SensorDht> 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();
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
#include "items/vCountDown.h"
|
#include "items/vCountDown.h"
|
||||||
|
#include "items/vSensorAnalog.h"
|
||||||
|
#include "items/vSensorDht.h"
|
||||||
|
|
||||||
void loopCmdAdd(const String& cmdStr) {
|
void loopCmdAdd(const String& cmdStr) {
|
||||||
if (cmdStr.endsWith(",")) {
|
if (cmdStr.endsWith(",")) {
|
||||||
@@ -73,7 +75,7 @@ void csvCmdExecute(String& cmdStr) {
|
|||||||
}
|
}
|
||||||
#ifdef SensorDhtEnabled
|
#ifdef SensorDhtEnabled
|
||||||
else if (order == F("dht-temp")) {
|
else if (order == F("dht-temp")) {
|
||||||
sCmd.addCommand(order.c_str(), dhtTemp);
|
sCmd.addCommand(order.c_str(), dhtTmp);
|
||||||
}
|
}
|
||||||
else if (order == F("dht-hum")) {
|
else if (order == F("dht-hum")) {
|
||||||
sCmd.addCommand(order.c_str(), dhtHum);
|
sCmd.addCommand(order.c_str(), dhtHum);
|
||||||
@@ -84,7 +86,7 @@ void csvCmdExecute(String& cmdStr) {
|
|||||||
sCmd.addCommand(order.c_str(), bme280Temp);
|
sCmd.addCommand(order.c_str(), bme280Temp);
|
||||||
}
|
}
|
||||||
else if (order == F("bme280-hum")) {
|
else if (order == F("bme280-hum")) {
|
||||||
sCmd.addCommand(order.c_str(), bme280Hum);
|
//sCmd.addCommand(order.c_str(), bme280Hum);
|
||||||
}
|
}
|
||||||
else if (order == F("bme280-press")) {
|
else if (order == F("bme280-press")) {
|
||||||
sCmd.addCommand(order.c_str(), bme280Press);
|
sCmd.addCommand(order.c_str(), bme280Press);
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ void getFSInfo() {
|
|||||||
|
|
||||||
jsonWriteStr(configSetupJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
|
jsonWriteStr(configSetupJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
|
||||||
|
|
||||||
SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes));
|
//SerialPrint("I", F("FS"), "totalBytes=" + String(totalBytes));
|
||||||
SerialPrint("I", F("FS"), "usedBytes=" + String(usedBytes));
|
//SerialPrint("I", F("FS"), "usedBytes=" + String(usedBytes));
|
||||||
SerialPrint("I", F("FS"), "maxOpenFiles=" + String(maxOpenFiles));
|
//SerialPrint("I", F("FS"), "maxOpenFiles=" + String(maxOpenFiles));
|
||||||
SerialPrint("I", F("FS"), "blockSize=" + String(blockSize));
|
//SerialPrint("I", F("FS"), "blockSize=" + String(blockSize));
|
||||||
SerialPrint("I", F("FS"), "pageSize=" + String(pageSize));
|
//SerialPrint("I", F("FS"), "pageSize=" + String(pageSize));
|
||||||
SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength));
|
//SerialPrint("I", F("FS"), "maxPathLength=" + String(maxPathLength));
|
||||||
SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes));
|
//SerialPrint("I", F("FS"), "freeBytes=" + String(freeBytes));
|
||||||
SerialPrint("I", F("FS"), "freePer=" + String(freePer));
|
//SerialPrint("I", F("FS"), "freePer=" + String(freePer));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SerialPrint("E", F("FS"), F("FS info error"));
|
SerialPrint("E", F("FS"), F("FS info error"));
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ int countDown_EnterCounter = -1;
|
|||||||
String logging_KeyList = "";
|
String logging_KeyList = "";
|
||||||
int logging_EnterCounter = -1;
|
int logging_EnterCounter = -1;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
int dhtTmp_EnterCounter = -1;
|
||||||
|
int dhtHum_EnterCounter = -1;
|
||||||
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
String sensorReadingMap10sec;
|
String sensorReadingMap10sec;
|
||||||
|
|||||||
24
src/Init.cpp
24
src/Init.cpp
@@ -1,16 +1,17 @@
|
|||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "items/vLogging.h"
|
|
||||||
#include "items/vImpulsOut.h"
|
|
||||||
#include "items/vButtonOut.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/vSensorDallas.h"
|
||||||
#include "items/vSensorUltrasonic.h"
|
#include "items/vSensorUltrasonic.h"
|
||||||
#include "items/vInOutput.h"
|
|
||||||
#include "items/vPwmOut.h"
|
|
||||||
#include "items/vCountDown.h"
|
|
||||||
|
|
||||||
void loadConfig() {
|
void loadConfig() {
|
||||||
configSetupJson = readFile("config.json", 4096);
|
configSetupJson = readFile("config.json", 4096);
|
||||||
@@ -42,7 +43,6 @@ void espInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deviceInit() {
|
void deviceInit() {
|
||||||
|
|
||||||
sensorReadingMap10sec = "";
|
sensorReadingMap10sec = "";
|
||||||
|
|
||||||
//======clear dallas params======
|
//======clear dallas params======
|
||||||
@@ -92,14 +92,16 @@ void deviceInit() {
|
|||||||
countDown_KeyList = "";
|
countDown_KeyList = "";
|
||||||
countDown_EnterCounter = -1;
|
countDown_EnterCounter = -1;
|
||||||
//===================================
|
//===================================
|
||||||
|
dhtTmp_EnterCounter = -1;
|
||||||
|
dhtHum_EnterCounter = -1;
|
||||||
|
//=========================================
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
all_widgets = "";
|
all_widgets = "";
|
||||||
#else
|
#else
|
||||||
removeFile(String("layout.txt"));
|
removeFile(String("layout.txt"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
myLineParsing.clearErrors();
|
myLineParsing.clearErrors();
|
||||||
|
|
||||||
fileCmdExecute(String(DEVICE_CONFIG_FILE));
|
fileCmdExecute(String(DEVICE_CONFIG_FILE));
|
||||||
@@ -108,8 +110,7 @@ void deviceInit() {
|
|||||||
|
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
jsonWriteStr(configSetupJson, F("warning3"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Обнаружен неверный номер пина</p></font></div>"));
|
jsonWriteStr(configSetupJson, F("warning3"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Обнаружен неверный номер пина</p></font></div>"));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
jsonWriteStr(configSetupJson, F("warning3"), "");
|
jsonWriteStr(configSetupJson, F("warning3"), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,4 +136,3 @@ void uptime_init() {
|
|||||||
void handle_uptime() {
|
void handle_uptime() {
|
||||||
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
|
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,35 +1,35 @@
|
|||||||
#include "Consts.h"
|
//#include "Consts.h"
|
||||||
#ifdef SensorDhtEnabled
|
//#ifdef SensorDhtEnabled
|
||||||
#include "items/SensorDhtClass.h"
|
//#include "items/SensorDhtClass.h"
|
||||||
#include "BufferExecute.h"
|
//#include "BufferExecute.h"
|
||||||
//=========================================DHT Sensor==================================================================
|
////=========================================DHT Sensor==================================================================
|
||||||
//dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1]
|
////dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1]
|
||||||
//dht-hum;id;anydata;Сенсоры;Влажность;order;pin;type[dht11];c[1]
|
////dht-hum;id;anydata;Сенсоры;Влажность;order;pin;type[dht11];c[1]
|
||||||
//=========================================================================================================================================
|
////=========================================================================================================================================
|
||||||
SensorDhtClass mySensorDht;
|
//SensorDhtClass mySensorDht;
|
||||||
void dhtTemp() {
|
//void dhtTemp() {
|
||||||
mySensorDht.update();
|
// mySensorDht.update();
|
||||||
String key = mySensorDht.gkey();
|
// String key = mySensorDht.gkey();
|
||||||
sCmd.addCommand(key.c_str(), dhtReadingTemp);
|
// sCmd.addCommand(key.c_str(), dhtReadingTemp);
|
||||||
mySensorDht.SensorDhtInit();
|
// mySensorDht.SensorDhtInit();
|
||||||
mySensorDht.clear();
|
// mySensorDht.clear();
|
||||||
}
|
//}
|
||||||
void dhtReadingTemp() {
|
//void dhtReadingTemp() {
|
||||||
String key = sCmd.order();
|
// String key = sCmd.order();
|
||||||
mySensorDht.SensorDhtReadTemp(key);
|
// mySensorDht.SensorDhtReadTemp(key);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
void dhtHum() {
|
//void dhtHum() {
|
||||||
mySensorDht.update();
|
// mySensorDht.update();
|
||||||
String key = mySensorDht.gkey();
|
// String key = mySensorDht.gkey();
|
||||||
sCmd.addCommand(key.c_str(), dhtReadingHum);
|
// sCmd.addCommand(key.c_str(), dhtReadingHum);
|
||||||
mySensorDht.SensorDhtInit();
|
// mySensorDht.SensorDhtInit();
|
||||||
mySensorDht.clear();
|
// mySensorDht.clear();
|
||||||
}
|
//}
|
||||||
void dhtReadingHum() {
|
//void dhtReadingHum() {
|
||||||
String key = sCmd.order();
|
// String key = sCmd.order();
|
||||||
mySensorDht.SensorDhtReadHum(key);
|
// mySensorDht.SensorDhtReadHum(key);
|
||||||
}
|
//}
|
||||||
#endif
|
//#endif
|
||||||
161
src/items/vSensorDht.cpp
Normal file
161
src/items/vSensorDht.cpp
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
#include "items/vSensorDht.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "items/vSensorAnalog.h"
|
#include "items/vSensorAnalog.h"
|
||||||
#include "items/vSensorDallas.h"
|
#include "items/vSensorDallas.h"
|
||||||
#include "items/vSensorUltrasonic.h"
|
#include "items/vSensorUltrasonic.h"
|
||||||
|
#include "items/vSensorDht.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -134,4 +135,10 @@ void loop() {
|
|||||||
mySensorAnalog->at(i).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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user