Files
IoTManager/src/Init.cpp

110 lines
2.7 KiB
C++
Raw Normal View History

2020-09-02 22:34:49 +03:00
#include "Global.h"
#include "Init.h"
#include "Cmd.h"
void loadConfig() {
configSetupJson = readFile("config.json", 4096);
configSetupJson.replace(" ", "");
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);
}
void all_init() {
Device_init();
loadScenario();
Timer_countdown_init();
}
void Device_init() {
2020-10-20 22:55:45 +03:00
sensorReadingMap10sec = "";
2020-09-04 00:35:38 +03:00
dallasEnterCounter = -1;
2020-09-02 22:34:49 +03:00
2020-10-10 12:04:40 +03:00
//logging_value_names_list = "";
//enter_to_logging_counter = LOG1 - 1;
2020-09-03 23:29:34 +03:00
//analog_value_names_list = "";
//enter_to_analog_counter = 0;
//dallas_value_name = "";
//enter_to_dallas_counter = 0;
//levelPr_value_name = "";
//ultrasonicCm_value_name = "";
//dhtT_value_name = "";
//dhtH_value_name = "";
//bmp280T_value_name = "";
//bmp280P_value_name = "";
//bme280T_value_name = "";
//bme280P_value_name = "";
//bme280H_value_name = "";
//bme280A_value_name = "";
//int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
//for (int i = 0; i < array_sz; i++) {
// sensors_reading_map[i] = 0;
//}
2020-10-10 12:04:40 +03:00
//for (int i = LOG1; i <= LOG5; i++) {
// ts.remove(i);
//}
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);
}
2020-09-06 23:00:33 +03:00
2020-09-02 22:34:49 +03:00
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);
// }
//}