Optimization

This commit is contained in:
Dmitry Borisenko
2020-10-20 23:58:23 +03:00
parent a5171f1178
commit 29e5a55ad3
14 changed files with 63 additions and 121 deletions

View File

@@ -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");
@@ -164,4 +162,5 @@ class Clock {
const String getUptime() {
return prettyMillis(_uptime);
}
};
};
extern Clock* timeNow;

View File

@@ -86,7 +86,7 @@ struct Time_t {
enum TimerTask_t { WIFI_SCAN,
WIFI_MQTT_CONNECTION_CHECK,
SENSORS10SEC,
SENSORS60SEC,
SENSORS30SEC,
STEPPER1,
STEPPER2,
LOG1,

View File

@@ -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();

View File

@@ -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;
};