LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
systemConfig Class Reference

Persistent system configuration manager. More...

#include <config.h>

Public Member Functions

 systemConfig ()
 Constructs a config manager without a backing storage.
 systemConfig (flashStream *fs)
 Constructs a config manager over the given flash stream.
bool isValidSysConf ()
 Checks that the stored config block has a valid signature.
bool getMAC ()
 Loads the MAC address from flash into the mac member.
String getMACString ()
 Returns the MAC address of the controller as a hex string.
bool setMAC (macAddress &mac)
 Stores the given MAC address into flash.
char * getMQTTpwd (char *buffer, uint16_t bufLen)
 Reads the MQTT password from flash into a caller buffer.
bool setMQTTpwd (char *pwd=NULL)
 Stores the MQTT password in flash (NULL clears it).
char * getOTApwd (char *buffer, uint16_t bufLen)
 Reads the OTA (HTTP update) password from flash.
bool setOTApwd (char *pwd=NULL)
 Stores the OTA password in flash (NULL clears it).
bool setServer (char *url)
 Stores the URL of the remote configuration server in flash. Falls back to the compile-time MY_CONFIG_SERVER / CONFIG_SERVER when nothing is stored.
char * getServer (char *buffer, uint16_t bufLen)
 Reads the stored configuration server URL into a buffer.
bool getIP (IPAddress &ip)
 Loads the static IP address from flash.
bool getMask (IPAddress &mask)
 Loads the static subnet mask from flash.
bool getDNS (IPAddress &dns)
 Loads the static DNS server address from flash.
bool getGW (IPAddress &gw)
 Loads the static default gateway address from flash.
bool setIP (IPAddress &ip)
 Stores the static IP address in flash.
bool setMask (IPAddress &mask)
 Stores the static subnet mask in flash.
bool setDNS (IPAddress &dns)
 Stores the static DNS server address in flash.
bool setGW (IPAddress &gw)
 Stores the static default gateway address in flash.
bool setSerialDebuglevel (short)
 Sets the serial (debug port) log level in flash.
bool setUdpDebuglevel (short)
 Sets the UDP (syslog) log level in flash.
uint8_t getSerialDebuglevel ()
 Returns the stored serial log level.
uint8_t getUdpDebuglevel ()
 Returns the stored UDP log level.
bool clear ()
 Wipes the whole config block and restores defaults.
bool getSaveSuccedConfig ()
 Returns whether a successfully downloaded config is auto-saved.
bool setSaveSuccedConfig (bool)
 Enables/disables auto-save of a successfully downloaded config.
bool getLoadHTTPConfig ()
 Returns whether the config is fetched from the portal over HTTP.
bool setLoadHTTPConfig (bool)
 Enables/disables fetching the config from the portal over HTTP (disabled permanently after a local config change).
String getETAG ()
 Returns the ETag of the current remote config, quoted for HTTP.
bool setETAG (String etag)
 Sets the in-memory ETag of the remote config (strips quotes).
bool saveETAG ()
 Persists the in-memory ETag to flash.
bool loadETAG ()
 Loads the stored ETag from flash into memory.
bool getDHCPfallback ()
 Returns whether static-IP-to-DHCP fallback is enabled.
bool setDHCPfallback (bool flag)
 Enables/disables static-IP-to-DHCP fallback in flash.
systemConfigFlags getConfigFlags ()
 Returns the packed system configuration flags from flash.
bool setConfigFlags (systemConfigFlags flags)
 Writes the packed system configuration flags to flash.

Public Attributes

macAddress mac
 MAC address of the controller, kept in memory after load.

Detailed Description

Persistent system configuration manager.

Reads and writes the fixed-layout system configuration block (see systemConfigData) stored in flash/EEPROM through a flashStream: MAC address, static network parameters, MQTT/OTA passwords, the remote configuration server URL and assorted control flags. It also keeps track of the ETag of the last downloaded remote config, which is sent back as "If-None-Match" so that the portal server can answer 304 (not modified) and skip the download. The full JSON config load/save/submit workflow (HTTP download from MY_CONFIG_SERVER / CONFIG_SERVER, CRC validation, save to flash) is driven from main.cpp via loadConfigFromHttp(), cmdFunctionSave() and cmdFunctionLoad().

