Then it seems to work as expected. (Except the SETUP BUTTON (20)) Thank you all for good help! Here is the final code. Maybe it could be of interest for others:
// To wake the Photon from deep skeep and set it in safe mode (wifi is on in safe mode) press SETUP and RESET, relese RESET after 2sec, wait for violet)
//
// This #include statement was automatically added by the Particle IDE.
#include <DailyTimerSpark.h>
const uint32_t SLEEP_MINUTES = 50; // wake every xx minutes
const uint32_t WAKE_HOUR = 18; // starting hour per day
const uint32_t SLEEP_HOUR = 23; // stopping hour per day
int relay1 = D0; // initialize and give the D0 the variable name relay1
int relay2 = D1; // initialize and give the D1 the variable name relay2
retained uint32_t expectedWake = 0;
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
void setup()
{
Time.zone(+1); //utc time - 1 hour behind GMT - I use GMT
// pinMode(D7, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
}
void loop()
{
uint32_t dt;
if (WAKE_HOUR <= (uint32_t)Time.hour() && (uint32_t)Time.hour() < SLEEP_HOUR)
{
dt = (SLEEP_MINUTES - Time.minute() % SLEEP_MINUTES) * 60 - Time.second(); // wake at next time boundary
}
else
{
uint32_t now = 86400 - Time.local() % 86400;
dt = (now + WAKE_HOUR * 3600) % 86400;
}
// delay(3000); // 3sek delay where Photoen is awake but relay/power is off
digitalWrite(relay1, HIGH); // turn on relay1/power for the router
delay(120000); // delay for 2 min for the internet to establish
digitalWrite(relay2, HIGH); // turn on relay2/power for the Raspberry Pi
delay(480000); // delay for 8 min for the data collection to be finished, then go to deep sleep.
System.sleep(SLEEP_MODE_DEEP , dt); // , SLEEP_NETWORK_STANDBY); go to Deep Sleep
System.sleep(BTN, FALLING , dt); // , SLEEP_NETWORK_STANDBY); // use SETUP BUTTON (20) to wake (don\t work!)
expectedWake = Time.now() + dt; // calculate next wakeup.
}