Initial commit
This commit is contained in:
30
src/config.cpp
Normal file
30
src/config.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "config.h"
|
||||
|
||||
void initialize_config(Config *config, StaticJsonDocument<512> json) {
|
||||
config->ssid = strdup(json["ssid"]);
|
||||
config->psk = strdup(json["psk"]);
|
||||
config->mqtt_host = strdup(json["mqtt_host"]);
|
||||
config->mqtt_user = strdup(json["mqtt_user"]);
|
||||
config->mqtt_password = strdup(json["mqtt_password"]);
|
||||
config->topic = strdup(json["mqtt_topic"]);
|
||||
config->device_id = strdup(json["device_id"]);
|
||||
config->mqtt_port = json["mqtt_port"];
|
||||
config->sleep_time = minutes_to_microseconds(json["sleep_time"]);
|
||||
config->connection_attempts = json["connection_attempts"];
|
||||
}
|
||||
|
||||
bool load_config_file(const char *file_path, Config *config) {
|
||||
if (!LittleFS.begin())
|
||||
return false;
|
||||
File config_file = LittleFS.open(file_path, "r");
|
||||
if (!config_file)
|
||||
return false;
|
||||
StaticJsonDocument<512> json;
|
||||
DeserializationError err = deserializeJson(json, config_file);
|
||||
if (err)
|
||||
return false;
|
||||
initialize_config(config, json);
|
||||
return true;
|
||||
}
|
||||
|
||||
long minutes_to_microseconds(int minutes) { return (minutes * 6e7); }
|
||||
Reference in New Issue
Block a user