|
|
@ -41,6 +41,7 @@ char timeStr[20]; |
|
|
|
char weatherStr[32]; |
|
|
|
RTC_DATA_ATTR static int boot_count = 0; |
|
|
|
RTC_DATA_ATTR struct tm alarmTime; |
|
|
|
RTC_DATA_ATTR bool alarmArmed = false; |
|
|
|
|
|
|
|
//Create a new Basecamp instance called iot
|
|
|
|
Basecamp iot; |
|
|
@ -112,7 +113,7 @@ void setup() { |
|
|
|
|
|
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { |
|
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
|
Serial.printf("seconds to alarm: %f\n", seconds); |
|
|
|
Serial.printf("alarm in %f seconds\n", seconds); |
|
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
|
Serial.print(" Alarm time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
@ -226,11 +227,16 @@ void suspend() { |
|
|
|
|
|
|
|
void setAlarmTime(struct tm time) { |
|
|
|
alarmTime = time; |
|
|
|
alarmArmed = true; |
|
|
|
char strftime_buf[64]; |
|
|
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); |
|
|
|
Serial.print("Setting Alarm time: "); Serial.println(strftime_buf); |
|
|
|
} |
|
|
|
|
|
|
|
struct tm getAlarmTime() { |
|
|
|
return alarmTime; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void obtain_time(void) { |
|
|
|
sntp_setoperatingmode(SNTP_OPMODE_POLL); |
|
|
@ -266,16 +272,30 @@ void loop() |
|
|
|
if(millis() - lastUpdate >= 1000) { |
|
|
|
lastUpdate = millis(); |
|
|
|
|
|
|
|
time_t now; |
|
|
|
struct tm timeinfo; |
|
|
|
time(&now); |
|
|
|
localtime_r(&now, &timeinfo); |
|
|
|
time_t now; |
|
|
|
struct tm timeinfo; |
|
|
|
time(&now); |
|
|
|
localtime_r(&now, &timeinfo); |
|
|
|
|
|
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
|
Serial.printf("alarm in %f seconds (%d)\n", seconds, alarmArmed); |
|
|
|
if (seconds >= 0 && alarmArmed) { |
|
|
|
alarmArmed = false; |
|
|
|
led.wakeUpLight(0); |
|
|
|
Serial.println("WAKEUP TIME!!!!!"); |
|
|
|
mp3.setVolume(2); |
|
|
|
mp3.start(); |
|
|
|
led.changeAnimation(2, 0); |
|
|
|
} |
|
|
|
if (seconds >= -5*60 && seconds <= 0) { |
|
|
|
led.wakeUpLight(255*(seconds+300)/300); |
|
|
|
} |
|
|
|
|
|
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); |
|
|
|
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); |
|
|
|
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
|
|
|
|
|
Serial.print("Free Heap: "); |
|
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
|
Serial.print("Free Heap: "); |
|
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|