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