settings wrapper
This commit is contained in:
@@ -51,7 +51,7 @@ void unlock()
|
||||
}
|
||||
|
||||
bool isConnecting = false;
|
||||
void initWifi(YAMLNode *settings)
|
||||
void initWifi(Settings *settings)
|
||||
{
|
||||
if (!settings)
|
||||
{
|
||||
@@ -98,7 +98,7 @@ void initWifi(YAMLNode *settings)
|
||||
}
|
||||
}
|
||||
|
||||
void initTOTP(YAMLNode *settings)
|
||||
void initTOTP(Settings *settings)
|
||||
{
|
||||
uint8_t *base32_key = new uint8_t[20];
|
||||
const char *hmac = ((String)settings->gettext("totp:hmac")).c_str();
|
||||
@@ -118,7 +118,7 @@ void setup()
|
||||
keypad_init();
|
||||
keypad_write("loading");
|
||||
|
||||
auto settings = settings_load();
|
||||
auto settings = new Settings();
|
||||
|
||||
if (!settings)
|
||||
{
|
||||
@@ -132,8 +132,6 @@ void setup()
|
||||
mqtt->connect();
|
||||
setupTime();
|
||||
initTOTP(settings);
|
||||
|
||||
// lock();
|
||||
}
|
||||
|
||||
void submit(String code)
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
WiFiClient wifiClient;
|
||||
|
||||
MQTT::MQTT(YAMLNode *settings, MQTT_CALLBACK_SIGNATURE)
|
||||
MQTT::MQTT(Settings *settings, MQTT_CALLBACK_SIGNATURE)
|
||||
{
|
||||
IPAddress ip;
|
||||
if (!ip.fromString(settings->gettext("mqtt:hostname")))
|
||||
|
@@ -4,20 +4,19 @@
|
||||
#include <WString.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoYaml.h>
|
||||
#include "settings.hpp"
|
||||
|
||||
class MQTT
|
||||
{
|
||||
|
||||
public:
|
||||
MQTT(YAMLNode *settings, MQTT_CALLBACK_SIGNATURE);
|
||||
MQTT(Settings *settings, MQTT_CALLBACK_SIGNATURE);
|
||||
void connect();
|
||||
void send(String);
|
||||
void loop();
|
||||
|
||||
private:
|
||||
YAMLNode *settings = nullptr;
|
||||
Settings *settings = nullptr;
|
||||
PubSubClient *client = nullptr;
|
||||
};
|
||||
|
||||
|
@@ -1,18 +1,21 @@
|
||||
#include "settings.hpp"
|
||||
#include <SD.h>
|
||||
|
||||
YAMLNode *settings_load()
|
||||
Settings::Settings()
|
||||
{
|
||||
Serial.println("Loading settings");
|
||||
if (!SD.exists("/settings.yml"))
|
||||
{
|
||||
Serial.println("settings.yml not found");
|
||||
return nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
File settingsFile = SD.open("/settings.yml");
|
||||
YAMLNode node = YAMLNode::loadStream(settingsFile);
|
||||
this->yaml = YAMLNode::loadStream(settingsFile);
|
||||
settingsFile.close();
|
||||
}
|
||||
|
||||
return new YAMLNode(node);
|
||||
}
|
||||
const char *Settings::gettext(const char *path, char delimiter)
|
||||
{
|
||||
return this->yaml.gettext(path, delimiter);
|
||||
}
|
||||
|
@@ -4,6 +4,14 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoYaml.h>
|
||||
|
||||
YAMLNode *settings_load();
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
Settings();
|
||||
const char *gettext(const char *path, char delimiter = (char)58);
|
||||
|
||||
private:
|
||||
YAMLNode yaml;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user