Skip to content

Commit

Permalink
Fix update wifi settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lan143 committed Feb 12, 2022
1 parent 0cb709b commit b86f473
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
17 changes: 10 additions & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
24 changes: 12 additions & 12 deletions src/Web/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}");
}
});

Expand Down

0 comments on commit b86f473

Please sign in to comment.