changes to allow restart command from API to complete before rebooting

This commit is contained in:
Proddy
2021-10-11 16:42:36 +02:00
parent 3113d392ac
commit cddadcfae2
4 changed files with 25 additions and 11 deletions

View File

@@ -597,7 +597,7 @@ void Console::load_system_commands(unsigned int context) {
CommandFlags::ADMIN, CommandFlags::ADMIN,
flash_string_vector{F_(restart)}, flash_string_vector{F_(restart)},
[](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) { [](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) {
EMSESP::system_.restart(); EMSESP::system_.system_restart();
}); });
EMSESPShell::commands->add_command(context, EMSESPShell::commands->add_command(context,

View File

@@ -34,6 +34,7 @@ uuid::syslog::SyslogService System::syslog_;
// init statics // init statics
uint32_t System::heap_start_ = 1; // avoid using 0 to divide-by-zero later uint32_t System::heap_start_ = 1; // avoid using 0 to divide-by-zero later
PButton System::myPButton_; PButton System::myPButton_;
bool System::restart_requested_ = false;
// send on/off to a gpio pin // send on/off to a gpio pin
// value: true = HIGH, false = LOW // value: true = HIGH, false = LOW
@@ -160,8 +161,8 @@ bool System::command_watch(const char * value, const int8_t id) {
} }
// restart EMS-ESP // restart EMS-ESP
void System::restart() { void System::system_restart() {
LOG_INFO(F("Restarting system...")); LOG_INFO(F("Restarting EMS-ESP..."));
Shell::loop_all(); Shell::loop_all();
delay(1000); // wait a second delay(1000); // wait a second
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
@@ -192,7 +193,7 @@ void System::format(uuid::console::Shell & shell) {
LITTLEFS.format(); LITTLEFS.format();
#endif #endif
System::restart(); System::system_restart();
} }
void System::syslog_start() { void System::syslog_start() {
@@ -422,6 +423,11 @@ void System::upload_status(bool in_progress) {
// checks system health and handles LED flashing wizardry // checks system health and handles LED flashing wizardry
void System::loop() { void System::loop() {
// check if we're supposed to do a reset/restart
if (restart_requested()) {
this->system_restart();
}
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
myPButton_.check(); // check button press myPButton_.check(); // check button press
@@ -441,8 +447,8 @@ void System::loop() {
last_heartbeat_ = currentMillis; last_heartbeat_ = currentMillis;
send_heartbeat(); send_heartbeat();
} }
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
#if defined(EMSESP_DEBUG) #if defined(EMSESP_DEBUG)
/* /*
static uint32_t last_memcheck_ = 0; static uint32_t last_memcheck_ = 0;
@@ -452,6 +458,7 @@ void System::loop() {
} }
*/ */
#endif #endif
#endif #endif
#endif #endif
@@ -1028,11 +1035,9 @@ bool System::load_board_profile(std::vector<uint8_t> & data, const std::string &
return true; return true;
} }
// restart command - perform a hard reset // restart command - perform a hard reset by setting flag
bool System::command_restart(const char * value, const int8_t id) { bool System::command_restart(const char * value, const int8_t id) {
#ifndef EMSESP_STANDALONE restart_requested(true);
ESP.restart();
#endif
return true; return true;
} }

View File

@@ -63,7 +63,7 @@ class System {
static bool command_settings(const char * value, const int8_t id, JsonObject & json); static bool command_settings(const char * value, const int8_t id, JsonObject & json);
static bool command_commands(const char * value, const int8_t id, JsonObject & json); static bool command_commands(const char * value, const int8_t id, JsonObject & json);
void restart(); void system_restart();
void format(uuid::console::Shell & shell); void format(uuid::console::Shell & shell);
void upload_status(bool in_progress); void upload_status(bool in_progress);
bool upload_status(); bool upload_status();
@@ -84,6 +84,14 @@ class System {
static bool is_valid_gpio(uint8_t pin); static bool is_valid_gpio(uint8_t pin);
static bool load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile); static bool load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile);
static void restart_requested(bool restart_requested) {
restart_requested_ = restart_requested;
}
static bool restart_requested() {
return restart_requested_;
}
bool analog_enabled() { bool analog_enabled() {
return analog_enabled_; return analog_enabled_;
} }
@@ -122,6 +130,7 @@ class System {
private: private:
static uuid::log::Logger logger_; static uuid::log::Logger logger_;
static uint32_t heap_start_; static uint32_t heap_start_;
static bool restart_requested_;
// button // button
static PButton myPButton_; // PButton instance static PButton myPButton_; // PButton instance

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.2.2b10" #define EMSESP_APP_VERSION "3.2.2b11"