--- /dev/null
+#include "Clock.h"
+#include <LittleFS.h>
+
+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();
+}
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);
}
}
if (File f = LittleFS.open(F("/config.txt"),"w")) {
f.print(cfg);
f.close();
- Serial.print(cfg);
Serial.println(F("Конфигурация сохранена"));
cfg.resetTimestamp();
}
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"));
}
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];
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("Сеть потеряна"));
}
}
void timeIsSet(bool ntp) {
if (ntp) {
- Serial.println(F("Time syncronized with NTP"));
+ Serial.println(F("Время синхронизировано"));
message(F("Время синхронизировано"));
if (isRTCEnabled) {
RTC.adjust(DateTime(now));
isWebStarted = true;
- Serial.println("Setting authentication...");
strncpy(auth_user,cfg.getCharValue(F("auth_user")),31);
strncpy(auth_pwd,cfg.getCharValue(F("auth_pwd")),31);
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);