Add PoC support for BSSID

This commit is contained in:
Lorow
2026-01-10 22:05:26 +01:00
parent c6584af3b5
commit e205509fec
13 changed files with 139 additions and 209 deletions

View File

@@ -170,14 +170,23 @@ struct WiFiConfig_t : BaseConfigModel
// default constructor used for loading
WiFiConfig_t(Preferences* pref) : BaseConfigModel(pref) {}
WiFiConfig_t(Preferences* pref, const uint8_t index, std::string name, std::string ssid, std::string password, const uint8_t channel, const uint8_t power)
: BaseConfigModel(pref), index(index), name(std::move(name)), ssid(std::move(ssid)), password(std::move(password)), channel(channel), power(power)
WiFiConfig_t(Preferences* pref, const uint8_t index, std::string name, std::string ssid, std::string bssid, std::string password, const uint8_t channel,
const uint8_t power)
: BaseConfigModel(pref),
index(index),
name(std::move(name)),
ssid(std::move(ssid)),
bssid(std::move(bssid)),
password(std::move(password)),
channel(channel),
power(power)
{
}
uint8_t index;
std::string name;
std::string ssid;
std::string bssid;
std::string password;
uint8_t channel;
uint8_t power;
@@ -190,6 +199,7 @@ struct WiFiConfig_t : BaseConfigModel
auto const iter_str = std::string(Helpers::itoa(index, buffer, 10));
this->name = this->pref->getString(("name" + iter_str).c_str(), "");
this->ssid = this->pref->getString(("ssid" + iter_str).c_str(), "");
this->bssid = this->pref->getString(("bssid" + iter_str).c_str(), "");
this->password = this->pref->getString(("password" + iter_str).c_str(), "");
this->channel = this->pref->getUInt(("channel" + iter_str).c_str());
this->power = this->pref->getUInt(("power" + iter_str).c_str());
@@ -204,6 +214,7 @@ struct WiFiConfig_t : BaseConfigModel
this->pref->putString(("name" + iter_str).c_str(), this->name.c_str());
this->pref->putString(("ssid" + iter_str).c_str(), this->ssid.c_str());
this->pref->putString(("bssid" + iter_str).c_str(), this->bssid.c_str());
this->pref->putString(("password" + iter_str).c_str(), this->password.c_str());
this->pref->putUInt(("channel" + iter_str).c_str(), this->channel);
this->pref->putUInt(("power" + iter_str).c_str(), this->power);
@@ -213,8 +224,8 @@ struct WiFiConfig_t : BaseConfigModel
std::string toRepresentation()
{
return Helpers::format_string("{\"name\": \"%s\", \"ssid\": \"%s\", \"password\": \"%s\", \"channel\": %u, \"power\": %u}", this->name.c_str(),
this->ssid.c_str(), this->password.c_str(), this->channel, this->power);
return Helpers::format_string("{\"name\": \"%s\", \"ssid\": \"%s\", \"bssid\": \"%s\", \"password\": \"%s\", \"channel\": %u, \"power\": %u}",
this->name.c_str(), this->ssid.c_str(), this->bssid.c_str(), this->password.c_str(), this->channel, this->power);
};
};

View File

@@ -127,7 +127,8 @@ void ProjectConfig::setCameraConfig(const uint8_t vflip, const uint8_t framesize
ESP_LOGD(CONFIGURATION_TAG, "Updating Camera config");
}
void ProjectConfig::setWifiConfig(const std::string& networkName, const std::string& ssid, const std::string& password, uint8_t channel, uint8_t power)
void ProjectConfig::setWifiConfig(const std::string& networkName, const std::string& ssid, const std::string& bssid, const std::string& password,
uint8_t channel, uint8_t power)
{
const auto size = this->config.networks.size();
@@ -139,6 +140,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName, const std::str
it->name = networkName;
it->ssid = ssid;
it->bssid = bssid;
it->password = password;
it->channel = channel;
it->power = power;
@@ -150,7 +152,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName, const std::str
if (size == 0)
{
ESP_LOGI(CONFIGURATION_TAG, "No networks, We're adding a new network");
this->config.networks.emplace_back(this->pref, static_cast<uint8_t>(0), networkName, ssid, password, channel, power);
this->config.networks.emplace_back(this->pref, static_cast<uint8_t>(0), networkName, ssid, bssid, password, channel, power);
// Save the new network immediately
this->config.networks.back().save();
saveNetworkCount(this->pref, 1);
@@ -162,10 +164,10 @@ void ProjectConfig::setWifiConfig(const std::string& networkName, const std::str
{
ESP_LOGI(CONFIGURATION_TAG, "We're adding a new network");
// we don't have that network yet, we can add it as we still have some
// space we're using emplace_back as push_back will create a copy of it,
// space, we're using emplace_back as push_back will create a copy of it,
// we want to avoid that
uint8_t last_index = getNetworkCount(this->pref);
this->config.networks.emplace_back(this->pref, last_index, networkName, ssid, password, channel, power);
this->config.networks.emplace_back(this->pref, last_index, networkName, ssid, bssid, password, channel, power);
// Save the new network immediately
this->config.networks.back().save();
saveNetworkCount(this->pref, static_cast<int>(this->config.networks.size()));

View File

@@ -37,7 +37,8 @@ class ProjectConfig
void setLEDDUtyCycleConfig(int led_external_pwm_duty_cycle);
void setMDNSConfig(const std::string& hostname);
void setCameraConfig(uint8_t vflip, uint8_t framesize, uint8_t href, uint8_t quality, uint8_t brightness);
void setWifiConfig(const std::string& networkName, const std::string& ssid, const std::string& password, uint8_t channel, uint8_t power);
void setWifiConfig(const std::string& networkName, const std::string& ssid, const std::string& bssid, const std::string& password, uint8_t channel,
uint8_t power);
void deleteWifiConfig(const std::string& networkName);