7#include "..\UsedInterrupts.h"
84 time_t currentTime = time(NULL);
86 localtime_r(¤tTime, &tmBuf);
87 uint32_t currentSeconds = tmBuf.tm_hour * 3600 + tmBuf.tm_min * 60 + tmBuf.tm_sec;
108 String start = file.readStringUntil(
'\n');
109 String end = file.readStringUntil(
'\n');
110 String restrictions = file.readStringUntil(
'\n');
114 if (start.isEmpty() || end.isEmpty() || restrictions.isEmpty()) {
123 startTime = strtoul(start.c_str(), NULL, 0);
124 endTime = strtoul(end.c_str(), NULL, 0);
126 unsigned long l = strtoul(restrictions.c_str(), NULL, 0);
148#pragma region Singelton
178#pragma region WiFi Settings
192#pragma region Emlalock settings
220#pragma region Miscellaneous Settings
260#pragma region WiFi Settings
278#pragma region Emlalock settings
315#pragma region Miscellaneous Settings
411 this->timeRestrictions.
startTime = std::min(this->timeRestrictions.
startTime, (uint32_t)86400);
412 this->timeRestrictions.
endTime = std::min(this->timeRestrictions.
endTime, (uint32_t)86400);
421 std::srand((
unsigned int)micros());
422 for (
int i = 0; i < 6; i++) {
443 timezone =
"CET-1CEST,M3.5.0,M10.5.0/3";
458 File file = SPIFFS.open(
"/configuration.txt",
"r");
460 Serial.println(
"Loading configuration.txt failed");
464 ssid = file.readStringUntil(
'\n');
466 pwd = file.readStringUntil(
'\n');
468 userId = file.readStringUntil(
'\n');
470 apiKey = file.readStringUntil(
'\n');
475 emergencyKey =
"AAAAAA";
478 timezone = file.readStringUntil(
'\n');
489 file = SPIFFS.open(
"/configuration.txt",
"r");
490 Serial.printf(
"configuration.txt: \n\"%s\"\n", file.readString().c_str());
501 File file = SPIFFS.open(
"/configuration.txt",
"w");
503 Serial.println(
"Loading configuration.txt failed");
532 x = std::rand() / ((RAND_MAX + 1u) / 35);
536 return (
char)x +
'A';
538 return (
char)x - 26 +
'0';
static void executeWithoutInterrupts(std::function< void(void)> f)
Execute the passed function without interrupts.
Definition: UsedInterrupts.h:58
Container to restrict the time when the safe can be opened.
Definition: Configuration.h:27
bool restrictUnlockTimes
If set, the safe can only be opened during the specified time using the normal unlock function.
Definition: Configuration.h:46
bool restrictEmergencyKeyTimes
If set, the time when the emergency key is accepted is restricted.
Definition: Configuration.h:58
bool restrictHygieneOpeningTimes
If set, the time for hygiene openings is restricted.
Definition: Configuration.h:52
void writeToFile(File &file)
Writes all configuration items of this class to the file at the current stream position.
Definition: Configuration.h:140
uint32_t startTime
The number of seconds after midnight after which the safe can be opened.
Definition: Configuration.h:34
bool restrictConfigurationServer
If set, the time when the configuration server can be started is restricted.
Definition: Configuration.h:64
TimeRestrictions()
Construct a new Time Restrictions object.
Definition: Configuration.h:70
uint32_t endTime
The number of seconds after midnight until which the safe can be opened.
Definition: Configuration.h:40
void readFromFile(File &file)
Reads the content of this class from the configuration file stream.
Definition: Configuration.h:107
bool checkTime() const
check if the current time is valid for opening the safe
Definition: Configuration.h:82
Static class accessing the configuration.
Definition: Configuration.h:20
String timezoneName
The name to the timezone-string (e.g. "Europe/Berlin")
Definition: Configuration.h:232
static char getRandomChar()
Get a random character (A-Z, 0-9)
Definition: Configuration.h:526
const bool & getAutoLockHygieneOpeningTimeout() const
return if the safe should automatically lock after the time for hygiene opening is over....
Definition: Configuration.h:346
const String & getTimezone() const
get the timezone-string (e.g. "CET-1CEST,M3.5.0,M10.5.0/3") see also https://github....
Definition: Configuration.h:321
void setConfigurationSettings(const String &userId, const String &apiKey, const bool &disableFailedSession, const String &timezoneName, const String &timezone, const long &backlightTimeOut, const bool &autoLockHygieneOpeningTimeout, const TimeRestrictions &timeRestrictions)
Set the Configuration Settings.
Definition: Configuration.h:389
const bool & getDisableFailedSession() const
get disable support of failed session. Note: If selected, the safe will be locked until the last know...
Definition: Configuration.h:309
const unsigned long & getBacklightTimeOut() const
get the timeout of display backlight in seconds
Definition: Configuration.h:337
bool disableFailedSession
Disable support of failed session. Note: If selected, the safe will be locked until the last known en...
Definition: Configuration.h:217
const String & getUserId() const
get the User ID extracted from the webpage settings > API
Definition: Configuration.h:283
String ssid
The SSID(name) of your wifi.
Definition: Configuration.h:183
void restoreFactoryDefaults()
Reset all values to the default values and write configuration.
Definition: Configuration.h:436
static Configuration ** getInstance()
Function providing the instance for the singleton.
Definition: Configuration.h:153
TimeRestrictions timeRestrictions
Container to restrict the time when the safe can be opened.
Definition: Configuration.h:251
const String & generateNewEmergencyKey()
Generates a new key and stores it to the file system.
Definition: Configuration.h:420
String timezone
The timezone-string (e.g. "CET-1CEST,M3.5.0,M10.5.0/3") see also https://github.com/nayarsystems/posi...
Definition: Configuration.h:226
String apiKey
The API Key extracted from the webpage settings > API.
Definition: Configuration.h:203
const TimeRestrictions & getTimeRestrictions() const
get the timeout of display backlight in seconds
Definition: Configuration.h:354
String userId
The User ID extracted from the webpage settings > API.
Definition: Configuration.h:197
void readConfiguration()
Read all configuration data from file.
Definition: Configuration.h:455
unsigned long backlightTimeOut
Timeout of display backlight in seconds.
Definition: Configuration.h:238
const String & getSsid() const
get the SSID(name) of your wifi
Definition: Configuration.h:265
const String & getTimezoneName() const
get the name to the timezone-string (e.g. "Europe/Berlin")
Definition: Configuration.h:329
const String & getPwd() const
get the password of your wifi.
Definition: Configuration.h:273
static Configuration & getSingleton()
Get the Singleton object.
Definition: Configuration.h:162
const String & getEmergencyKey() const
get the emergency key of the safe
Definition: Configuration.h:299
void setWifiSettings(const String &ssid, const String &pwd)
Set the Wifi Settings.
Definition: Configuration.h:368
const String & getApiKey() const
get the API Key extracted from the webpage settings > API
Definition: Configuration.h:291
String emergencyKey
The emergency key.
Definition: Configuration.h:209
Configuration()
Definition: Configuration.h:255
bool autoLockHygieneOpeningTimeout
Automatically lock after the time for hygiene opening is over. If not set, the safe stays unlocked un...
Definition: Configuration.h:245
static Configuration & begin()
initialize the configuration object and load the configuration file
Definition: Configuration.h:170
String pwd
The password of your wifi.
Definition: Configuration.h:189
void writeConfiguration()
writes all configuration values to the SPIFFS
Definition: Configuration.h:498
Definition: Configuration.h:16