From b86f47363ec011c52fedffe297bac88efe76529b Mon Sep 17 00:00:00 2001 From: Artem Kravchenko Date: Sat, 12 Feb 2022 17:29:00 +0300 Subject: [PATCH] Fix update wifi settings --- .vscode/extensions.json | 17 ++++++++++------- src/Web/Web.cpp | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0f0d740..080e70d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,10 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/src/Web/Web.cpp b/src/Web/Web.cpp index 2d4f6a9..d1ac689 100644 --- a/src/Web/Web.cpp +++ b/src/Web/Web.cpp @@ -41,29 +41,29 @@ Web::Web(WifiService* wifiService, Settings* settings) request->send(response); }); - _server->on("/api/settings", HTTP_POST, [this](AsyncWebServerRequest *request) { - if (request->hasParam("mavlinkPort", true)) { - AsyncWebParameter* mavlinkPort = request->getParam("mavlinkPort", true); + _server->on("/api/settings/wifi", HTTP_POST, [this](AsyncWebServerRequest *request) { + if (request->hasParam("wifiSSID", true) && request->hasParam("wifiPassword", true)) { + AsyncWebParameter* wifiSSID = request->getParam("wifiSSID", true); + AsyncWebParameter* wifiPassword = request->getParam("wifiPassword", true); - _settings->setMavlinkPort(atoi(mavlinkPort->value().c_str())); + _settings->setWifiAPSSID(wifiSSID->value()); + _settings->setWifiAPPassword(wifiPassword->value()); request->send(200, "application/json", "{}"); } else { - request->send(422, "application/json", "{}"); + request->send(422, "application/json", "{\"message\": \"empty wifiSSID or wifiPassword\"}"); } }); - _server->on("/api/settings/wifi", HTTP_POST, [this](AsyncWebServerRequest *request) { - if (request->hasParam("wifiSSID", true) && request->hasParam("wifiPassword", true)) { - AsyncWebParameter* wifiSSID = request->getParam("wifiSSID", true); - AsyncWebParameter* wifiPassword = request->getParam("wifiPassword", true); + _server->on("/api/settings", HTTP_POST, [this](AsyncWebServerRequest *request) { + if (request->hasParam("mavlinkPort", true)) { + AsyncWebParameter* mavlinkPort = request->getParam("mavlinkPort", true); - _settings->setWifiAPSSID(wifiSSID->value()); - _settings->setWifiAPPassword(wifiPassword->value()); + _settings->setMavlinkPort(atoi(mavlinkPort->value().c_str())); request->send(200, "application/json", "{}"); } else { - request->send(422, "application/json", "{}"); + request->send(422, "application/json", "{\"message\": \"empty mavlinkPort\"}"); } });