Files
IoTManager/src/main.cpp

128 lines
2.4 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-09-02 22:34:49 +03:00
#include "Class/CallBackTest.h"
#include "Class/NotAsinc.h"
#include "Class/ScenarioClass.h"
2020-09-15 23:50:08 +03:00
#include "Utils/StatUtils.h"
2020-09-02 22:34:49 +03:00
#include "Cmd.h"
#include "Global.h"
#include "Init.h"
#include "ItemsList.h"
#include "Utils/Timings.h"
#include "Utils\WebUtils.h"
2020-09-03 23:29:34 +03:00
#include "items/ButtonInClass.h"
2020-09-02 22:34:49 +03: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();
myNotAsincActions = new NotAsinc(do_LAST);
myScenario = new Scenario();
pm.info("FS");
fileSystemInit();
pm.info("Config");
loadConfig();
pm.info("Clock");
clock_init();
pm.info("Commands");
cmd_init();
pm.info("Sensors");
sensorsInit();
pm.info("Init");
all_init();
pm.info("Network");
startSTAMode();
pm.info("Uptime");
uptime_init();
pm.info("Updater");
upgradeInit();
pm.info("HttpServer");
HttpServer::init();
pm.info("WebAdmin");
web_init();
2020-09-06 23:00:33 +03:00
initSt();
2020-09-02 22:34:49 +03:00
#ifdef UDP_ENABLED
pm.info("Broadcast UDP");
udpInit();
#endif
2020-09-04 18:58:03 +03:00
#ifdef SSDP_EN
2020-09-03 02:08:11 +03:00
pm.info("Ssdp Init");
SsdpInit();
2020-09-03 23:29:34 +03:00
#endif
2020-09-02 22:34:49 +03:00
ts.add(
TEST, 1000 * 60, [&](void*) {
pm.info(printMemoryStatus());
2020-09-16 15:16:01 +03:00
2020-09-02 22:34:49 +03:00
},
nullptr, true);
just_load = false;
2020-09-15 23:50:08 +03:00
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
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
#ifdef UDP_ENABLED
loopUdp();
#endif
timeNow->loop();
MqttClient::loop();
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
myNotAsincActions->loop();
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);
}