Constructor & Destructor Documentation

◆ systemConfig() [1/2]

systemConfig::systemConfig ( )
inline

Constructs a config manager without a backing storage.

◆ systemConfig() [2/2]

systemConfig::systemConfig ( flashStream * fs)
inline

Constructs a config manager over the given flash stream.

Parameters
fsPointer to the flashStream holding the config block.

Member Function Documentation

◆ clear()

bool systemConfig::clear ( )

Wipes the whole config block and restores defaults.

Returns
true on success.

◆ getConfigFlags()

systemConfigFlags systemConfig::getConfigFlags ( )

Returns the packed system configuration flags from flash.

Returns
Current flags (log levels, behavior bits, config hash).

◆ getDHCPfallback()

bool systemConfig::getDHCPfallback ( )

Returns whether static-IP-to-DHCP fallback is enabled.

Returns
true if the controller may fall back to DHCP.

◆ getDNS()

bool systemConfig::getDNS ( IPAddress & dns)

Loads the static DNS server address from flash.

Parameters
dnsOutput IPAddress.
Returns
true if a usable (non-blank) address was read.

◆ getETAG()

String systemConfig::getETAG ( )

Returns the ETag of the current remote config, quoted for HTTP.

Returns
ETag surrounded by double quotes (may be empty).

◆ getGW()

bool systemConfig::getGW ( IPAddress & gw)

Loads the static default gateway address from flash.

Parameters
gwOutput IPAddress.
Returns
true if a usable (non-blank) address was read.

◆ getIP()

bool systemConfig::getIP ( IPAddress & ip)

Loads the static IP address from flash.

Parameters
ipOutput IPAddress.
Returns
true if a usable (non-blank) address was read.

◆ getLoadHTTPConfig()

bool systemConfig::getLoadHTTPConfig ( )

Returns whether the config is fetched from the portal over HTTP.

Returns
true if HTTP config loading is enabled.

◆ getMAC()

bool systemConfig::getMAC ( )

Loads the MAC address from flash into the mac member.

Returns
true if a non-blank MAC was read.

◆ getMACString()

String systemConfig::getMACString ( )

Returns the MAC address of the controller as a hex string.

Returns
MAC in "AA:BB:CC:DD:EE:FF" form.

◆ getMask()

bool systemConfig::getMask ( IPAddress & mask)

Loads the static subnet mask from flash.

Parameters
maskOutput IPAddress.
Returns
true if a usable (non-blank) mask was read.

◆ getMQTTpwd()

char * systemConfig::getMQTTpwd ( char * buffer,
uint16_t bufLen )

Reads the MQTT password from flash into a caller buffer.

Parameters
bufferOutput buffer for the password.
bufLenSize of the buffer.
Returns
Pointer to buffer if a password is stored, NULL otherwise.

◆ getOTApwd()

char * systemConfig::getOTApwd ( char * buffer,
uint16_t bufLen )

Reads the OTA (HTTP update) password from flash.

Parameters
bufferOutput buffer for the password.
bufLenSize of the buffer.
Returns
Pointer to buffer if a password is stored, NULL otherwise.

◆ getSaveSuccedConfig()

bool systemConfig::getSaveSuccedConfig ( )

Returns whether a successfully downloaded config is auto-saved.

Returns
true if saving after HTTP load is enabled.

◆ getSerialDebuglevel()

uint8_t systemConfig::getSerialDebuglevel ( )

Returns the stored serial log level.

Returns
Current serial log level.

◆ getServer()

char * systemConfig::getServer ( char * buffer,
uint16_t bufLen )

Reads the stored configuration server URL into a buffer.

Parameters
bufferOutput buffer.
bufLenSize of the buffer.
Returns
Pointer to buffer if a URL is stored, NULL otherwise.

