diff --git a/data/widgets/btn.json b/data/widgets/btn.json new file mode 100644 index 00000000..7b2bf78e --- /dev/null +++ b/data/widgets/btn.json @@ -0,0 +1,6 @@ +{ + "widget": "btn", + "icon": "switch", + "fill": "outline", + "color": "orange" +} \ No newline at end of file diff --git a/include/Clock.h b/include/Clock.h index eaddafde..dea567c8 100644 --- a/include/Clock.h +++ b/include/Clock.h @@ -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); } -}; \ No newline at end of file +}; +extern Clock* timeNow; \ No newline at end of file diff --git a/include/Consts.h b/include/Consts.h index 52e81fc5..e2228407 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -86,7 +86,7 @@ struct Time_t { enum TimerTask_t { WIFI_SCAN, WIFI_MQTT_CONNECTION_CHECK, SENSORS10SEC, - SENSORS60SEC, + SENSORS30SEC, STEPPER1, STEPPER2, LOG1, diff --git a/include/Global.h b/include/Global.h index 42967865..c6e76833 100644 --- a/include/Global.h +++ b/include/Global.h @@ -1,27 +1,10 @@ #pragma once //===================Libraries=================================================================================================================================================== -#include -#include - -#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 #include +#include +#include +#include #include #include #include @@ -31,27 +14,37 @@ #include #include #include -#include - +#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(); - diff --git a/include/Utils/PrintMessage.h b/include/Utils/PrintMessage.h deleted file mode 100644 index 2db05d6b..00000000 --- a/include/Utils/PrintMessage.h +++ /dev/null @@ -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; -}; diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 677a0989..83d6ab45 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -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(); -// } -//} diff --git a/src/Clock.cpp b/src/Clock.cpp new file mode 100644 index 00000000..888f9d5b --- /dev/null +++ b/src/Clock.cpp @@ -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); +} diff --git a/src/Global.cpp b/src/Global.cpp index d840dd98..18cb15b4 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -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; diff --git a/src/SSDP.cpp b/src/SSDP.cpp index b42f6db7..c84d99ca 100644 --- a/src/SSDP.cpp +++ b/src/SSDP.cpp @@ -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(""); diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index 5d7fe2ba..32b52beb 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -1,5 +1,6 @@ #include "Utils/FileUtils.h" -#include "Utils/PrintMessage.h" +#include "Utils\SerialPrint.h" +#include "Utils/StringUtils.h" diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index eefdc87a..a9f507a1 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -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(); diff --git a/src/items/InputTimeClass.cpp b/src/items/InputTimeClass.cpp index 52834b86..43d14b3f 100644 --- a/src/items/InputTimeClass.cpp +++ b/src/items/InputTimeClass.cpp @@ -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", ""); }, diff --git a/src/items/sysUptime.cpp b/src/items/sysUptime.cpp index 26119c16..2f1b222c 100644 --- a/src/items/sysUptime.cpp +++ b/src/items/sysUptime.cpp @@ -7,7 +7,7 @@ void sysUptime() { myLineParsing.update(); String key = myLineParsing.gkey(); sCmd.addCommand(key.c_str(), uptimeReading); - sensorReadingMap60sec += key + ","; + sensorReadingMap30sec += key + ","; myLineParsing.clear(); } diff --git a/src/main.cpp b/src/main.cpp index fce31a41..d6a64e9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,16 +116,4 @@ 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); -} +} \ No newline at end of file