fix: renamed files

This commit is contained in:
alban 2023-10-28 19:06:10 +02:00
parent 7dbb880056
commit fd24e602e5
2 changed files with 17 additions and 9 deletions

View File

@ -18,6 +18,7 @@ Preferences preferences;
// WIFI // WIFI
const char* ssid = "Wokwi-GUEST"; const char* ssid = "Wokwi-GUEST";
const char* password = ""; const char* password = "";
const uint8_t wifi_loop_max = 10;
// NTP // NTP
bool sntp_initialized = false; bool sntp_initialized = false;
@ -33,6 +34,7 @@ uint16_t timer_interval_in_secs = timer_interval / 1000000;
; ;
// SCHEDULER // SCHEDULER
bool brun_scheduler = true;
uint8_t current_hour = HOUR_DEFAULT; uint8_t current_hour = HOUR_DEFAULT;
uint8_t current_minute = MINUTE_DEFAULT; uint8_t current_minute = MINUTE_DEFAULT;
uint8_t current_second = 0; uint8_t current_second = 0;
@ -93,8 +95,10 @@ void timeavailable(struct timeval *t)
// TIMER Callback // TIMER Callback
void IRAM_ATTR onTimer(){ void IRAM_ATTR onTimer(){
brun_scheduler = true;
Serial.println("onTimer::run"); }
void run_scheduler(){
// Serial.println("onTimer::run");
// Get the current time via NTP, or downgrade // Get the current time via NTP, or downgrade
if ( sntp_initialized ){ if ( sntp_initialized ){
struct tm timeinfo; struct tm timeinfo;
@ -104,10 +108,11 @@ void IRAM_ATTR onTimer(){
current_hour = timeinfo.tm_hour; current_hour = timeinfo.tm_hour;
current_minute = timeinfo.tm_min; current_minute = timeinfo.tm_min;
current_second = timeinfo.tm_sec; current_second = timeinfo.tm_sec;
// If no NTP clock // If no NTP clock
}else{ }else{
Serial.println("onTimer::NO NTP"); // Serial.println("onTimer::NO NTP");
current_second += timer_interval_in_secs; current_second += timer_interval_in_secs;
if(current_second >= 60) { if(current_second >= 60) {
current_second = 0; current_second = 0;
@ -178,18 +183,18 @@ void setup(){
preferences.putBytes(RELAY_2_SCHEDULE, scheduler_2_default, sizeof(scheduler_2_default)); preferences.putBytes(RELAY_2_SCHEDULE, scheduler_2_default, sizeof(scheduler_2_default));
/// ... more to come /// ... more to come
} }
/* Huh... This crashes wokwi
preferences.getBytes(RELAY_1_SCHEDULE, scheduler_1, preferences.getBytesLength(RELAY_1_SCHEDULE)); preferences.getBytes(RELAY_1_SCHEDULE, scheduler_1, preferences.getBytesLength(RELAY_1_SCHEDULE));
preferences.getBytes(RELAY_2_SCHEDULE, scheduler_2, preferences.getBytesLength(RELAY_2_SCHEDULE)); preferences.getBytes(RELAY_2_SCHEDULE, scheduler_2, preferences.getBytesLength(RELAY_2_SCHEDULE));
*/
preferences.end(); preferences.end();
// WIFI // WIFI
Serial.println("Setup::WIFI"); Serial.println("Setup::WIFI");
Serial.printf("Connecting to %s ", ssid); Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { uint8_t wifi_loop_count = 0;
while (WiFi.status() != WL_CONNECTED or wifi_loop_count < wifi_loop_max ) {
delay(500); delay(500);
wifi_loop_count++;
Serial.print("."); Serial.print(".");
} }
Serial.print("Connect to IP Address: "); Serial.print("Connect to IP Address: ");
@ -211,7 +216,7 @@ void setup(){
// SCHEDULER // SCHEDULER
Serial.println("Setup::SCHEDULER"); Serial.println("Setup::SCHEDULER");
next_event_ts = get_timestamp( HOUR_DEFAULT, MINUTE_DEFAULT + EVENT_INC_MINUTE, 0 ); next_event_ts = get_timestamp( HOUR_DEFAULT, MINUTE_DEFAULT, 10 );
// HTTP // HTTP
@ -221,8 +226,11 @@ void setup(){
void loop(){ void loop(){
Serial.println("Loop::Enter"); Serial.println("Loop::Enter");
if( brun_scheduler == true ){
brun_scheduler = false;
run_scheduler();
}
delay(1000); delay(1000);
}
nc }