Skip to content

Commit

Permalink
Merge pull request #504 from EVerest/jc/enhanced-wifi-setup
Browse files Browse the repository at this point in the history
enhanced wifi setup
  • Loading branch information
james-ctc authored Jan 23, 2024
2 parents b49a853 + 8752531 commit 1754279
Show file tree
Hide file tree
Showing 13 changed files with 1,170 additions and 420 deletions.
2 changes: 2 additions & 0 deletions modules/Setup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!meson.build

6 changes: 5 additions & 1 deletion modules/Setup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ ev_setup_cpp_module()

# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"RunApplication.cpp"
"WiFiSetup.cpp"
)# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
PRIVATE
Expand Down
22 changes: 21 additions & 1 deletion modules/Setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,29 @@ To add a wifi network a payload with the following format must be published to t
{
"interface": "wlan0",
"ssid": "Example",
"psk": "a_valid_pre_shared_key"
"psk": "20fcb529dee0aad11b0568f553942850d06e4c4531c0d75b35345d580b300f78"
}
```
The PSK field can represent the passphrase instead using escaped quotes:
```json
{
"interface": "wlan0",
"ssid": "Example",
"psk": "\"A_valid_passphrase\""
}
```
For open WiFi networks the psk must be an empty string `"psk": ""`.

For hidden networks an optional item is needed:
```json
{
"interface": "wlan0",
"ssid": "Example",
"psk": "\"A_valid_passphrase\"",
"hidden": true
}
```
When `hidden` is not supplied then it is assumed to be false.

### everest_api/setup/cmd/enable_network
To enable a wifi network a payload with the following format must be published to this topic:
Expand Down
39 changes: 39 additions & 0 deletions modules/Setup/RunApplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#include "RunApplication.hpp"

#include <boost/process.hpp>
#include <fmt/core.h>

#include <everest/logging.hpp>

namespace module {

CmdOutput run_application(const std::string& name, std::vector<std::string> args) {
// search_path requires basename and not a full path
boost::filesystem::path path = name;

if (path.is_relative()) {
path = boost::process::search_path(name);
}

if (path.empty()) {
EVLOG_debug << fmt::format("The application '{}' could not be found", name);
return CmdOutput{"", {}, 1};
}

boost::process::ipstream stream;
boost::process::child cmd(path, boost::process::args(args), boost::process::std_out > stream);
std::string output;
std::vector<std::string> split_output;
std::string temp;
while (std::getline(stream, temp)) {
output += temp + "\n";
split_output.push_back(temp);
}
cmd.wait();
return CmdOutput{output, split_output, cmd.exit_code()};
}

} // namespace module
21 changes: 21 additions & 0 deletions modules/Setup/RunApplication.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef RUNAPPLICATION_HPP
#define RUNAPPLICATION_HPP

#include <string>
#include <vector>

namespace module {

struct CmdOutput {
std::string output;
std::vector<std::string> split_output;
int exit_code;
};

CmdOutput run_application(const std::string& name, std::vector<std::string> args);

} // namespace module

#endif // RUNAPPLICATION_HPP
Loading

0 comments on commit 1754279

Please sign in to comment.