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