mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
in progress not working version!!!
This commit is contained in:
@@ -75,10 +75,10 @@ void csvCmdExecute(String& cmdStr) {
|
||||
}
|
||||
#ifdef SensorDhtEnabled
|
||||
else if (order == F("dht-temp")) {
|
||||
sCmd.addCommand(order.c_str(), dhtTmp);
|
||||
//sCmd.addCommand(order.c_str(), dhtTmp);
|
||||
}
|
||||
else if (order == F("dht-hum")) {
|
||||
sCmd.addCommand(order.c_str(), dhtHum);
|
||||
//sCmd.addCommand(order.c_str(), dhtHum);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBme280Enabled
|
||||
|
||||
@@ -59,8 +59,7 @@ int countDown_EnterCounter = -1;
|
||||
String logging_KeyList = "";
|
||||
int logging_EnterCounter = -1;
|
||||
//=========================================
|
||||
int dhtTmp_EnterCounter = -1;
|
||||
int dhtHum_EnterCounter = -1;
|
||||
int dht_EnterCounter = -1;
|
||||
//=========================================
|
||||
|
||||
// Sensors
|
||||
|
||||
@@ -92,8 +92,7 @@ void deviceInit() {
|
||||
countDown_KeyList = "";
|
||||
countDown_EnterCounter = -1;
|
||||
//===================================
|
||||
dhtTmp_EnterCounter = -1;
|
||||
dhtHum_EnterCounter = -1;
|
||||
dht_EnterCounter = -1;
|
||||
//=========================================
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
|
||||
@@ -23,40 +23,43 @@ void itemsListInit() {
|
||||
SerialPrint("I", F("Items"), F("Items Init"));
|
||||
}
|
||||
|
||||
void addItem2(String param) {
|
||||
int num = selectToMarker(param, "-").toInt();
|
||||
void addItem2(int num) {
|
||||
File configFile = FileFS.open("/items/items.txt", "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
String seachingLine;
|
||||
|
||||
int i = 0;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String item = configFile.readStringUntil('\n');
|
||||
int tmpNum = selectToMarker(item, ";").toInt();
|
||||
if (tmpNum == num) {
|
||||
seachingLine = item;
|
||||
i++;
|
||||
String item = configFile.readStringUntil('*');
|
||||
if (i == num) {
|
||||
if (i == 1) {
|
||||
seachingLine = "\n" + item;
|
||||
} else {
|
||||
seachingLine = item;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
configFile.close();
|
||||
|
||||
String name = deleteBeforeDelimiter(param, "-");
|
||||
//while (seachingLine.length()) {
|
||||
//String tmp = selectToMarker(seachingLine, "\n");
|
||||
|
||||
randomSeed(micros());
|
||||
unsigned int rnd = random(0, 1000);
|
||||
seachingLine.replace("id", name + String(rnd));
|
||||
seachingLine.replace("id", String(rnd));
|
||||
seachingLine.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
if (seachingLine.indexOf("gpio") != -1) {
|
||||
seachingLine.replace("gpio", "pin[" + String(getFreePinAll()) + "]");
|
||||
}
|
||||
|
||||
//seachingLine = deleteBeforeDelimiter(seachingLine, ",");
|
||||
//}
|
||||
|
||||
seachingLine = deleteBeforeDelimiter(seachingLine, ";");
|
||||
seachingLine.replace("\r\n", "");
|
||||
seachingLine.replace("\r", "");
|
||||
seachingLine.replace("\n", "");
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + seachingLine);
|
||||
addFile(DEVICE_CONFIG_FILE, seachingLine);
|
||||
Serial.println(seachingLine);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ void web_init() {
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
//==============================set.device.json====================================================================================================
|
||||
if (request->hasArg(F("addItem"))) {
|
||||
addItem2(request->getParam("addItem")->value());
|
||||
addItem2(request->getParam("addItem")->value().toInt());
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,156 +8,104 @@
|
||||
|
||||
DHTesp* dht = nullptr;
|
||||
|
||||
SensorDht::SensorDht() {}
|
||||
SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) {
|
||||
_paramsTmp = params(paramsTmp);
|
||||
_paramsHum = params(paramsHum);
|
||||
|
||||
if (!dht) {
|
||||
dht = new DHTesp();
|
||||
}
|
||||
|
||||
dht->setup(_paramsTmp.pin, DHTesp::DHT11);
|
||||
|
||||
//dht->getMinimumSamplingPeriod()
|
||||
}
|
||||
|
||||
SensorDht::~SensorDht() {}
|
||||
|
||||
void SensorDht::tmpInit(const tmpParams& tmpSet) {
|
||||
_tmpSet = tmpParams(tmpSet);
|
||||
if (!dht) {
|
||||
dht = new DHTesp();
|
||||
}
|
||||
dht->setup(_tmpSet.pin, DHTesp::DHT11);
|
||||
_tmpSet.interval = dht->getMinimumSamplingPeriod() + _tmpSet.interval;
|
||||
}
|
||||
|
||||
void SensorDht::humInit(const humParams& humSet) {
|
||||
_humSet = humParams(humSet);
|
||||
if (!dht) {
|
||||
dht = new DHTesp();
|
||||
}
|
||||
dht->setup(_tmpSet.pin, DHTesp::DHT11);
|
||||
_tmpSet.interval = dht->getMinimumSamplingPeriod() + _tmpSet.interval;
|
||||
}
|
||||
|
||||
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 " + String(counter) + " " + dht->getStatusString());
|
||||
//} 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::loop() {
|
||||
//currentMillis = millis();
|
||||
//difference = currentMillis - prevMillis;
|
||||
//if (difference >= _myParams.interval) {
|
||||
// prevMillis = millis();
|
||||
// readTmpHum();
|
||||
//}
|
||||
}
|
||||
|
||||
void SensorDht::readHum() {
|
||||
float value;
|
||||
static int counter;
|
||||
//if (dht->getStatus() != 0 && counter < 5) {
|
||||
// counter++;
|
||||
// SerialPrint("E", "Sensor", "Disconnected " + String(counter) + " " + dht->getStatusString());
|
||||
void SensorDht::readTmpHum() {
|
||||
//float tmp;
|
||||
//float hum;
|
||||
//tmp = dht->getTemperature();
|
||||
//hum = dht->getHumidity();
|
||||
//
|
||||
//if (String(tmp) != "nan" && String(hum) != "nan") {
|
||||
// if (_myParams.type == "tmp") {
|
||||
// }
|
||||
//
|
||||
// if (_myParams.type == "hum") {
|
||||
// }
|
||||
//
|
||||
// tmp = tmp * _tmpSet.c;
|
||||
// hum = hum * _humSet.c;
|
||||
//
|
||||
// if (_tmpSet.interval > 0) {
|
||||
// eventGen2(_tmpSet.key, String(tmp));
|
||||
// jsonWriteStr(configLiveJson, _tmpSet.key, String(tmp));
|
||||
// publishStatus(_tmpSet.key, String(tmp));
|
||||
// SerialPrint("I", "Sensor", "'" + _tmpSet.key + "' data: " + String(tmp));
|
||||
// }
|
||||
//
|
||||
// if (_humSet.interval > 0) {
|
||||
// eventGen2(_humSet.key, String(hum));
|
||||
// jsonWriteStr(configLiveJson, _humSet.key, String(hum));
|
||||
// publishStatus(_humSet.key, String(hum));
|
||||
// SerialPrint("I", "Sensor", "'" + _humSet.key + "' data: " + String(hum));
|
||||
// }
|
||||
//
|
||||
//} 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));
|
||||
}
|
||||
// SerialPrint("E", "Sensor DHT", "Error");
|
||||
//}
|
||||
}
|
||||
|
||||
//if (dht->getStatus() != 0 && counter < 5) {
|
||||
// counter++;
|
||||
// SerialPrint("E", "Sensor", "Disconnected " + String(counter) + " " + dht->getStatusString());
|
||||
//} else {
|
||||
|
||||
MySensorDhtVector* mySensorDht = nullptr;
|
||||
|
||||
void dhtTmp() {
|
||||
void dhtSensor() {
|
||||
myLineParsing.update();
|
||||
String type = myLineParsing.gtype();
|
||||
String value = myLineParsing.gval();
|
||||
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);
|
||||
static params paramsTmp;
|
||||
static params paramsHum;
|
||||
if (value = "tmp") {
|
||||
paramsTmp.type = type;
|
||||
paramsTmp.value = value;
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.interval = interval.toInt() * 1000;
|
||||
paramsTmp.pin = pin.toInt();
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
if (value = "hum") {
|
||||
paramsHum.type = type;
|
||||
paramsHum.value = value;
|
||||
paramsHum.key = key;
|
||||
paramsHum.interval = interval.toInt() * 1000;
|
||||
paramsHum.pin = pin.toInt();
|
||||
paramsHum.c = c.toFloat();
|
||||
}
|
||||
dht_EnterCounter++;
|
||||
if (dht_EnterCounter == 2) {
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorDht = new MySensorDhtVector();
|
||||
firstTime = false;
|
||||
mySensorDht->push_back(SensorDht(paramsTmp, paramsHum));
|
||||
}
|
||||
}
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -135,10 +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();
|
||||
}
|
||||
}
|
||||
//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