Files
IoTManager/src/Init.cpp

106 lines
2.5 KiB
C++
Raw Normal View History

2020-09-02 22:34:49 +03:00
#include "Init.h"
2020-11-02 01:21:51 +03:00
#include "BufferExecute.h"
2020-11-01 04:48:35 +03:00
#include "Cmd.h"
#include "Global.h"
#include "items/LoggingClass.h"
2020-11-02 15:20:04 +03:00
#include "items/ImpulsOutClass.h"
2020-11-03 19:07:22 +03:00
#include "items/SensorDallas.h"
2020-09-02 22:34:49 +03:00
void loadConfig() {
configSetupJson = readFile("config.json", 4096);
2020-10-21 01:51:13 +03:00
//configSetupJson.replace(" ", "");
2020-09-02 22:34:49 +03:00
configSetupJson.replace("\r\n", "");
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;
Serial.println(configSetupJson);
2020-11-01 02:52:57 +03:00
serverIP = jsonReadStr(configSetupJson, "serverip");
2020-09-02 22:34:49 +03:00
}
void all_init() {
Device_init();
loadScenario();
Timer_countdown_init();
}
void Device_init() {
2020-11-02 15:20:04 +03:00
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-11-02 15:20:04 +03:00
//======clear logging params======
2020-11-01 04:48:35 +03:00
if (myLogging != nullptr) {
myLogging->clear();
}
2020-11-02 01:21:51 +03:00
loggingKeyList = "";
2020-09-02 22:34:49 +03:00
2020-11-02 15:20:04 +03:00
//======clear impuls params=======
if (myImpulsOut != nullptr) {
myImpulsOut->clear();
}
2020-11-02 01:21:51 +03:00
impulsKeyList = "";
impulsEnterCounter = -1;
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-09-04 18:58:03 +03:00
fileCmdExecute(String(DEVICE_CONFIG_FILE));
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);
}
void handle_uptime() {
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
}
2020-09-06 23:00:33 +03:00
//void handle_statistics() {
// if (isNetworkActive()) {
// String urls = "http://backup.privet.lv/visitors/?";
// //-----------------------------------------------------------------
// urls += WiFi.macAddress().c_str();
// urls += "&";
// //-----------------------------------------------------------------
//#ifdef ESP8266
// urls += "iot-manager_esp8266";
//#endif
//#ifdef ESP32
// urls += "iot-manager_esp32";
//#endif
// urls += "&";
//#ifdef ESP8266
// urls += ESP.getResetReason();
//#endif
//#ifdef ESP32
// urls += "Power on";
//#endif
// urls += "&";
// urls += String(FIRMWARE_VERSION);
// String stat = getURL(urls);
// }
//}