mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Wifi configuration from NVS
This commit is contained in:
@@ -45,6 +45,29 @@ ModuleType ConfigManager::get_module_type() {
|
||||
return static_cast<ModuleType>(type);
|
||||
}
|
||||
|
||||
std::string ConfigManager::get_wifi_ssid() {
|
||||
return get_string(WIFI_SSID_KEY);
|
||||
}
|
||||
|
||||
std::string ConfigManager::get_wifi_password() {
|
||||
return get_string(WIFI_PASSWORD_KEY);
|
||||
}
|
||||
|
||||
std::string ConfigManager::get_string(const char *key) {
|
||||
nvs_handle config_handle;
|
||||
nvs_open(NVS_FLASH_NAMESPACE, NVS_READONLY, &config_handle);
|
||||
|
||||
size_t required_size; // get size of the string
|
||||
nvs_get_str(config_handle, key, nullptr, &required_size);
|
||||
|
||||
std::string str;
|
||||
str.resize(required_size);
|
||||
nvs_get_str(config_handle, key, str.data(), &required_size);
|
||||
|
||||
nvs_close(config_handle);
|
||||
return str;
|
||||
}
|
||||
|
||||
void ConfigManager::set_module_id(const uint16_t id) {
|
||||
nvs_handle config_handle;
|
||||
nvs_open(NVS_FLASH_NAMESPACE, NVS_READWRITE, &config_handle);
|
||||
@@ -58,3 +81,18 @@ void ConfigManager::set_module_type(const ModuleType type) {
|
||||
nvs_set_u16(config_handle, MODULE_TYPE_KEY, type);
|
||||
nvs_close(config_handle);
|
||||
}
|
||||
|
||||
void ConfigManager::set_wifi_ssid(const char* ssid) {
|
||||
nvs_handle config_handle;
|
||||
nvs_open(NVS_FLASH_NAMESPACE, NVS_READWRITE, &config_handle);
|
||||
nvs_set_str(config_handle, WIFI_SSID_KEY, ssid);
|
||||
nvs_close(config_handle);
|
||||
}
|
||||
|
||||
void ConfigManager::set_wifi_password(const char* password) {
|
||||
nvs_handle config_handle;
|
||||
nvs_open(NVS_FLASH_NAMESPACE, NVS_READWRITE, &config_handle);
|
||||
nvs_set_str(config_handle, WIFI_PASSWORD_KEY, password);
|
||||
nvs_close(config_handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,17 @@ public:
|
||||
|
||||
static uint16_t get_module_id();
|
||||
static ModuleType get_module_type();
|
||||
static std::string get_wifi_ssid();
|
||||
static std::string get_wifi_password();
|
||||
|
||||
static void set_module_id(uint16_t id);
|
||||
static void set_module_type(ModuleType type);
|
||||
static void set_wifi_ssid(const char* ssid);
|
||||
static void set_wifi_password(const char* password);
|
||||
|
||||
private:
|
||||
static std::string get_string(const char* key);
|
||||
|
||||
};
|
||||
|
||||
#endif //CONFIGMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user