Wifi
This commit is contained in:
parent
6b7ad96708
commit
ff1e9bb4d5
@ -267,19 +267,29 @@ std::vector<std::string> Wifi::getSavedNetworks() {
|
||||
|
||||
size_t required_size = 0;
|
||||
err = nvs_get_str(handle, "networks", nullptr, &required_size);
|
||||
if (err == ESP_OK && required_size > 0) {
|
||||
std::string networkList(required_size, '\0');
|
||||
nvs_get_str(handle, "networks", &networkList[0], &required_size);
|
||||
if (err == ESP_OK && required_size > 1) {
|
||||
char* buf = new char[required_size];
|
||||
nvs_get_str(handle, "networks", buf, &required_size);
|
||||
std::string networkList(buf);
|
||||
delete[] buf;
|
||||
|
||||
size_t start = 0;
|
||||
size_t end = networkList.find(';');
|
||||
while (end != std::string::npos) {
|
||||
networks.push_back(networkList.substr(start, end - start));
|
||||
start = end + 1;
|
||||
end = networkList.find(';', start);
|
||||
}
|
||||
if (start < networkList.size() - 1) {
|
||||
networks.push_back(networkList.substr(start));
|
||||
if (!networkList.empty()) {
|
||||
size_t start = 0;
|
||||
size_t end = networkList.find(';');
|
||||
while (end != std::string::npos) {
|
||||
std::string net = networkList.substr(start, end - start);
|
||||
if (!net.empty()) {
|
||||
networks.push_back(net);
|
||||
}
|
||||
start = end + 1;
|
||||
end = networkList.find(';', start);
|
||||
}
|
||||
if (start < networkList.size()) {
|
||||
std::string net = networkList.substr(start);
|
||||
if (!net.empty()) {
|
||||
networks.push_back(net);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ public:
|
||||
void disconnect();
|
||||
bool isConnected();
|
||||
std::string getCurrentSSID();
|
||||
std::string getIPAddress();
|
||||
int8_t getRSSI();
|
||||
|
||||
void saveNetwork(const char* ssid, const char* password);
|
||||
void removeNetwork(const char* ssid);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user