Files
IoTManager/src/main.cpp

189 lines
5.0 KiB
C++
Raw Normal View History

2020-09-02 22:34:49 +03:00
#include <SSDP.h>
2020-09-06 23:00:33 +03:00
2020-09-04 18:58:03 +03:00
#include "BufferExecute.h"
2020-11-01 04:48:35 +03:00
#include "Bus.h"
2020-09-02 22:34:49 +03:00
#include "Class/CallBackTest.h"
2020-10-18 09:52:17 +03:00
#include "Class/NotAsync.h"
2020-11-07 01:11:32 +03:00
#include "Class/ScenarioClass3.h"
2020-09-02 22:34:49 +03:00
#include "Cmd.h"
#include "Global.h"
#include "Init.h"
#include "ItemsList.h"
2020-11-01 04:48:35 +03:00
#include "RemoteOrdersUdp.h"
#include "Utils/StatUtils.h"
2020-09-02 22:34:49 +03:00
#include "Utils/Timings.h"
2020-10-18 09:52:17 +03:00
#include "Utils/WebUtils.h"
2020-09-03 23:29:34 +03:00
#include "items/ButtonInClass.h"
2020-11-15 01:44:25 +03:00
#include "items/vLogging.h"
#include "items/vImpulsOut.h"
#include "items/vSensorDallas.h"
2020-11-18 03:25:05 +03:00
#include "items/vCountDown.h"
2020-12-06 00:34:30 +03:00
#include "items/vSensorUltrasonic.h"
2020-11-04 23:48:21 +03:00
#include "Telegram.h"
2020-12-06 02:08:37 +03:00
#include "SoftUART.h"
2020-11-01 16:50:44 +03:00
2020-09-02 22:34:49 +03:00
void not_async_actions();
Timings metric;
boolean initialized = false;
void setup() {
WiFi.setAutoConnect(false);
WiFi.persistent(false);
Serial.begin(115200);
Serial.flush();
Serial.println();
2020-11-17 01:01:42 +03:00
Serial.println(F("--------------started----------------"));
2020-09-02 22:34:49 +03:00
setChipId();
2020-10-18 09:52:17 +03:00
myNotAsyncActions = new NotAsync(do_LAST);
2020-09-02 22:34:49 +03:00
myScenario = new Scenario();
fileSystemInit();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("FS"), F("FS Init"));
2020-09-02 22:34:49 +03:00
loadConfig();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Conf"), F("Config Init"));
2020-09-02 22:34:49 +03:00
clock_init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Time"), F("Clock Init"));
2020-09-02 22:34:49 +03:00
2020-11-04 23:48:21 +03:00
handle_time_init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Time"), F("Handle time init"));
2020-09-02 22:34:49 +03:00
sensorsInit();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Sensors"), F("Sensors Init"));
2020-09-02 22:34:49 +03:00
itemsListInit();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Items"), F("Items Init"));
2020-09-02 22:34:49 +03:00
all_init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Init"), F("Init Init"));
2020-09-02 22:34:49 +03:00
2020-10-02 01:14:45 +03:00
routerConnect();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("WIFI"), F("Network Init"));
2020-11-04 23:48:21 +03:00
telegramInit();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Telegram"), F("Telegram Init"));
2020-09-02 22:34:49 +03:00
uptime_init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Uptime"), F("Uptime Init"));
2020-09-02 22:34:49 +03:00
upgradeInit();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Update"), F("Updater Init"));
2020-09-02 22:34:49 +03:00
HttpServer::init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
2020-09-02 22:34:49 +03:00
web_init();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Web"), F("WebAdmin Init"));
2020-09-02 22:34:49 +03:00
2020-09-06 23:00:33 +03:00
initSt();
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Stat"), F("Stat Init"));
2020-11-01 04:48:35 +03:00
#ifdef UDP_ENABLED
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("UDP"), "Udp Init");
2020-11-01 02:52:57 +03:00
asyncUdpInit();
2020-11-01 04:48:35 +03:00
#endif
2020-09-18 00:24:07 +03:00
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("Bus"), F("Bus Init"));
2020-09-18 00:24:07 +03:00
busInit();
2020-12-06 02:08:37 +03:00
SerialPrint("I", F("UART"), F("UART Init"));
uartInit();
2020-10-19 01:21:20 +03:00
#ifdef SSDP_ENABLED
2020-11-17 01:01:42 +03:00
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
2020-09-03 02:08:11 +03:00
SsdpInit();
2020-09-03 23:29:34 +03:00
#endif
2020-09-02 22:34:49 +03:00
2020-10-19 01:21:20 +03:00
//esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
2020-09-02 22:34:49 +03:00
ts.add(
2020-11-19 04:14:52 +03:00
SYGNAL, 1000 * 60, [&](void*) {
SerialPrint("I", "System", printMemoryStatus());
2020-11-17 01:01:42 +03:00
switch (RSSIquality()) {
case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
break;
case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
break;
case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
break;
case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
break;
case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
break;
case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
break;
case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
break;
}
2020-09-02 22:34:49 +03:00
},
nullptr, true);
2020-11-19 04:14:52 +03:00
2020-09-02 22:34:49 +03:00
just_load = false;
2020-11-16 13:58:26 +03:00
initialized = true;
2020-09-02 22:34:49 +03:00
}
void loop() {
if (!initialized) {
return;
}
#ifdef OTA_UPDATES_ENABLED
ArduinoOTA.handle();
#endif
#ifdef WS_enable
ws.cleanupClients();
#endif
timeNow->loop();
2020-10-02 01:14:45 +03:00
mqttLoop();
2020-09-03 02:07:12 +03:00
myButtonIn.loop();
2020-09-02 22:34:49 +03:00
myScenario->loop();
2020-09-04 18:58:03 +03:00
loopCmdExecute();
//loopSerial();
2020-09-02 22:34:49 +03:00
2020-10-18 09:52:17 +03:00
myNotAsyncActions->loop();
2020-09-02 22:34:49 +03:00
ts.update();
2020-11-04 23:48:21 +03:00
handleTelegram();
2020-12-06 02:08:37 +03:00
uartHandle();
2020-11-01 00:03:08 +03:00
if (myLogging != nullptr) {
for (unsigned int i = 0; i < myLogging->size(); i++) {
myLogging->at(i).loop();
}
}
2020-11-01 16:50:44 +03:00
if (myImpulsOut != nullptr) {
for (unsigned int i = 0; i < myImpulsOut->size(); i++) {
myImpulsOut->at(i).loop();
}
}
2020-11-03 19:07:22 +03:00
if (mySensorDallas2 != nullptr) {
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
mySensorDallas2->at(i).loop();
}
}
2020-12-06 00:34:30 +03:00
if (mySensorUltrasonic != nullptr) {
for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) {
mySensorUltrasonic->at(i).loop();
}
}
2020-11-18 03:25:05 +03:00
if (myCountDown != nullptr) {
for (unsigned int i = 0; i < myCountDown->size(); i++) {
myCountDown->at(i).loop();
}
}
2020-10-20 23:58:23 +03:00
}