try fix restart wrong fonctionnement, old condition fonction nor rm
This commit is contained in:
parent
44872fc71e
commit
efa325b044
69
src/main.cpp
69
src/main.cpp
|
@ -11,6 +11,8 @@
|
|||
#define STORAGE_NAMESPACE "storage"
|
||||
#define RESTART 1
|
||||
#define REFRESHMEMBOOT 0
|
||||
#define RESTARTTIMES 2
|
||||
#define REFRESHTIMES 4
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -36,6 +38,33 @@ NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 7200, 60000);
|
|||
|
||||
//-------------------- CONDITION --------------------//
|
||||
|
||||
|
||||
bool testTime (int hours, int minutes, bool restart){
|
||||
Serial.println('\n');
|
||||
Serial.println((REFRESHTIMES * TIME_TO_SLEEP) / 3600,DEC);
|
||||
Serial.println(((REFRESHTIMES * TIME_TO_SLEEP) % 3600) / 60,DEC);
|
||||
Serial.println('\n');
|
||||
|
||||
if (restart){ // restart parts
|
||||
if(hours < (RESTARTTIMES * TIME_TO_SLEEP) / 3600) return true;
|
||||
else{
|
||||
if((hours = (RESTARTTIMES * TIME_TO_SLEEP) / 3600) && (minutes <= ((RESTARTTIMES * TIME_TO_SLEEP) % 3600) / 60))return true;
|
||||
return false;
|
||||
}
|
||||
} else { // refresh parts
|
||||
if(hours >= (RESTARTTIMES * TIME_TO_SLEEP) / 3600){
|
||||
if(hours < (REFRESHTIMES * TIME_TO_SLEEP) / 3600)return true;
|
||||
else{
|
||||
if((hours = (REFRESHTIMES * TIME_TO_SLEEP) / 3600) && (minutes <= ((REFRESHTIMES * TIME_TO_SLEEP) % 3600) / 60))return true;
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Time hour for restart or time for refresh restart persistant mem
|
||||
*
|
||||
|
@ -46,10 +75,13 @@ NTPClient TimeClient(NtpUDP, "europe.pool.ntp.org", 7200, 60000);
|
|||
*/
|
||||
bool ishour(int hours, bool restart){
|
||||
if (restart){
|
||||
return hours <= (2 * TIME_TO_SLEEP) / 3600;
|
||||
Serial.println('\n');
|
||||
Serial.println((RESTARTTIMES * TIME_TO_SLEEP) / 3600,DEC);
|
||||
Serial.println('\n');
|
||||
return hours <= (RESTARTTIMES * TIME_TO_SLEEP) / 3600;
|
||||
}
|
||||
// Then refresh time
|
||||
return (hours > (2 * TIME_TO_SLEEP) / 3600) && (hours <= (4 * TIME_TO_SLEEP) / 3600);
|
||||
return (hours >= (RESTARTTIMES * TIME_TO_SLEEP) / 3600) && (hours <= (REFRESHTIMES * TIME_TO_SLEEP) / 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,10 +94,12 @@ bool ishour(int hours, bool restart){
|
|||
*/
|
||||
bool isminute(int minutes, bool restart){
|
||||
if (restart){
|
||||
return minutes <= ((2 * TIME_TO_SLEEP) % 3600) / 60;
|
||||
Serial.println(((RESTARTTIMES * TIME_TO_SLEEP) % 3600) / 60,DEC);
|
||||
Serial.println('\n');
|
||||
return minutes <= ((RESTARTTIMES * TIME_TO_SLEEP) % 3600) / 60;
|
||||
}
|
||||
// Then refresh time
|
||||
return (minutes > ((2 * TIME_TO_SLEEP) % 3600)) / 60 && (minutes <= ((4 * TIME_TO_SLEEP) % 3600) / 60);
|
||||
return (minutes >= ((RESTARTTIMES * TIME_TO_SLEEP) % 3600) / 60) && (minutes <= ((REFRESHTIMES * TIME_TO_SLEEP) % 3600) / 60);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,13 +110,13 @@ bool isminute(int minutes, bool restart){
|
|||
* @return true right secondes for restart or refresh
|
||||
* @return false bad secondes for restart or refresh
|
||||
*/
|
||||
bool issecond(int secondes, bool restart){
|
||||
if (restart){
|
||||
return secondes <= ((2 * TIME_TO_SLEEP) - 1 ) % 60;
|
||||
}
|
||||
// Then refresh time
|
||||
return (secondes > ((2 * TIME_TO_SLEEP) - 1 ) % 60) && (secondes <= ((4 * TIME_TO_SLEEP) - 1 ) % 60);
|
||||
}
|
||||
// bool issecond(int secondes, bool restart){
|
||||
// if (restart){
|
||||
// return secondes <= ((2 * TIME_TO_SLEEP) - 1 ) % 60;
|
||||
// }
|
||||
// // Then refresh time
|
||||
// return (secondes > ((2 * TIME_TO_SLEEP) - 1 ) % 60) && (secondes <= ((4 * TIME_TO_SLEEP) - 1 ) % 60);
|
||||
// }
|
||||
|
||||
//-------------------- FONCTIONS --------------------//
|
||||
|
||||
|
@ -249,6 +283,7 @@ bool TestBoot(bool resOrRfsh)
|
|||
nvs_handle_t my_handle;
|
||||
esp_err_t err;
|
||||
bool booted = false;
|
||||
//Serial.println("Test");
|
||||
|
||||
// Open
|
||||
err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
|
||||
|
@ -305,13 +340,13 @@ bool TestBoot(bool resOrRfsh)
|
|||
// Close
|
||||
nvs_close(my_handle);
|
||||
Serial.println("not restart");
|
||||
return false;
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// Close
|
||||
nvs_close(my_handle);
|
||||
Serial.println("already restart");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Not needed but finish properly the function */
|
||||
|
@ -345,12 +380,12 @@ void setup()
|
|||
* @brief restart the ESP if there is the time restart
|
||||
*
|
||||
*/
|
||||
if(ishour(hours,RESTART) && isminute(minutes,RESTART) && issecond(secondes,RESTART) && TestBoot(RESTART)){
|
||||
if(TestBoot(RESTART) && testTime(hours, minutes, RESTART)){
|
||||
ESP.restart();
|
||||
} else if(ishour(hours,REFRESHMEMBOOT) && isminute(minutes,REFRESHMEMBOOT) && issecond(secondes,REFRESHMEMBOOT)){
|
||||
} else if(testTime(hours, minutes, REFRESHMEMBOOT)){
|
||||
TestBoot(REFRESHMEMBOOT);
|
||||
}
|
||||
/* ######### test time part #########
|
||||
/* ######### test time part ######### */
|
||||
Serial.println('\n');
|
||||
Serial.println(hours,DEC);
|
||||
Serial.println(':');
|
||||
|
@ -358,7 +393,7 @@ void setup()
|
|||
Serial.println(':');
|
||||
Serial.println(secondes,DEC);
|
||||
Serial.println('\n');
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue