|
|
@ -118,6 +118,7 @@ void setup() { |
|
|
|
Serial.print(" Alarm time: "); Serial.println(strftime_buf); |
|
|
|
|
|
|
|
if (-seconds > secondsToSleep) suspend(); |
|
|
|
else if (-seconds > 5*60) suspend(5*60); |
|
|
|
} |
|
|
|
|
|
|
|
u8g2.begin(); |
|
|
@ -160,6 +161,7 @@ void setup() { |
|
|
|
mp3.begin(); |
|
|
|
led.setup(); |
|
|
|
|
|
|
|
lastButtonPress = millis(); |
|
|
|
rotary.registerCallback(rotation); |
|
|
|
rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); |
|
|
|
} |
|
|
@ -205,9 +207,18 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties |
|
|
|
|
|
|
|
void suspend(uint32_t secondsToSleep) { |
|
|
|
DEBUG_PRINTLN("Entering deep sleep"); |
|
|
|
|
|
|
|
mp3.stop(); |
|
|
|
led.stop(); |
|
|
|
delay(1000); |
|
|
|
u8g2.setPowerSave(1); |
|
|
|
|
|
|
|
//properly disconnect from the MQTT broker
|
|
|
|
iot.mqtt.disconnect(); |
|
|
|
|
|
|
|
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep); |
|
|
|
const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton; |
|
|
|
esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask, ESP_EXT1_WAKEUP_ANY_HIGH); |
|
|
|
const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton; |
|
|
|
esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask, ESP_EXT1_WAKEUP_ANY_HIGH); |
|
|
|
|
|
|
|
////esp_sleep_enable_ext0_wakeup((gpio_num_t)sensorPin, 0);
|
|
|
|
// const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
|
|
|
@ -215,14 +226,17 @@ void suspend(uint32_t secondsToSleep) { |
|
|
|
//// esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
|
|
|
|
//
|
|
|
|
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
|
|
|
|
//properly disconnect from the MQTT broker
|
|
|
|
iot.mqtt.disconnect(); |
|
|
|
|
|
|
|
//send the ESP into deep sleep
|
|
|
|
esp_deep_sleep_start(); |
|
|
|
} |
|
|
|
|
|
|
|
void suspend() { |
|
|
|
suspend(secondsToSleep); |
|
|
|
time_t now; |
|
|
|
time(&now); |
|
|
|
double seconds = difftime(now, mktime(&alarmTime)); |
|
|
|
if (-seconds > secondsToSleep) suspend(secondsToSleep); |
|
|
|
else if (-seconds > 5*60) suspend(5*60); |
|
|
|
} |
|
|
|
|
|
|
|
void setAlarmTime(struct tm time) { |
|
|
@ -284,13 +298,17 @@ void loop() |
|
|
|
led.wakeUpLight(0); |
|
|
|
Serial.println("WAKEUP TIME!!!!!"); |
|
|
|
mp3.setVolume(2); |
|
|
|
mp3.start(); |
|
|
|
mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); |
|
|
|
led.changeAnimation(2, 0); |
|
|
|
} |
|
|
|
if (seconds >= -5*60 && seconds <= 0) { |
|
|
|
if (alarmArmed && seconds >= -5*60 && seconds <= 0) { |
|
|
|
led.wakeUpLight(255*(seconds+300)/300); |
|
|
|
} |
|
|
|
|
|
|
|
bool stayAwake = false; |
|
|
|
if (alarmArmed && seconds >= -2*5*60) stayAwake = true; |
|
|
|
if (!mp3.playing && millis() - lastButtonPress >= 60*1000 && !stayAwake) suspend(); |
|
|
|
|
|
|
|
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); |
|
|
|
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
|
|
|
|
|