Files
IoTManager/src/Init.cpp

121 lines
2.8 KiB
C++
Raw Normal View History

2020-06-18 23:43:06 +02:00
#include "Global.h"
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
void handle_uptime();
void handle_statistics();
2020-06-22 03:11:02 +03:00
void telemetry_init();
2020-06-20 14:27:58 +03:00
2020-06-21 03:43:15 +03:00
void loadConfig() {
2020-06-21 15:20:40 +03:00
configSetupJson = readFile("config.json", 4096);
configSetupJson.replace(" ", "");
configSetupJson.replace("\r\n", "");
2020-06-20 22:51:14 +03:00
jsonWriteStr(configSetupJson, "chipID", chipId);
2020-06-21 03:43:15 +03:00
jsonWriteStr(configSetupJson, "firmware_version", FIRMWARE_VERSION);
2020-06-20 22:51:14 +03:00
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
Serial.println(configSetupJson);
}
2020-06-17 23:30:48 +03:00
void All_init() {
2020-06-20 14:27:58 +03:00
Device_init();
2020-06-25 05:09:11 +03:00
loadScenario();
2020-06-20 14:27:58 +03:00
Timer_countdown_init();
2020-06-17 23:30:48 +03:00
}
void Device_init() {
2020-06-20 14:27:58 +03:00
logging_value_names_list = "";
enter_to_logging_counter = LOG1 - 1;
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
analog_value_names_list = "";
enter_to_analog_counter = 0;
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
levelPr_value_name = "";
ultrasonicCm_value_name = "";
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
dhtT_value_name = "";
dhtH_value_name = "";
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
bmp280T_value_name = "";
bmp280P_value_name = "";
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
bme280T_value_name = "";
bme280P_value_name = "";
bme280H_value_name = "";
bme280A_value_name = "";
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
for (int i = 0; i < array_sz; i++) {
sensors_reading_map[i] = 0;
}
2020-06-17 23:30:48 +03:00
2020-06-20 14:27:58 +03:00
for (int i = LOG1; i <= LOG5; i++) {
ts.remove(i);
}
2020-06-17 23:30:48 +03:00
2020-06-21 03:43:15 +03:00
#ifdef LAYOUT_IN_RAM
2020-06-20 14:27:58 +03:00
all_widgets = "";
2020-06-17 23:30:48 +03:00
#else
2020-06-25 05:09:11 +03:00
removeFile(String("layout.txt"));
2020-06-17 23:30:48 +03:00
#endif
2020-06-25 05:09:11 +03:00
fileExecute(String(DEVICE_CONFIG_FILE));
2020-06-20 14:27:58 +03:00
//outcoming_date();
2020-06-17 23:30:48 +03:00
}
2020-06-19 22:14:50 +02:00
//-------------------------------сценарии-----------------------------------------------------
2020-06-17 23:30:48 +03:00
2020-06-25 05:09:11 +03:00
void loadScenario() {
2020-06-20 14:27:58 +03:00
if (jsonReadStr(configSetupJson, "scen") == "1") {
2020-06-25 05:09:11 +03:00
scenario = readFile(String(DEVICE_SCENARIO_FILE), 2048);
2020-06-20 14:27:58 +03:00
}
2020-06-17 23:30:48 +03:00
}
2020-06-19 22:14:50 +02:00
void uptime_init() {
2020-06-20 14:27:58 +03:00
ts.add(
UPTIME, 5000, [&](void*) {
handle_uptime();
},
nullptr, true);
2020-06-22 03:11:02 +03:00
}
2020-06-21 03:43:15 +03:00
2020-06-22 03:11:02 +03:00
void telemetry_init() {
2020-06-21 03:43:15 +03:00
if (TELEMETRY_UPDATE_INTERVAL) {
ts.add(
STATISTICS, TELEMETRY_UPDATE_INTERVAL, [&](void*) {
handle_statistics();
},
nullptr, true);
}
2020-06-17 23:30:48 +03:00
}
2020-06-19 22:14:50 +02:00
void handle_uptime() {
2020-06-27 01:21:58 +03:00
jsonWriteStr(configSetupJson, "getUptime", timeNow->getUptime());
2020-06-17 23:30:48 +03:00
}
2020-06-19 22:14:50 +02:00
void handle_statistics() {
2020-06-20 14:27:58 +03:00
if (WiFi.status() == WL_CONNECTED) {
String urls = "http://backup.privet.lv/visitors/?";
//-----------------------------------------------------------------
urls += WiFi.macAddress().c_str();
urls += "&";
//-----------------------------------------------------------------
2020-06-17 23:30:48 +03:00
#ifdef ESP8266
2020-06-20 14:27:58 +03:00
urls += "iot-manager_esp8266";
2020-06-17 23:30:48 +03:00
#endif
#ifdef ESP32
2020-06-20 14:27:58 +03:00
urls += "iot-manager_esp32";
2020-06-17 23:30:48 +03:00
#endif
2020-06-20 14:27:58 +03:00
urls += "&";
2020-06-17 23:30:48 +03:00
#ifdef ESP8266
2020-06-20 14:27:58 +03:00
urls += ESP.getResetReason();
2020-06-17 23:30:48 +03:00
#endif
#ifdef ESP32
2020-06-20 14:27:58 +03:00
urls += "Power on";
2020-06-17 23:30:48 +03:00
#endif
2020-06-20 14:27:58 +03:00
urls += "&";
urls += "ver: ";
2020-06-21 03:43:15 +03:00
urls += String(FIRMWARE_VERSION);
2020-06-20 14:27:58 +03:00
String stat = getURL(urls);
}
2020-06-19 22:14:50 +02:00
}