#include <Arduino.h>
#include <ESP32Time.h>
ESP32Time rtc(3600*0);
void test_debug_schedule() {
int wakeup_check_time_value = 15;
int wakeup_send_time_value = 240;
int silent_period_start_value = 22;
int silent_period_end_value = 8;
//rtc.setTime(9, 0, 16, 6, 8, 2024); // August 06 2024 16:00:09 -> alert check with x=0, NOW x=1 Standard Operation
rtc.setTime(6, 0, 0, 7, 8, 2024); // August 07 2024 00:00:06 -> standard operation with x=1, NOW x=1 Wake for alert check
//rtc.setTime(sec2, min2, hour2, day2, month2, year2);
Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S"));
int _rtc_getYear = rtc.getYear();
int _rtc_getHour = rtc.getHour(true);
int _rtc_getMinute = rtc.getMinute();
// August 07 2024 00:00:06 -> standard operation??? x=1?
// August 06 2024 16:00:09 -> alert check??? x=0?
String _state = "";
float wakeup_send_time_value_div60 = (wakeup_send_time_value/60);
float delta = ((_rtc_getHour*60 + _rtc_getMinute) - (silent_period_end_value*60));
float deIntA = (delta / wakeup_send_time_value);
float deIntA_int = int(deIntA);
float deIntAA_int = (deIntA - deIntA_int);
float deIntAA_int_sum = ((deIntA - deIntA_int) * wakeup_send_time_value);
Serial.print("wakeup_check_time_value:");Serial.println(wakeup_check_time_value);
Serial.print("wakeup_send_time_value:");Serial.println(wakeup_send_time_value);
Serial.print("delta:");Serial.print(delta,4);
Serial.print(", deIntA:");Serial.print(deIntA,4);
Serial.print(", deIntA_int:");Serial.print(deIntA_int,4);
Serial.print(", deIntAA_int:");Serial.print(deIntAA_int,4);
Serial.print(", deIntAA_int_sum:");Serial.print(deIntAA_int_sum,4);
Serial.println();
Serial.print("_rtc_getHour:");
Serial.println(_rtc_getHour);
Serial.print("silent_period_end_value:");
Serial.println(silent_period_end_value);
Serial.print("silent_period_start_value:");
Serial.println(silent_period_start_value);
Serial.print("_rtc_getHour >= silent_period_end_value:");
Serial.println((_rtc_getHour >= silent_period_end_value));
Serial.print("_rtc_getHour < silent_period_start_value:");
Serial.println((_rtc_getHour < silent_period_start_value));
Serial.print(", x:");Serial.print((_rtc_getHour >= silent_period_end_value) and (_rtc_getHour < silent_period_start_value));
Serial.print(", y:");Serial.print((silent_period_start_value - silent_period_end_value) > wakeup_send_time_value_div60);
Serial.print(", z:");Serial.print(deIntAA_int_sum < wakeup_check_time_value);
Serial.println();
if ( (_rtc_getYear!=2024) or (
(_rtc_getHour >= silent_period_end_value) and
(_rtc_getHour < silent_period_start_value) and
((silent_period_start_value - silent_period_end_value) > (wakeup_send_time_value/60)) and
(((deIntA - deIntA_int) * wakeup_send_time_value) < wakeup_check_time_value)
)) {
Serial.print("Wake for standard operation, Time "); Serial.print(_rtc_getHour); Serial.print(":"); Serial.println(_rtc_getMinute);
} else {
Serial.print("Wake for alert check, Time "); Serial.print(_rtc_getHour); Serial.print(":"); Serial.println(_rtc_getMinute);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
test_debug_schedule();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}