LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#pragma once
2#if defined(ESP8266) || defined(ESP32)
3#include "FS.h"
4#endif
5
6#include <Arduino.h>
7#include "flashstream.h"
8#include <IPAddress.h>
9#include "systemconfigdata.h"
10
11
27 private:
29 flashStream * stream;
31 String currentConfigETAG;
37 int openStream(char mode = '\0');
38
39 public:
42
44 systemConfig():currentConfigETAG() {stream=NULL;};
49 systemConfig(flashStream * fs):currentConfigETAG() {stream=fs;};
50
55 bool isValidSysConf();
56
61 bool getMAC();
66 String getMACString();
72 bool setMAC(macAddress& mac);
73
80 char * getMQTTpwd(char * buffer, uint16_t bufLen);
86 bool setMQTTpwd(char * pwd = NULL);
87
94 char * getOTApwd(char * buffer, uint16_t bufLen);
100 bool setOTApwd(char * pwd = NULL);
101
109 bool setServer(char* url);
116 char * getServer(char * buffer, uint16_t bufLen);
117
123 bool getIP(IPAddress& ip);
129 bool getMask(IPAddress& mask);
135 bool getDNS(IPAddress& dns);
141 bool getGW(IPAddress& gw);
142
148 bool setIP(IPAddress& ip);
154 bool setMask(IPAddress& mask);
160 bool setDNS(IPAddress& dns);
166 bool setGW(IPAddress& gw);
167
173 bool setSerialDebuglevel(short);
179 bool setUdpDebuglevel(short);
184 uint8_t getSerialDebuglevel();
189 uint8_t getUdpDebuglevel();
190
195 bool clear();
200 bool getSaveSuccedConfig();
206 bool setSaveSuccedConfig(bool);
211 bool getLoadHTTPConfig();
218 bool setLoadHTTPConfig(bool);
223 String getETAG();
229 bool setETAG(String etag);
234 bool saveETAG();
239 bool loadETAG();
240
245 bool getDHCPfallback();
251 bool setDHCPfallback(bool flag);
252
264
265 //bool Save();
266};
Definition flashstream.h:52
char * getOTApwd(char *buffer, uint16_t bufLen)
Reads the OTA (HTTP update) password from flash.
Definition config.cpp:92
systemConfig(flashStream *fs)
Constructs a config manager over the given flash stream.
Definition config.h:49
bool setUdpDebuglevel(short)
Sets the UDP (syslog) log level in flash.
Definition config.cpp:330
bool setLoadHTTPConfig(bool)
Enables/disables fetching the config from the portal over HTTP (disabled permanently after a local co...
Definition config.cpp:315
systemConfigFlags getConfigFlags()
Returns the packed system configuration flags from flash.
Definition config.cpp:253
macAddress mac
MAC address of the controller, kept in memory after load.
Definition config.h:41
bool getMAC()
Loads the MAC address from flash into the mac member.
Definition config.cpp:38
bool setMQTTpwd(char *pwd=NULL)
Stores the MQTT password in flash (NULL clears it).
Definition config.cpp:80
bool clear()
Wipes the whole config block and restores defaults.
Definition config.cpp:235
bool setConfigFlags(systemConfigFlags flags)
Writes the packed system configuration flags to flash.
Definition config.cpp:271
bool getMask(IPAddress &mask)
Loads the static subnet mask from flash.
Definition config.cpp:158
bool getIP(IPAddress &ip)
Loads the static IP address from flash.
Definition config.cpp:146
uint8_t getSerialDebuglevel()
Returns the stored serial log level.
Definition config.cpp:338
bool setOTApwd(char *pwd=NULL)
Stores the OTA password in flash (NULL clears it).
Definition config.cpp:107
uint8_t getUdpDebuglevel()
Returns the stored UDP log level.
Definition config.cpp:344
bool setGW(IPAddress &gw)
Stores the static default gateway address in flash.
Definition config.cpp:224
bool getDNS(IPAddress &dns)
Loads the static DNS server address from flash.
Definition config.cpp:170
char * getServer(char *buffer, uint16_t bufLen)
Reads the stored configuration server URL into a buffer.
Definition config.cpp:119
bool setDNS(IPAddress &dns)
Stores the static DNS server address in flash.
Definition config.cpp:213
bool setMask(IPAddress &mask)
Stores the static subnet mask in flash.
Definition config.cpp:203
bool getSaveSuccedConfig()
Returns whether a successfully downloaded config is auto-saved.
Definition config.cpp:283
String getMACString()
Returns the MAC address of the controller as a hex string.
Definition config.cpp:5
systemConfig()
Constructs a config manager without a backing storage.
Definition config.h:44
bool setDHCPfallback(bool flag)
Enables/disables static-IP-to-DHCP fallback in flash.
Definition config.cpp:302
bool loadETAG()
Loads the stored ETag from flash into memory.
Definition config.cpp:379
bool setSerialDebuglevel(short)
Sets the serial (debug port) log level in flash.
Definition config.cpp:323
char * getMQTTpwd(char *buffer, uint16_t bufLen)
Reads the MQTT password from flash into a caller buffer.
Definition config.cpp:64
bool setIP(IPAddress &ip)
Stores the static IP address in flash.
Definition config.cpp:193
bool setETAG(String etag)
Sets the in-memory ETag of the remote config (strips quotes).
Definition config.cpp:356
bool getDHCPfallback()
Returns whether static-IP-to-DHCP fallback is enabled.
Definition config.cpp:296
bool saveETAG()
Persists the in-memory ETag to flash.
Definition config.cpp:367
bool setSaveSuccedConfig(bool)
Enables/disables auto-save of a successfully downloaded config.
Definition config.cpp:289
bool isValidSysConf()
Checks that the stored config block has a valid signature.
Definition config.cpp:22
bool getLoadHTTPConfig()
Returns whether the config is fetched from the portal over HTTP.
Definition config.cpp:309
bool setMAC(macAddress &mac)
Stores the given MAC address into flash.
Definition config.cpp:53
String getETAG()
Returns the ETag of the current remote config, quoted for HTTP.
Definition config.cpp:350
bool getGW(IPAddress &gw)
Loads the static default gateway address from flash.
Definition config.cpp:181
bool setServer(char *url)
Stores the URL of the remote configuration server in flash. Falls back to the compile-time MY_CONFIG_...
Definition config.cpp:134
Fixed-layout binary system configuration block stored in flash.
uint8_t macAddress[6]
6-byte MAC address.
Definition systemconfigdata.h:38
Packed 32-bit system configuration flags.
Definition systemconfigdata.h:43