mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 09:19:51 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -246,7 +246,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
networkSettings.password = password2.c_str();
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
shell.println("WiFi password updated");
|
||||
shell.println("WiFi password updated. Reconnecting...");
|
||||
to_app(shell).system_.wifi_reconnect();
|
||||
} else {
|
||||
shell.println("Passwords do not match");
|
||||
}
|
||||
@@ -279,7 +280,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
networkSettings.ssid = arguments.front().c_str();
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
shell.println("WiFi ssid updated");
|
||||
shell.println("WiFi ssid updated. Reconnecting...");
|
||||
to_app(shell).system_.wifi_reconnect();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -22,10 +22,8 @@ namespace emsesp {
|
||||
|
||||
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: events_(EVENT_SOURCE_LOG_PATH) {
|
||||
// set settings
|
||||
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { setValues(request, json); });
|
||||
// get settings
|
||||
server->on(LOG_SETTINGS_PATH, HTTP_GET, [this](AsyncWebServerRequest * request) { getValues(request); });
|
||||
// get & set settings
|
||||
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); });
|
||||
|
||||
// for bring back the whole log - is a command, hence a POST
|
||||
server->on(FETCH_LOG_PATH, HTTP_POST, [this](AsyncWebServerRequest * request) { fetchLog(request); });
|
||||
@@ -203,11 +201,20 @@ void WebLogService::fetchLog(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
// sets the values like level after a POST
|
||||
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
if (!json.is<JsonObject>()) {
|
||||
void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
if ((request->method() == HTTP_GET) || (!json.is<JsonObject>())) {
|
||||
// GET - return the values
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
root["level"] = log_level();
|
||||
root["max_messages"] = maximum_log_messages();
|
||||
root["compact"] = compact();
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
return;
|
||||
}
|
||||
|
||||
// POST - write the settings
|
||||
auto && body = json.as<JsonObject>();
|
||||
|
||||
uuid::log::Level level = body["level"];
|
||||
@@ -222,15 +229,4 @@ void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json)
|
||||
request->send(200); // OK
|
||||
}
|
||||
|
||||
// return the current value settings after a GET
|
||||
void WebLogService::getValues(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
root["level"] = log_level();
|
||||
root["max_messages"] = maximum_log_messages();
|
||||
root["compact"] = compact();
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
@@ -60,12 +60,10 @@ class WebLogService : public uuid::log::Handler {
|
||||
|
||||
void transmit(const QueuedLogMessage & message);
|
||||
void fetchLog(AsyncWebServerRequest * request);
|
||||
void getValues(AsyncWebServerRequest * request);
|
||||
void getSetValues(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
|
||||
|
||||
void setValues(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
uint64_t last_transmit_ = 0; // Last transmit time
|
||||
size_t maximum_log_messages_ = MAX_LOG_MESSAGES; // Maximum number of log messages to buffer before they are output
|
||||
size_t limit_log_messages_ = 1; // dynamic limit
|
||||
|
||||
Reference in New Issue
Block a user