mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Gisteresis termostat
This commit is contained in:
@@ -55,14 +55,16 @@ int pwmOut_EnterCounter = -1;
|
||||
String countDown_KeyList = "";
|
||||
int countDown_EnterCounter = -1;
|
||||
//=========================================
|
||||
String logging_KeyList = "";
|
||||
int logging_EnterCounter = -1;
|
||||
//=========================================
|
||||
|
||||
// Sensors
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
// Logging
|
||||
String loggingKeyList;
|
||||
int enter_to_logging_counter;
|
||||
String itemName;
|
||||
String presetName;
|
||||
|
||||
// Upgrade
|
||||
String serverIP;
|
||||
|
||||
@@ -52,7 +52,8 @@ void Device_init() {
|
||||
if (myLogging != nullptr) {
|
||||
myLogging->clear();
|
||||
}
|
||||
loggingKeyList = "";
|
||||
logging_KeyList = "";
|
||||
logging_EnterCounter = -1;
|
||||
//======clear impuls params=======
|
||||
if (myImpulsOut != nullptr) {
|
||||
myImpulsOut->clear();
|
||||
|
||||
@@ -18,36 +18,56 @@ void itemsListInit() {
|
||||
delChoosingItems();
|
||||
},
|
||||
nullptr);
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
myNotAsyncActions->add(
|
||||
do_addItem, [&](void*) {
|
||||
addItem(itemName);
|
||||
itemName = "";
|
||||
},
|
||||
nullptr);
|
||||
|
||||
myNotAsyncActions->add(
|
||||
do_addPreset, [&](void*) {
|
||||
addPreset(presetName);
|
||||
presetName = "";
|
||||
},
|
||||
nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void addItem(String name) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
String url = serverIP + F("/projects/iotmanager/config/items/") + name + ".txt";
|
||||
String item = getURL(url);
|
||||
Serial.println(url);
|
||||
Serial.println(item);
|
||||
if (item == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
#endif
|
||||
|
||||
name = selectToMarker(name, "-");
|
||||
|
||||
randomSeed(micros());
|
||||
unsigned int num = random(0, 1000);
|
||||
|
||||
item.replace("id", name + String(num)); // "-" + String(getNewElementNumber("id.txt")));
|
||||
item.replace("id", name + String(num));
|
||||
item.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
if (item.indexOf("pin") != -1) { //all cases (random pins from available)
|
||||
item.replace("pin", "pin[" + String(getFreePinAll()) + "]");
|
||||
} else
|
||||
|
||||
if (item.indexOf("gol") != -1) { //analog
|
||||
}
|
||||
else if (item.indexOf("gol") != -1) { //analog
|
||||
item.replace("gol", "pin[" + String(getFreePinAnalog()) + "]");
|
||||
} else
|
||||
|
||||
if (item.indexOf("cin") != -1) { //ultrasonic
|
||||
}
|
||||
else if (item.indexOf("cin") != -1) { //ultrasonic
|
||||
item.replace("cin", "pin[" + String(getFreePinAll()) + "," + String(getFreePinAll()) + "]");
|
||||
} else
|
||||
|
||||
if (item.indexOf("sal") != -1) { //dallas
|
||||
}
|
||||
else if (item.indexOf("sal") != -1) { //dallas
|
||||
item.replace("sal", "pin[2]");
|
||||
} else
|
||||
|
||||
if (item.indexOf("thd") != -1) { //dht11/22
|
||||
}
|
||||
else if (item.indexOf("thd") != -1) { //dht11/22
|
||||
item.replace("thd", "pin[2]");
|
||||
}
|
||||
|
||||
@@ -58,12 +78,32 @@ void addItem(String name) {
|
||||
}
|
||||
|
||||
void addPreset(String name) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
String url2 = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
||||
String preset = getURL(url2);
|
||||
Serial.println(url2);
|
||||
Serial.println(preset);
|
||||
if (preset == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||
#endif
|
||||
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||
|
||||
name.replace(".c",".s");
|
||||
name.replace(".c", ".s");
|
||||
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
String url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
||||
String scenario = getURL(url);
|
||||
Serial.println(url);
|
||||
Serial.println(scenario);
|
||||
if (scenario == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||
#endif
|
||||
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||
loadScenario();
|
||||
@@ -89,16 +129,17 @@ uint8_t getNewElementNumber(String file) {
|
||||
|
||||
uint8_t getFreePinAll() {
|
||||
#ifdef ESP8266
|
||||
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
|
||||
uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 };
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
|
||||
uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 };
|
||||
#endif
|
||||
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
|
||||
uint8_t i = getNewElementNumber("pins.txt");
|
||||
if (i < array_sz) {
|
||||
return pins[i];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +162,8 @@ void delChoosingItems() {
|
||||
String item = configFile.readStringUntil('\n');
|
||||
if (firstLine) {
|
||||
finalConf += item;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int checkbox = selectToMarker(item, ";").toInt();
|
||||
if (checkbox == 0) {
|
||||
finalConf += "\n" + item;
|
||||
|
||||
@@ -42,11 +42,11 @@ void getLastVersion() {
|
||||
#endif
|
||||
if (tmp == "error") {
|
||||
lastVersion = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastVersion = tmp.toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastVersion = -2;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ bool upgradeFS() {
|
||||
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
|
||||
SerialPrint("I", "Update", "LittleFS upgrade done!");
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ bool upgradeBuild() {
|
||||
if (retBuild == HTTP_UPDATE_OK) { //если BUILD обновился успешно
|
||||
SerialPrint("I", "Update", "BUILD upgrade done!");
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
18
src/Web.cpp
18
src/Web.cpp
@@ -20,14 +20,24 @@ void web_init() {
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
//==============================set.device.json====================================================================================================
|
||||
if (request->hasArg("addItem")) {
|
||||
String name = request->getParam("addItem")->value();
|
||||
addItem(name);
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
itemName = request->getParam("addItem")->value();
|
||||
myNotAsyncActions->make(do_addItem);
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
addItem(request->getParam("addItem")->value());
|
||||
#endif
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("addPreset")) {
|
||||
String name = request->getParam("addPreset")->value();
|
||||
addPreset(name);
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
presetName = request->getParam("addPreset")->value();
|
||||
myNotAsyncActions->make(do_addPreset);
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
addPreset(request->getParam("addPreset")->value());
|
||||
#endif
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,13 @@ void inOutputExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
if (value.indexOf(":") == -1) { //если этот текст не время
|
||||
value = getValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
int number = getKeyNum(key, inOutput_KeyList);
|
||||
|
||||
if (myInOutput != nullptr) {
|
||||
|
||||
@@ -16,27 +16,36 @@ LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String
|
||||
LoggingClass::~LoggingClass() {}
|
||||
|
||||
void LoggingClass::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _period) {
|
||||
prevMillis = millis();
|
||||
addNewDelOldData("logs/" + _key + ".txt", _maxPoints, getValue(_loggingValueKey)); //jsonReadStr(configLiveJson , _loggingValueKey));
|
||||
if (_period > 0) {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _period) {
|
||||
prevMillis = millis();
|
||||
execute("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoggingClass::addNewDelOldData(const String filename, size_t maxPoints, String payload) {
|
||||
void LoggingClass::execute(String payload) {
|
||||
|
||||
if (_period > 0) {
|
||||
payload = getValue(_loggingValueKey);
|
||||
}
|
||||
|
||||
String filename = "logs/" + _key + ".txt";
|
||||
String logData = readFile(filename, 5120);
|
||||
|
||||
size_t lines_cnt = itemsCount(logData, "\r\n");
|
||||
|
||||
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " (" + String(lines_cnt, DEC) + ")");
|
||||
|
||||
if ((lines_cnt > maxPoints + 1) || !lines_cnt) {
|
||||
if ((lines_cnt > _maxPoints + 1) || !lines_cnt) {
|
||||
removeFile(filename);
|
||||
lines_cnt = 0;
|
||||
}
|
||||
|
||||
if (payload != "") {
|
||||
if (lines_cnt > maxPoints) {
|
||||
if (lines_cnt > _maxPoints) {
|
||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
|
||||
@@ -61,16 +70,40 @@ void logging() {
|
||||
String maxcnt = myLineParsing.gcnt();
|
||||
myLineParsing.clear();
|
||||
|
||||
loggingKeyList += key + ",";
|
||||
logging_KeyList += key + ",";
|
||||
|
||||
logging_EnterCounter++;
|
||||
addKey(key, logging_KeyList, logging_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myLogging = new MyLoggingVector();
|
||||
firstTime = false;
|
||||
myLogging->push_back(LoggingClass(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
|
||||
|
||||
sCmd.addCommand(key.c_str(), loggingExecute);
|
||||
}
|
||||
|
||||
void loggingExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
value = getValue(value);
|
||||
}
|
||||
|
||||
int number = getKeyNum(key, logging_KeyList);
|
||||
|
||||
if (myLogging != nullptr) {
|
||||
if (number != -1) {
|
||||
myLogging->at(number).execute(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void choose_log_date_and_send() {
|
||||
String all_line = loggingKeyList;
|
||||
String all_line = logging_KeyList;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
sendLogData("logs/" + tmp + ".txt", tmp);
|
||||
|
||||
Reference in New Issue
Block a user