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
|
|
|
unsigned long UptimeInterval::_uptime_seconds;
|
|
|
|
|
|
|
|
|
|
UptimeInterval myUptime(10);
|
|
|
|
|
|
|
|
|
|
void handle_uptime();
|
|
|
|
|
void handle_statistics();
|
|
|
|
|
|
2020-06-17 23:30:48 +03:00
|
|
|
void All_init() {
|
2020-06-20 14:27:58 +03:00
|
|
|
Device_init();
|
|
|
|
|
Scenario_init();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#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-20 14:27:58 +03:00
|
|
|
SPIFFS.remove("/layout.txt");
|
2020-06-17 23:30:48 +03:00
|
|
|
#endif
|
|
|
|
|
|
2020-06-20 14:27:58 +03:00
|
|
|
txtExecution("firmware.c.txt");
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
void Scenario_init() {
|
2020-06-20 14:27:58 +03:00
|
|
|
if (jsonReadStr(configSetupJson, "scen") == "1") {
|
|
|
|
|
scenario = readFile("firmware.s.txt", 2048);
|
|
|
|
|
}
|
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);
|
|
|
|
|
ts.add(
|
|
|
|
|
STATISTICS, statistics_update, [&](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-20 14:27:58 +03:00
|
|
|
if (myUptime.check()) {
|
|
|
|
|
jsonWriteStr(configSetupJson, "uptime", prettyMillis());
|
|
|
|
|
}
|
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();
|
|
|
|
|
//Serial.println(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: ";
|
|
|
|
|
urls += String(firmware_version);
|
|
|
|
|
//-----------------------------------------------------------------
|
|
|
|
|
String stat = getURL(urls);
|
|
|
|
|
//Serial.println(stat);
|
|
|
|
|
}
|
2020-06-19 22:14:50 +02:00
|
|
|
}
|