From 7fff81f521f6b9d6f277d972f59411452fb4a677 Mon Sep 17 00:00:00 2001 From: Roman Bazalevskiy Date: Thu, 17 Nov 2022 08:26:38 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=20=D0=B1=D1=83=D0=B4=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8?= =?utf8?q?=D0=BA=20=D0=BF=D0=BE=20=D0=B4=D0=BD=D1=8F=D0=BC=20+=20=D0=BD?= =?utf8?q?=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=B8=D1=87?= =?utf8?q?=D0=B5=D1=81=D0=B0=D0=BD=D1=8B=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD?= =?utf8?q?=D0=BE=D1=81=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20?= =?utf8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ESP8266_clock.ino | 50 +++++++++++++++++++++++++++++++++++++++++++++++ alarm.cpp | 2 +- config.cpp | 1 - net.cpp | 8 ++++---- time.cpp | 2 +- web.cpp | 7 +++---- 6 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 ESP8266_clock.ino diff --git a/ESP8266_clock.ino b/ESP8266_clock.ino new file mode 100644 index 0000000..b8e8c4a --- /dev/null +++ b/ESP8266_clock.ino @@ -0,0 +1,50 @@ +#include "Clock.h" +#include + +void setup() { + // put your setup code here, to run once: + + Serial.begin(115200); + Serial.println(); + Serial.println(F("Starting...")); + + setupConfig(); + Serial.println(cfg); + + setupHandlers(); + + setupHardware(); + setupPanel(); + + setupNet(); + setupTime(); + + setupAlarm(); + setupWeatherRequest(); + + setupWeb(); +} + +void mem() { + Serial.println(F("-------------------------------------------------------------")); + Serial.print("Heap:"); Serial.print(ESP.getFreeHeap()); + Serial.print(" Largest chunk:"); Serial.print(ESP.getMaxFreeBlockSize()); + Serial.print(" Fragmentation:"); Serial.print(ESP.getHeapFragmentation()); + Serial.print(" Stack:"); Serial.println(ESP.getFreeContStack()); + Serial.println(F("-------------------------------------------------------------")); +} + +void loop() { + static unsigned long lastMillis = 0; + int interval = 15000; + // put your main code here, to run repeatedly: + if (millis() - lastMillis > interval) { + lastMillis = millis(); + mem(); + } + tickNet(); + tickTime(); + tickHardware(); + tickPanel(); + tickWeb(); +} diff --git a/alarm.cpp b/alarm.cpp index 4028b6c..e609dba 100644 --- a/alarm.cpp +++ b/alarm.cpp @@ -22,7 +22,7 @@ void checkAlarm() { int alarm_length = cfg.getIntValue(F("alarm_length")); int alarm_beep_ms = cfg.getIntValue(F("alarm_beep_ms")); int alarm_silent_ms = cfg.getIntValue(F("alarm_silent_ms")); - if ( enable_alarm && hh == alarm_hour && mi == alarm_minute && alarm_days[dd?dd-1:6]!='0') { + if ( enable_alarm && (hh == alarm_hour) && (mi == alarm_minute) && (alarm_days[dw?dw-1:6]!='0')) { beep(alarm_tone, alarm_length * 1000, alarm_beep_ms, alarm_silent_ms); } } diff --git a/config.cpp b/config.cpp index bb60f3a..0835802 100644 --- a/config.cpp +++ b/config.cpp @@ -489,7 +489,6 @@ void saveConfig(bool force) { if (File f = LittleFS.open(F("/config.txt"),"w")) { f.print(cfg); f.close(); - Serial.print(cfg); Serial.println(F("Конфигурация сохранена")); cfg.resetTimestamp(); } diff --git a/net.cpp b/net.cpp index b211f63..ff18fcc 100644 --- a/net.cpp +++ b/net.cpp @@ -15,7 +15,7 @@ void setupNet(bool AP) { WiFi.mode(WIFI_STA); WiFi.begin(SSID,PSK); isApEnabled = false; - Serial.println(F("STA mode active")); + Serial.println(F("Режим беспроводного клиента")); } else { SSID = cfg.getCharValue(F("ap_ssid")); PSK = cfg.getCharValue(F("ap_psk")); @@ -24,7 +24,7 @@ void setupNet(bool AP) { } WiFi.mode(WIFI_AP); WiFi.softAP(SSID,PSK); - Serial.println(F("AP mode active")); + Serial.println(F("Режим точки доступа")); isApEnabled = true; String IP = WiFi.softAPIP().toString(); char buf[256]; @@ -44,11 +44,11 @@ void tickNet() { if (isApEnabled) { if (WiFi.status() == WL_CONNECTED && !isNetConnected) { isNetConnected = true; - Serial.print(F("Device connected to SSID ")); Serial.println(SSID); + Serial.print(F("Выполнено подключение к сети ")); Serial.println(SSID); message(F("Соединение установлено")); } else if (WiFi.status() != WL_CONNECTED && isNetConnected) { isNetConnected = false; - Serial.println(F("Network connection lost")); + Serial.println(F("Сеть потеряна")); message(F("Сеть потеряна")); } } diff --git a/time.cpp b/time.cpp index c874bb9..e6f81c9 100644 --- a/time.cpp +++ b/time.cpp @@ -23,7 +23,7 @@ std::function tTimeHandlers[maxTimeHandlers]; void timeIsSet(bool ntp) { if (ntp) { - Serial.println(F("Time syncronized with NTP")); + Serial.println(F("Время синхронизировано")); message(F("Время синхронизировано")); if (isRTCEnabled) { RTC.adjust(DateTime(now)); diff --git a/web.cpp b/web.cpp index b34d7cf..7b7f1bc 100644 --- a/web.cpp +++ b/web.cpp @@ -129,7 +129,6 @@ void setupWeb() { isWebStarted = true; - Serial.println("Setting authentication..."); strncpy(auth_user,cfg.getCharValue(F("auth_user")),31); strncpy(auth_pwd,cfg.getCharValue(F("auth_pwd")),31); @@ -308,18 +307,18 @@ void tickWeb() { static bool connectInProgress = false; static unsigned long connectMillis = 0; if (actionScheduled && millis()>millisScheduled+300) { - Serial.print(F("Scheduled action ")); Serial.println(actionScheduled); + Serial.print(F("Запланированная операция ")); Serial.println(actionScheduled); // if (strcmp(actionScheduled,"restart") == 0) { server.end(); reboot(); } else if (strcmp(actionScheduled,"auth") == 0) { - Serial.println("New authentication credentials"); + Serial.println("Логин/пароль изменены"); strncpy(auth_user,cfg.getCharValue(F("auth_user")),31); strncpy(auth_pwd,cfg.getCharValue(F("auth_pwd")),31); pendingAuth = false; } else if (strcmp(actionScheduled,"wifi") == 0) { - Serial.println("New wifi credentials"); + Serial.println("Применяю настройки сети"); strcpy(storedSSID,WiFi.SSID().c_str()); strcpy(storedPSK,WiFi.psk().c_str()); WiFi.mode(WIFI_STA); -- 2.34.1