◆ getUdpDebuglevel()

uint8_t systemConfig::getUdpDebuglevel ( )

Returns the stored UDP log level.

Returns
Current UDP log level.

◆ isValidSysConf()

bool systemConfig::isValidSysConf ( )

Checks that the stored config block has a valid signature.

Returns
true if the "LHC3" signature in flash is intact.

◆ loadETAG()

bool systemConfig::loadETAG ( )

Loads the stored ETag from flash into memory.

Returns
true if a non-empty ETag was loaded.

◆ saveETAG()

bool systemConfig::saveETAG ( )

Persists the in-memory ETag to flash.

Returns
true on success.

◆ setConfigFlags()

bool systemConfig::setConfigFlags ( systemConfigFlags flags)

Writes the packed system configuration flags to flash.

Parameters
flagsFlags to store.
Returns
true on success.

◆ setDHCPfallback()

bool systemConfig::setDHCPfallback ( bool flag)

Enables/disables static-IP-to-DHCP fallback in flash.

Parameters
flagtrue to allow DHCP fallback.
Returns
true on success.

◆ setDNS()

bool systemConfig::setDNS ( IPAddress & dns)

Stores the static DNS server address in flash.

Parameters
dnsAddress to write.
Returns
true on success.

◆ setETAG()

bool systemConfig::setETAG ( String etag)

Sets the in-memory ETag of the remote config (strips quotes).

Parameters
etagETag string.
Returns
true on success.

◆ setGW()

bool systemConfig::setGW ( IPAddress & gw)

Stores the static default gateway address in flash.

Parameters
gwAddress to write.
Returns
true on success.

◆ setIP()

bool systemConfig::setIP ( IPAddress & ip)

Stores the static IP address in flash.

Parameters
ipAddress to write.
Returns
true on success.

◆ setLoadHTTPConfig()

bool systemConfig::setLoadHTTPConfig ( bool load)

Enables/disables fetching the config from the portal over HTTP (disabled permanently after a local config change).

Parameters
loadtrue to allow HTTP config loading.
Returns
true on success.

◆ setMAC()

bool systemConfig::setMAC ( macAddress & mac)

Stores the given MAC address into flash.

Parameters
macMAC address to write.
Returns
true on success.

◆ setMask()

bool systemConfig::setMask ( IPAddress & mask)

Stores the static subnet mask in flash.

Parameters
maskMask to write.
Returns
true on success.

◆ setMQTTpwd()

bool systemConfig::setMQTTpwd ( char * pwd = NULL)

Stores the MQTT password in flash (NULL clears it).

Parameters
pwdNull-terminated password, or NULL to erase.
Returns
true on success.

◆ setOTApwd()

bool systemConfig::setOTApwd ( char * pwd = NULL)

Stores the OTA password in flash (NULL clears it).

Parameters
pwdNull-terminated password, or NULL to erase.
Returns
true on success.

◆ setSaveSuccedConfig()

bool systemConfig::setSaveSuccedConfig ( bool flag)

Enables/disables auto-save of a successfully downloaded config.

Parameters
flagtrue to enable auto-save.
Returns
true on success.

◆ setSerialDebuglevel()

bool systemConfig::setSerialDebuglevel ( short level)

Sets the serial (debug port) log level in flash.

Parameters
levelLog level to store.
Returns
true on success.

◆ setServer()

bool systemConfig::setServer ( char * url)

Stores the URL of the remote configuration server in flash. Falls back to the compile-time MY_CONFIG_SERVER / CONFIG_SERVER when nothing is stored.

Parameters
urlNull-terminated server URL.
Returns
true on success.

◆ setUdpDebuglevel()

bool systemConfig::setUdpDebuglevel ( short level)

Sets the UDP (syslog) log level in flash.

Parameters
levelLog level to store.
Returns
true on success.

Member Data Documentation

◆ mac

macAddress systemConfig::mac

MAC address of the controller, kept in memory after load.


The documentation for this class was generated from the following files: