Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#include <settings/wifi/wifi.hpp>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <syslog.h>
|
|
|
|
#define WIFI_CHANNEL_REQUIRED_STRING R"({"required":"[token,channel]"})"
|
|
|
|
namespace api
|
|
{
|
|
namespace settings
|
|
{
|
|
namespace wifi
|
|
{
|
|
void set_wifi_channel(int new_channel)
|
|
{
|
|
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
|
std::string old_channel_string;
|
|
std::string wifisettingsbuffer;
|
|
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
|
{
|
|
if (wifisettingsbuffer.find("channel=") == 0)
|
|
{
|
|
old_channel_string = wifisettingsbuffer;
|
|
old_channel_string.erase(0, 8);
|
|
break;
|
|
}
|
|
}
|
|
wifisettingsfile.close();
|
|
std::cout << old_channel_string << std::endl;
|
|
int old_channel = std::stoi(old_channel_string);
|
|
std::string systemrequest;
|
|
systemrequest += "sed -i \"/channel=" \
|
|
+ std::to_string(old_channel) \
|
|
+ "/s//channel=" \
|
|
+ std::to_string(new_channel) \
|
|
+ "/\" /etc/hostapd/hostapd.conf";
|
|
std::cout << systemrequest << std::endl;
|
|
system(systemrequest.c_str());
|
|
system("rc restart hostapd");
|
|
std::string syslogstring = "WIFI channel changed to " + std::to_string(new_channel);
|
|
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|