mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add system commands for syslog level and watch
This commit is contained in:
@@ -46,6 +46,7 @@ MAKE_PSTR_WORD(restart)
|
||||
MAKE_PSTR_WORD(format)
|
||||
MAKE_PSTR_WORD(raw)
|
||||
MAKE_PSTR_WORD(watch)
|
||||
MAKE_PSTR_WORD(syslog_level)
|
||||
MAKE_PSTR_WORD(send)
|
||||
MAKE_PSTR_WORD(telegram)
|
||||
MAKE_PSTR_WORD(bus_id)
|
||||
@@ -114,6 +115,8 @@ MAKE_PSTR(log_level_fmt, "Log level: %s")
|
||||
|
||||
MAKE_STR(productid_fmt, "%s EMS Product ID")
|
||||
|
||||
MAKE_PSTR_LIST(enum_syslog_level, F_(off), F("emerg"), F("alert"), F("crit"), F("error"), F("warn"), F("notice"), F_(info), F_(debug), F("trace"), F("all"))
|
||||
MAKE_PSTR_LIST(enum_watch, F_(off), F_(on), F_(raw), F_(unknown))
|
||||
// strings
|
||||
MAKE_PSTR(EMSESP, "EMS-ESP")
|
||||
MAKE_PSTR(cmd_optional, "[cmd]")
|
||||
|
||||
@@ -122,6 +122,41 @@ bool System::command_publish(const char * value, const int8_t id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// syslog level
|
||||
bool System::command_syslog_level(const char * value, const int8_t id) {
|
||||
uint8_t s = 0xff;
|
||||
if (Helpers::value2enum(value, s, FL_(enum_syslog_level))) {
|
||||
EMSESP::webSettingsService.update([&](WebSettings & settings) {
|
||||
settings.syslog_level = (int8_t)s - 1;
|
||||
return StateUpdateResult::CHANGED;
|
||||
}, "local");
|
||||
EMSESP::system_.syslog_start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// watch
|
||||
bool System::command_watch(const char * value, const int8_t id) {
|
||||
uint8_t w = 0xff;
|
||||
if (Helpers::value2enum(value, w, FL_(enum_watch))) {
|
||||
if (w == 0 || EMSESP::watch() == EMSESP::Watch::WATCH_OFF) {
|
||||
EMSESP::watch_id(0);
|
||||
}
|
||||
EMSESP::watch(w);
|
||||
return true;
|
||||
}
|
||||
uint16_t i = Helpers::hextoint(value);
|
||||
if (i) {
|
||||
EMSESP::watch_id(i);
|
||||
if (EMSESP::watch() == EMSESP::Watch::WATCH_OFF) {
|
||||
EMSESP::watch(EMSESP::Watch::WATCH_ON);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// restart EMS-ESP
|
||||
void System::restart() {
|
||||
LOG_INFO(F("Restarting system..."));
|
||||
@@ -620,6 +655,8 @@ void System::commands_init() {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F("test"), System::command_test, F("run tests"));
|
||||
#endif
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, F("watching telegrams"), CommandFlag::ADMIN_ONLY);
|
||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog_level), System::command_syslog_level, F("set syslog level"), CommandFlag::ADMIN_ONLY);
|
||||
}
|
||||
|
||||
// flashes the LED
|
||||
|
||||
@@ -56,6 +56,8 @@ class System {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
static bool command_test(const char * value, const int8_t id);
|
||||
#endif
|
||||
static bool command_syslog_level(const char * value, const int8_t id);
|
||||
static bool command_watch(const char * value, const int8_t id);
|
||||
|
||||
static bool command_info(const char * value, const int8_t id, JsonObject & json);
|
||||
static bool command_settings(const char * value, const int8_t id, JsonObject & json);
|
||||
|
||||
Reference in New Issue
Block a user