upraven nazev ino souboru, upravena prace s casem

main
Michal 2024-04-06 11:37:12 +02:00
parent 956ee23a7c
commit 996b2253fb
5 changed files with 82 additions and 23 deletions

View File

@ -3,7 +3,7 @@
#define RELAY3 13 // D2 #define RELAY3 13 // D2
#define RELAY4 12 // D1 #define RELAY4 12 // D1
const char* version = "v2.2"; const char* version = "v2.3";
const char* ssid = "Vlcice"; const char* ssid = "Vlcice";
const char* password = "1010201010"; const char* password = "1010201010";
@ -15,7 +15,7 @@ const char* host = "terarium";
#include <Preferences.h> // preference #include <Preferences.h> // preference
Preferences pref; Preferences pref;
#include "ntp.h" #include "time.h"
#include "relay.h" #include "relay.h"

18
ntp.h
View File

@ -1,18 +0,0 @@
//#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600 * 1, 60000);
void time_client_setup() {
timeClient.begin();
}
void time_client_update() {
timeClient.update();
}

View File

@ -26,8 +26,8 @@ bool relay_state(uint8_t id, bool negation) {
} }
void relay_scheduler() { void relay_scheduler() {
int hours = timeClient.getHours(); int hours = time_getHours();
int minutes = timeClient.getMinutes(); int minutes = time_getMinutes();
// rele 1 // rele 1
if (pref.getBool("r1_enable", true)) { if (pref.getBool("r1_enable", true)) {
if (hours == pref.getString("r1_on_h", "00").toInt() && minutes == pref.getString("r1_on_m", "00").toInt() && relay_state(RELAY1, pref.getBool("r1_neg", false)) == 0) { if (hours == pref.getString("r1_on_h", "00").toInt() && minutes == pref.getString("r1_on_m", "00").toInt() && relay_state(RELAY1, pref.getBool("r1_neg", false)) == 0) {

View File

@ -16,7 +16,7 @@ String pageSettings() {
ptr += "<h1>Terarium - nastavení</h1>\n"; ptr += "<h1>Terarium - nastavení</h1>\n";
ptr += "<div class=\"center\">Verze: " + String(version) + "</div>"; ptr += "<div class=\"center\">Verze: " + String(version) + "</div>";
ptr += "<div class=\"center\">Aktuální čas: " + timeClient.getFormattedTime() + "</div>\n"; ptr += "<div class=\"center\">Aktuální čas: " + time_getFormattedTime() + "</div>\n";
ptr += "<div class=\"center\"><a href=\"/\">Zpět na přehled</a></div>"; ptr += "<div class=\"center\"><a href=\"/\">Zpět na přehled</a></div>";

77
time.h Normal file
View File

@ -0,0 +1,77 @@
#include <NTPClient.h>
#include <WiFiUdp.h>
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "tik.cesnet.cz");
//Week Days
String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//Month names
String months[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
void time_client_setup() {
// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(2*3600);
}
void time_client_update() {
timeClient.update();
}
unsigned long time_getEpochTime() {
return timeClient.getEpochTime();
}
String time_getFormattedTime(){
return timeClient.getFormattedTime();
}
int time_getHours() {
return timeClient.getHours();
}
int time_getMinutes() {
return timeClient.getMinutes();
}
int time_getSeconds() {
return timeClient.getSeconds();
}
String time_getDayName(){
return weekDays[timeClient.getDay()];
}
int time_getDay(){
unsigned long epochTime = time_getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
return ptm->tm_mday;
}
int time_getMonth(){
unsigned long epochTime = time_getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
return ptm->tm_mon+1;
}
int time_getYear(){
unsigned long epochTime = time_getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
return ptm->tm_year+1900;
}
String time_getMonthName(){
return months[time_getMonth()-1];
}