2020-09-02 22:34:49 +03:00
|
|
|
#include "Init.h"
|
2020-12-21 01:46:11 +01:00
|
|
|
|
2020-11-02 01:21:51 +03:00
|
|
|
#include "BufferExecute.h"
|
2020-12-21 01:46:11 +01:00
|
|
|
#include "Class/LineParsing.h"
|
2020-11-01 04:48:35 +03:00
|
|
|
#include "Cmd.h"
|
|
|
|
|
#include "Global.h"
|
2020-11-15 01:44:25 +03:00
|
|
|
#include "items/vButtonOut.h"
|
2020-12-21 01:46:11 +01:00
|
|
|
#include "items/vCountDown.h"
|
|
|
|
|
#include "items/vImpulsOut.h"
|
2020-11-17 01:01:42 +03:00
|
|
|
#include "items/vInOutput.h"
|
2020-12-21 01:46:11 +01:00
|
|
|
#include "items/vLogging.h"
|
2020-11-17 01:01:42 +03:00
|
|
|
#include "items/vPwmOut.h"
|
2020-12-21 01:46:11 +01:00
|
|
|
#include "items/vSensorDallas.h"
|
|
|
|
|
#include "items/vSensorUltrasonic.h"
|
2020-09-02 22:34:49 +03:00
|
|
|
|
|
|
|
|
void loadConfig() {
|
|
|
|
|
configSetupJson = readFile("config.json", 4096);
|
|
|
|
|
configSetupJson.replace("\r\n", "");
|
|
|
|
|
|
2020-11-16 18:47:09 +03:00
|
|
|
configStoreJson = readFile("store.json", 4096);
|
|
|
|
|
configStoreJson.replace("\r\n", "");
|
2020-11-15 01:44:25 +03:00
|
|
|
|
2020-11-17 01:01:42 +03:00
|
|
|
jsonWriteStr(configSetupJson, "warning1", "");
|
|
|
|
|
jsonWriteStr(configSetupJson, "warning2", "");
|
2020-12-18 23:20:42 +01:00
|
|
|
jsonWriteStr(configSetupJson, "warning3", "");
|
2020-11-17 01:01:42 +03:00
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
jsonWriteStr(configSetupJson, "chipID", chipId);
|
2020-09-17 21:33:54 +03:00
|
|
|
jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION);
|
2020-09-02 22:34:49 +03:00
|
|
|
|
|
|
|
|
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
|
|
|
|
|
|
2020-12-10 19:12:15 +03:00
|
|
|
//Serial.println(configSetupJson);
|
2020-11-01 02:52:57 +03:00
|
|
|
|
|
|
|
|
serverIP = jsonReadStr(configSetupJson, "serverip");
|
2020-12-10 19:12:15 +03:00
|
|
|
|
|
|
|
|
SerialPrint("I", F("Conf"), F("Config Json Init"));
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 19:12:15 +03:00
|
|
|
void espInit() {
|
|
|
|
|
deviceInit();
|
2020-09-02 22:34:49 +03:00
|
|
|
loadScenario();
|
2020-12-10 19:12:15 +03:00
|
|
|
SerialPrint("I", F("esp"), F("esp Init"));
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 19:12:15 +03:00
|
|
|
void deviceInit() {
|
2020-11-01 04:48:35 +03:00
|
|
|
sensorReadingMap10sec = "";
|
2020-11-02 15:20:04 +03:00
|
|
|
|
2020-11-03 19:07:22 +03:00
|
|
|
//======clear dallas params======
|
|
|
|
|
if (mySensorDallas2 != nullptr) {
|
|
|
|
|
mySensorDallas2->clear();
|
|
|
|
|
}
|
2020-12-06 00:34:30 +03:00
|
|
|
//======clear ultrasonic params======
|
|
|
|
|
if (mySensorUltrasonic != nullptr) {
|
|
|
|
|
mySensorUltrasonic->clear();
|
|
|
|
|
}
|
2020-11-02 15:20:04 +03:00
|
|
|
//======clear logging params======
|
2020-11-01 04:48:35 +03:00
|
|
|
if (myLogging != nullptr) {
|
|
|
|
|
myLogging->clear();
|
|
|
|
|
}
|
2020-12-09 04:08:36 +03:00
|
|
|
logging_KeyList = "";
|
|
|
|
|
logging_EnterCounter = -1;
|
2020-11-02 15:20:04 +03:00
|
|
|
//======clear impuls params=======
|
|
|
|
|
if (myImpulsOut != nullptr) {
|
|
|
|
|
myImpulsOut->clear();
|
|
|
|
|
}
|
2020-11-13 17:13:50 +03:00
|
|
|
impuls_KeyList = "";
|
|
|
|
|
impuls_EnterCounter = -1;
|
|
|
|
|
//======clear buttonOut params=======
|
|
|
|
|
if (myButtonOut != nullptr) {
|
|
|
|
|
myButtonOut->clear();
|
|
|
|
|
}
|
|
|
|
|
buttonOut_KeyList = "";
|
|
|
|
|
buttonOut_EnterCounter = -1;
|
2020-11-15 01:44:25 +03:00
|
|
|
//======clear input params=======
|
2020-11-17 01:01:42 +03:00
|
|
|
if (myInOutput != nullptr) {
|
|
|
|
|
myInOutput->clear();
|
|
|
|
|
}
|
|
|
|
|
inOutput_KeyList = "";
|
|
|
|
|
inOutput_EnterCounter = -1;
|
|
|
|
|
//======clear pwm params=======
|
2020-12-18 23:20:42 +01:00
|
|
|
#ifdef PwmOutEnable
|
2020-11-17 01:01:42 +03:00
|
|
|
if (myPwmOut != nullptr) {
|
|
|
|
|
myPwmOut->clear();
|
2020-11-15 01:44:25 +03:00
|
|
|
}
|
2020-11-17 01:01:42 +03:00
|
|
|
pwmOut_KeyList = "";
|
|
|
|
|
pwmOut_EnterCounter = -1;
|
2020-12-18 23:20:42 +01:00
|
|
|
#endif
|
2020-11-13 17:13:50 +03:00
|
|
|
//===================================
|
2020-11-18 03:25:05 +03:00
|
|
|
if (myCountDown != nullptr) {
|
|
|
|
|
myCountDown->clear();
|
|
|
|
|
}
|
|
|
|
|
countDown_KeyList = "";
|
|
|
|
|
countDown_EnterCounter = -1;
|
|
|
|
|
//===================================
|
2020-12-22 12:38:05 +01:00
|
|
|
dht_EnterCounter = -1;
|
2020-12-21 01:46:11 +01:00
|
|
|
//=========================================
|
2020-11-02 15:20:04 +03:00
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
#ifdef LAYOUT_IN_RAM
|
|
|
|
|
all_widgets = "";
|
|
|
|
|
#else
|
|
|
|
|
removeFile(String("layout.txt"));
|
|
|
|
|
#endif
|
2020-12-21 01:46:11 +01:00
|
|
|
|
2020-12-18 23:20:42 +01:00
|
|
|
myLineParsing.clearErrors();
|
2020-09-02 22:34:49 +03:00
|
|
|
|
2020-09-04 18:58:03 +03:00
|
|
|
fileCmdExecute(String(DEVICE_CONFIG_FILE));
|
2020-12-18 23:20:42 +01:00
|
|
|
|
|
|
|
|
int errors = myLineParsing.getPinErrors();
|
|
|
|
|
|
2020-12-20 17:08:16 +01:00
|
|
|
if (errors > 0) {
|
2020-12-18 23:20:42 +01:00
|
|
|
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>"));
|
2020-12-21 01:46:11 +01:00
|
|
|
} else {
|
2020-12-18 23:20:42 +01:00
|
|
|
jsonWriteStr(configSetupJson, F("warning3"), "");
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
//outcoming_date();
|
|
|
|
|
}
|
|
|
|
|
//-------------------------------сценарии-----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void loadScenario() {
|
|
|
|
|
if (jsonReadStr(configSetupJson, "scen") == "1") {
|
|
|
|
|
scenario = readFile(String(DEVICE_SCENARIO_FILE), 2048);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uptime_init() {
|
|
|
|
|
ts.add(
|
|
|
|
|
UPTIME, 5000, [&](void*) {
|
|
|
|
|
handle_uptime();
|
|
|
|
|
},
|
|
|
|
|
nullptr, true);
|
2020-12-10 19:12:15 +03:00
|
|
|
SerialPrint("I", F("Uptime"), F("Uptime Init"));
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_uptime() {
|
|
|
|
|
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
|
|
|
|
|
}
|