2020-08-25 19:25:54 +03:00
|
|
|
|
2020-08-29 22:14:35 +03:00
|
|
|
#include <SSDP.h>
|
2020-08-25 18:36:05 +03:00
|
|
|
#include "Class/CallBackTest.h"
|
|
|
|
|
#include "Class/NotAsinc.h"
|
2020-08-29 20:17:39 +03:00
|
|
|
#include "Class/ScenarioClass.h"
|
2020-08-29 22:14:35 +03:00
|
|
|
#include "Class/Switch.h"
|
2020-08-24 13:56:12 +03:00
|
|
|
#include "Cmd.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "Init.h"
|
2020-08-29 22:14:35 +03:00
|
|
|
#include "ItemsList.h"
|
2020-08-24 13:56:12 +03:00
|
|
|
#include "Utils/Timings.h"
|
2020-08-29 22:14:35 +03:00
|
|
|
#include "Utils\WebUtils.h"
|
2020-07-26 23:48:19 +02:00
|
|
|
|
|
|
|
|
void not_async_actions();
|
|
|
|
|
|
|
|
|
|
static const char* MODULE = "Main";
|
|
|
|
|
|
|
|
|
|
Timings metric;
|
|
|
|
|
boolean initialized = false;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
WiFi.setAutoConnect(false);
|
|
|
|
|
WiFi.persistent(false);
|
|
|
|
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.flush();
|
|
|
|
|
Serial.println();
|
|
|
|
|
Serial.println("--------------started----------------");
|
|
|
|
|
|
|
|
|
|
setChipId();
|
|
|
|
|
|
2020-08-26 01:03:45 +03:00
|
|
|
myNotAsincActions = new NotAsinc(do_LAST);
|
2020-08-29 20:17:39 +03:00
|
|
|
myScenario = new Scenario();
|
2020-08-26 01:03:45 +03:00
|
|
|
|
2020-07-26 23:48:19 +02:00
|
|
|
pm.info("FS");
|
|
|
|
|
fileSystemInit();
|
|
|
|
|
|
|
|
|
|
pm.info("Config");
|
|
|
|
|
loadConfig();
|
|
|
|
|
|
|
|
|
|
pm.info("Clock");
|
|
|
|
|
clock_init();
|
|
|
|
|
|
|
|
|
|
pm.info("Commands");
|
|
|
|
|
cmd_init();
|
|
|
|
|
|
|
|
|
|
pm.info("Sensors");
|
2020-08-28 02:49:26 +03:00
|
|
|
sensorsInit();
|
2020-07-26 23:48:19 +02:00
|
|
|
|
|
|
|
|
pm.info("Init");
|
|
|
|
|
all_init();
|
|
|
|
|
|
|
|
|
|
pm.info("Network");
|
|
|
|
|
startSTAMode();
|
|
|
|
|
|
|
|
|
|
pm.info("Uptime");
|
|
|
|
|
uptime_init();
|
|
|
|
|
|
2020-08-26 01:03:45 +03:00
|
|
|
pm.info("telemetry");
|
2020-07-26 23:48:19 +02:00
|
|
|
telemetry_init();
|
|
|
|
|
|
|
|
|
|
pm.info("Updater");
|
2020-08-25 18:36:05 +03:00
|
|
|
upgradeInit();
|
2020-07-26 23:48:19 +02:00
|
|
|
|
|
|
|
|
pm.info("HttpServer");
|
|
|
|
|
HttpServer::init();
|
|
|
|
|
|
|
|
|
|
pm.info("WebAdmin");
|
|
|
|
|
web_init();
|
|
|
|
|
|
|
|
|
|
#ifdef UDP_ENABLED
|
|
|
|
|
pm.info("Broadcast UDP");
|
2020-08-25 19:25:54 +03:00
|
|
|
udpInit();
|
2020-07-26 23:48:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
2020-08-28 23:18:18 +03:00
|
|
|
pm.info("Ssdp Init");
|
|
|
|
|
SsdpInit();
|
|
|
|
|
|
2020-08-24 15:09:43 +03:00
|
|
|
ts.add(
|
2020-08-29 23:30:04 +03:00
|
|
|
TEST, 1000 * 60, [&](void*) {
|
|
|
|
|
pm.info(printMemoryStatus());
|
2020-08-25 18:36:05 +03:00
|
|
|
},
|
|
|
|
|
nullptr, true);
|
2020-07-26 23:48:19 +02:00
|
|
|
|
2020-08-24 13:56:12 +03:00
|
|
|
just_load = false;
|
2020-07-26 23:48:19 +02:00
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
if (!initialized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#ifdef OTA_UPDATES_ENABLED
|
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef WS_enable
|
|
|
|
|
ws.cleanupClients();
|
|
|
|
|
#endif
|
2020-08-24 13:56:12 +03:00
|
|
|
#ifdef UDP_ENABLED
|
|
|
|
|
loopUdp();
|
|
|
|
|
#endif
|
|
|
|
|
timeNow->loop();
|
2020-07-26 23:48:19 +02:00
|
|
|
MqttClient::loop();
|
2020-08-02 01:54:26 +02:00
|
|
|
mySwitch->loop();
|
2020-08-29 20:17:39 +03:00
|
|
|
myScenario->loop();
|
|
|
|
|
//loopScenario();
|
2020-08-26 01:03:45 +03:00
|
|
|
loopCmd();
|
2020-07-26 23:48:19 +02:00
|
|
|
loopSerial();
|
2020-08-29 22:14:35 +03:00
|
|
|
|
2020-08-25 19:25:54 +03:00
|
|
|
myNotAsincActions->loop();
|
2020-07-26 23:48:19 +02:00
|
|
|
ts.update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clock_init() {
|
|
|
|
|
timeNow = new Clock();
|
|
|
|
|
timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp"));
|
|
|
|
|
timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt());
|
|
|
|
|
|
|
|
|
|
ts.add(
|
|
|
|
|
TIME_SYNC, 30000, [&](void*) {
|
|
|
|
|
timeNow->hasSync();
|
|
|
|
|
},
|
|
|
|
|
nullptr, true);
|
|
|
|
|
}
|