|
@ -71,6 +71,7 @@ uint32_t lastActive = 0; |
|
|
uint32_t lastUpdate = 0; |
|
|
uint32_t lastUpdate = 0; |
|
|
uint32_t lastTransmit = 0; |
|
|
uint32_t lastTransmit = 0; |
|
|
bool sensorON = false; |
|
|
bool sensorON = false; |
|
|
|
|
|
bool alarmRunning = false; |
|
|
|
|
|
|
|
|
//Variables for the mqtt packages and topics
|
|
|
//Variables for the mqtt packages and topics
|
|
|
String commandTopic; |
|
|
String commandTopic; |
|
@ -383,11 +384,12 @@ struct tm getAlarmTime() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool isAlarmActive(){ |
|
|
bool isAlarmActive(){ |
|
|
time_t now; |
|
|
/* time_t now;
|
|
|
time(&now); |
|
|
time(&now); |
|
|
double seconds = difftime(now, mktime(&(state_persistant.alarmTime))); |
|
|
double seconds = difftime(now, mktime(&(state_persistant.alarmTime))); |
|
|
if (seconds > -24*60*60 && seconds <=0) return true; |
|
|
if (seconds > -24*60*60 && seconds <=0) return true; |
|
|
else return false; |
|
|
else return false;*/ |
|
|
|
|
|
return state_persistant.alarmArmed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -439,24 +441,28 @@ void loop() |
|
|
|
|
|
|
|
|
Serial.printf("alarm in %f seconds (%d)\n", seconds, state_persistant.alarmArmed); |
|
|
Serial.printf("alarm in %f seconds (%d)\n", seconds, state_persistant.alarmArmed); |
|
|
if (seconds >= 0 && state_persistant.alarmArmed) { |
|
|
if (seconds >= 0 && state_persistant.alarmArmed) { |
|
|
state_persistant.alarmArmed = false; |
|
|
if (mp3.aborted) alarmRunning = false; |
|
|
lastActive = millis(); |
|
|
if (!mp3.playing && !alarmRunning) { |
|
|
led.wakeUpLight(0); |
|
|
led.wakeUpLight(0); |
|
|
|
|
|
mp3.setVolume(2); |
|
|
Serial.println("WAKEUP TIME!!!!!"); |
|
|
Serial.println("WAKEUP TIME!!!!!"); |
|
|
// mp3.setVolume(10);
|
|
|
alarmRunning = true; |
|
|
// mp3.start_Progmem();
|
|
|
if (!mp3.aborted && iot.wifi.status() == WL_CONNECTED) { |
|
|
// delay(1500);
|
|
|
mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); |
|
|
|
|
|
} else { |
|
|
static const char starwars[] PROGMEM = |
|
|
static const char starwars[] PROGMEM = |
|
|
"Cantina:d=8,o=5,b=250:a,p,d6,p,a,p,d6,p,a,d6,p,a,p,g#,4a,a,g#,a,4g,f#,g,f#,4f.,d.,16p,4p.,a,p,d6,p,a,p,d6,p,a,d6,p,a,p,g#,a,p,g,p,4g.,f#,g,p,c6,4a#,4a,4g"; |
|
|
"Cantina:d=8,o=5,b=250:a,p,d6,p,a,p,d6,p,a,d6,p,a,p,g#,4a,a,g#,a,4g,f#,g,f#,4f.,d.,16p,4p.,a,p,d6,p,a,p,d6,p,a,d6,p,a,p,g#,a,p,g,p,4g.,f#,g,p,c6,4a#,4a,4g"; |
|
|
// Plenty more at: http://mines.lumpylumpy.com/Electronics/Computers/Software/Cpp/MFC/RingTones.RTTTL
|
|
|
// Plenty more at: http://mines.lumpylumpy.com/Electronics/Computers/Software/Cpp/MFC/RingTones.RTTTL
|
|
|
mp3.playRTTTL(starwars, strlen_P(starwars)); |
|
|
mp3.playRTTTL(starwars, strlen_P(starwars)); |
|
|
delay(15000); |
|
|
// mp3.start_Progmem();
|
|
|
|
|
|
} |
|
|
mp3.setVolume(2); |
|
|
|
|
|
mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); |
|
|
|
|
|
led.changeAnimation(2, 0); |
|
|
led.changeAnimation(2, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
if (lastButtonPress != 0 && millis() - lastButtonPress <= 10*1000) state_persistant.alarmArmed = false; // is this okay?
|
|
|
|
|
|
if (seconds >= 360) state_persistant.alarmArmed = false; // auto disable after time
|
|
|
|
|
|
if (state_persistant.alarmArmed == false) mp3.stop(); |
|
|
|
|
|
lastActive = millis(); |
|
|
|
|
|
} |
|
|
if (state_persistant.alarmArmed && seconds >= -5*60 && seconds <= 0) { |
|
|
if (state_persistant.alarmArmed && seconds >= -5*60 && seconds <= 0) { |
|
|
led.wakeUpLight(255*(seconds+300)/300); |
|
|
led.wakeUpLight(255*(seconds+300)/300); |
|
|
} |
|
|
} |
|
@ -471,6 +477,9 @@ void loop() |
|
|
Serial.print("Free Heap: "); |
|
|
Serial.print("Free Heap: "); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
Serial.println(ESP.getFreeHeap()); |
|
|
|
|
|
|
|
|
|
|
|
Serial.print("lastButtonPress: "); |
|
|
|
|
|
Serial.println(millis() - lastButtonPress); |
|
|
|
|
|
|
|
|
/* if (sensorON && digitalRead(sensorPin) == LOW) {
|
|
|
/* if (sensorON && digitalRead(sensorPin) == LOW) {
|
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, "OFF"); |
|
|
uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, "OFF"); |
|
|
sensorON = false; |
|
|
sensorON = false; |
|
|