mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Optimization
This commit is contained in:
6
data/widgets/btn.json
Normal file
6
data/widgets/btn.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"widget": "btn",
|
||||
"icon": "switch",
|
||||
"fill": "outline",
|
||||
"color": "orange"
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/TimeUtils.h"
|
||||
#include "Utils/PrintMessage.h"
|
||||
#include "Global.h"
|
||||
#include "Clock.h"
|
||||
#include "Global.h"
|
||||
#include "Utils/TimeUtils.h"
|
||||
#include "Utils\SerialPrint.h"
|
||||
|
||||
extern void clock_init();
|
||||
|
||||
#ifdef ESP8266
|
||||
#include "sntp.h"
|
||||
#endif
|
||||
|
||||
class Clock {
|
||||
|
||||
|
||||
private:
|
||||
Time_t _time_local;
|
||||
Time_t _time_utc;
|
||||
@@ -39,7 +39,6 @@ class Clock {
|
||||
if (drift > 1) {
|
||||
// Обработать ситуации c дрифтом времени на значительные величины
|
||||
}
|
||||
// TODO сохранять время на флеше
|
||||
|
||||
_unixtime = now;
|
||||
|
||||
@@ -71,27 +70,26 @@ class Clock {
|
||||
|
||||
void startSync() {
|
||||
if (!_configured) {
|
||||
//SerialPrint("I","module","sync to: " + _ntp + " timezone: " + String(_timezone));
|
||||
SerialPrint("I", "NTP", "sync to: " + _ntp + " timezone: " + String(_timezone));
|
||||
setupSntp();
|
||||
_configured = true;
|
||||
// лучше не ждать, проверим в следующий раз
|
||||
return;
|
||||
}
|
||||
_hasSynced = hasTimeSynced();
|
||||
if (_hasSynced) {
|
||||
//SerialPrint("I","module","synced " + getDateDotFormated() + " " + getTime());
|
||||
SerialPrint("I", "NTP", "synced " + getDateDotFormated() + " " + getTime());
|
||||
} else {
|
||||
//SerialPrint("[E]","module","failed to obtain");
|
||||
SerialPrint("E", "NTP", "failed to obtain time");
|
||||
}
|
||||
}
|
||||
|
||||
void setupSntp() {
|
||||
#ifdef ESP2866
|
||||
#ifdef ESP8266
|
||||
sntp_setservername(0, _ntp.c_str());
|
||||
sntp_setservername(1, "ru.pool.ntp.org");
|
||||
sntp_setservername(2, "pool.ntp.org");
|
||||
sntp_stop();
|
||||
sntp_set_timezone(0); // UTC time
|
||||
sntp_set_timezone(0);
|
||||
sntp_init();
|
||||
#else
|
||||
configTime(0, 0, _ntp.c_str(), "ru.pool.ntp.org", "pool.ntp.org");
|
||||
@@ -165,3 +163,4 @@ class Clock {
|
||||
return prettyMillis(_uptime);
|
||||
}
|
||||
};
|
||||
extern Clock* timeNow;
|
||||
@@ -86,7 +86,7 @@ struct Time_t {
|
||||
enum TimerTask_t { WIFI_SCAN,
|
||||
WIFI_MQTT_CONNECTION_CHECK,
|
||||
SENSORS10SEC,
|
||||
SENSORS60SEC,
|
||||
SENSORS30SEC,
|
||||
STEPPER1,
|
||||
STEPPER2,
|
||||
LOG1,
|
||||
|
||||
@@ -1,27 +1,10 @@
|
||||
#pragma once
|
||||
//===================Libraries===================================================================================================================================================
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "ESP32.h"
|
||||
#include "ESP8266.h"
|
||||
|
||||
#include "Consts.h"
|
||||
#include "GyverFilters.h"
|
||||
#include "Upgrade.h"
|
||||
#include "Clock.h"
|
||||
|
||||
#include "MqttClient.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Utils/SysUtils.h"
|
||||
#include "Utils/PrintMessage.h"
|
||||
#include "Utils/WiFiUtils.h"
|
||||
#include "Utils/SerialPrint.h"
|
||||
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <Bounce2.h>
|
||||
#include <DHTesp.h>
|
||||
#include <DallasTemperature.h>
|
||||
@@ -31,27 +14,37 @@
|
||||
#include <TickerScheduler.h>
|
||||
#include <Wire.h>
|
||||
#include <time.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
|
||||
#include "Clock.h"
|
||||
#include "Consts.h"
|
||||
#include "ESP32.h"
|
||||
#include "ESP8266.h"
|
||||
#include "GyverFilters.h"
|
||||
#include "MqttClient.h"
|
||||
#include "Upgrade.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/SerialPrint.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Utils/SysUtils.h"
|
||||
#include "Utils/WiFiUtils.h"
|
||||
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
extern AsyncWebSocket ws;
|
||||
//extern AsyncEventSource events;
|
||||
#endif
|
||||
|
||||
extern Clock* timeNow;
|
||||
|
||||
extern TickerScheduler ts;
|
||||
extern WiFiClient espClient;
|
||||
extern PubSubClient mqtt;
|
||||
extern StringCommand sCmd;
|
||||
extern AsyncWebServer server;
|
||||
extern DallasTemperature sensors;
|
||||
extern OneWire *oneWire;
|
||||
extern OneWire* oneWire;
|
||||
extern boolean but[NUM_BUTTONS];
|
||||
extern Bounce* buttons;
|
||||
|
||||
|
||||
//Global vars
|
||||
extern boolean just_load;
|
||||
|
||||
@@ -74,7 +67,7 @@ extern String itemsLine;
|
||||
|
||||
// Sensors
|
||||
extern String sensorReadingMap10sec;
|
||||
extern String sensorReadingMap60sec;
|
||||
extern String sensorReadingMap30sec;
|
||||
extern int8_t dallasEnterCounter;
|
||||
|
||||
extern String logging_value_names_list;
|
||||
@@ -98,7 +91,6 @@ extern String getURL(const String& urls);
|
||||
extern void do_fscheck();
|
||||
extern void doBusScan();
|
||||
extern void servo_();
|
||||
extern void clock_init();
|
||||
|
||||
extern void setLedStatus(LedStatus_t);
|
||||
|
||||
@@ -106,8 +98,6 @@ extern void setLedStatus(LedStatus_t);
|
||||
extern void eventGen(String event_name, String number);
|
||||
extern String add_set(String param_name);
|
||||
|
||||
|
||||
|
||||
//Timers
|
||||
extern void Timer_countdown_init();
|
||||
extern void timerStart_();
|
||||
@@ -132,8 +122,6 @@ extern void pushControl();
|
||||
//extern void do_udp_data_parse();
|
||||
//extern void do_mqtt_send_settings_to_udp();
|
||||
|
||||
|
||||
|
||||
extern void do_update();
|
||||
|
||||
// Init
|
||||
@@ -141,4 +129,3 @@ extern void uptime_init();
|
||||
|
||||
// Web
|
||||
extern void web_init();
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Utils/TimeUtils.h"
|
||||
#include "Global.h"
|
||||
|
||||
#define pm PrintMessage(MODULE)
|
||||
|
||||
class PrintMessage {
|
||||
public:
|
||||
PrintMessage(const char* module) {
|
||||
_module = module;
|
||||
}
|
||||
|
||||
void error(const String& str) {
|
||||
print(EL_ERROR, str);
|
||||
}
|
||||
|
||||
void info(const String& str) {
|
||||
print(EL_INFO, str);
|
||||
}
|
||||
|
||||
private:
|
||||
void printErrorLevel(ErrorLevel_t level) {
|
||||
Serial.printf("[%c] ", getErrorLevelStr(level));
|
||||
}
|
||||
|
||||
void printUptime() {
|
||||
Serial.printf("%lu ", ((unsigned long)millis() / 1000));
|
||||
}
|
||||
|
||||
void printModule() {
|
||||
Serial.printf("[%s] ", _module);
|
||||
}
|
||||
|
||||
void print(const ErrorLevel_t level, const String& str) {
|
||||
printUptime();
|
||||
printErrorLevel(level);
|
||||
printModule();
|
||||
Serial.println(str.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
const char* _module;
|
||||
};
|
||||
@@ -63,8 +63,8 @@ void sensorsInit() {
|
||||
nullptr, true);
|
||||
|
||||
ts.add(
|
||||
SENSORS60SEC, 60000, [&](void *) {
|
||||
String buf = sensorReadingMap60sec;
|
||||
SENSORS30SEC, 30000, [&](void *) {
|
||||
String buf = sensorReadingMap30sec;
|
||||
while (buf.length()) {
|
||||
String tmp = selectToMarker(buf, ",");
|
||||
sCmd.readStr(tmp);
|
||||
@@ -74,8 +74,3 @@ void sensorsInit() {
|
||||
nullptr, true);
|
||||
}
|
||||
|
||||
//void loopSerial() {
|
||||
// if (term) {
|
||||
// term->loop();
|
||||
// }
|
||||
//}
|
||||
|
||||
16
src/Clock.cpp
Normal file
16
src/Clock.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "Clock.h"
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
Clock* timeNow;
|
||||
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);
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
AsyncWebSocket ws;
|
||||
//AsyncEventSource events;
|
||||
#endif
|
||||
Clock* timeNow;
|
||||
|
||||
TickerScheduler ts(TEST + 1);
|
||||
WiFiClient espClient;
|
||||
PubSubClient mqtt(espClient);
|
||||
@@ -40,7 +40,7 @@ String itemsLine = "";
|
||||
// Sensors
|
||||
int8_t dallasEnterCounter = -1;
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap60sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
// Logging
|
||||
String logging_value_names_list;
|
||||
|
||||
@@ -14,8 +14,6 @@ String xmlNode(String tags, String data);
|
||||
|
||||
String decToHex(uint32_t decValue, byte desiredStringLength);
|
||||
|
||||
//39164
|
||||
//457684
|
||||
void SsdpInit() {
|
||||
server.on("/description.xml", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
String ssdpSend = F("<root xmlns=\"urn:schemas-upnp-org:device-1-0\">");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/PrintMessage.h"
|
||||
#include "Utils\SerialPrint.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Utils/SysUtils.h"
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/PrintMessage.h"
|
||||
|
||||
|
||||
const String getUniqueId(const char* name) {
|
||||
return String(name) + getMacAddress();
|
||||
|
||||
@@ -20,8 +20,6 @@ void inputTimeSet() {
|
||||
void handle_time_init() {
|
||||
ts.add(
|
||||
TIME, 1000, [&](void *) {
|
||||
//jsonWriteStr(configLiveJson, "time", timeNow->getTime());
|
||||
//jsonWriteStr(configLiveJson, "timenow", timeNow->getTimeJson());
|
||||
jsonWriteStr(configLiveJson, "timenow", timeNow->getTime());
|
||||
eventGen("timenow", "");
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ void sysUptime() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
sCmd.addCommand(key.c_str(), uptimeReading);
|
||||
sensorReadingMap60sec += key + ",";
|
||||
sensorReadingMap30sec += key + ",";
|
||||
myLineParsing.clear();
|
||||
}
|
||||
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -117,15 +117,3 @@ void loop() {
|
||||
myNotAsyncActions->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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user