Wombat Environmental Node 1.0
An environmental node for SDI-12 and digital sensors.
Loading...
Searching...
No Matches
DeviceConfig Class Reference

Node configuration options for both getting and setting values. More...

#include <DeviceConfig.h>

Collaboration diagram for DeviceConfig:

Public Member Functions

void reset ()
 Reset device configuration values back to their default. More...
 
void load ()
 Load device configuration values from SPIFFS storage. More...
 
void save ()
 Save device configuration values to SPIFFS storage. More...
 
uint32_t getBootCount (void)
 Method to get the number of times the ESP32 has rebooted. bootCount is incremented when the singleton is created, meaning at power-on it will be 1 by the time any code can ask for it. It is easier to do modulo arithmetic with a 0-based bootCount so adjust it before returning it. More...
 
uint16_t getMeasureInterval ()
 
void setMeasureInterval (const uint16_t seconds)
 Set the measurement interval. More...
 
uint16_t getUplinkInterval ()
 
void setUplinkInterval (const uint16_t seconds)
 Set the uplink interval. More...
 
void setMeasurementAndUplinkIntervals (const uint16_t measurement_seconds, const uint16_t uplink_seconds)
 Set both the measurement and uplink intervals. More...
 
void setMqttHost (const std::string &host)
 Set the MQTT hostname. More...
 
void setMqttPort (uint16_t port)
 Set the MQTT port. More...
 
void setMqttUser (const std::string &user)
 Set the MQTT broker username. More...
 
void setMqttPassword (const std::string &password)
 Set the MQTT broker password. More...
 
std::string & getMqttHost ()
 Get the MQTT hostname. More...
 
uint16_t getMqttPort ()
 Get the MQTT port. More...
 
std::string & getMqttUser ()
 Get the MQTT broker username. More...
 
std::string & getMqttPassword ()
 Get the MQTT broker password. More...
 
void setFtpHost (const std::string &host)
 Set the FTP hostname. More...
 
void setFtpUser (const std::string &user)
 Set the FTP username. More...
 
void setFtpPassword (const std::string &password)
 Set the FTP password. More...
 
std::string & getFtpHost ()
 Get the FTP hostname. More...
 
std::string & getFtpUser ()
 Get the FTP username. More...
 
std::string & getFtpPassword ()
 Get the FTP password. More...
 
float getSleepAdjustment ()
 
void setSleepAdjustment (float _sleep_adjustment)
 
void dumpConfig (Stream &stream)
 Print out device configuration to a stream. More...
 
const JsonDocument & getSDI12Defns (void)
 Get the SDI-12 device definitions from SPIFFS storage. More...
 

Static Public Member Functions

static DeviceConfigget ()
 Provides an instance to other functions (MQTT and uplink intervals) to access (set, get) device configuration. More...
 
static const char * getMsgFilePrefix (void)
 

Public Attributes

uint8_t mac [6]
 
char node_id [13]
 
char mqtt_topic_template [MAX_CONFIG_STR+1]
 

Static Public Attributes

static constexpr size_t MAX_CONFIG_STR = 32
 Maximum length of a configuration string. More...
 

Private Member Functions

 DeviceConfig ()
 Device configuration constructor with default values. More...
 
 DeviceConfig (const DeviceConfig &)=delete
 Avoid operations that would make copies of the singleton instance. More...
 
DeviceConfigoperator= (const DeviceConfig &)=delete
 

Private Attributes

float sleep_adjustment = 1.0f
 Multiplier for the sleep time to account for clock speed variations. More...
 
uint16_t measure_interval
 How often to read the sensors, in seconds. More...
 
uint16_t uplink_interval
 How often to uplink the data, in seconds. More...
 
std::string mqttHost
 MQTT hostname. More...
 
uint16_t mqttPort
 MQTT port. More...
 
std::string mqttUser
 MQTT broker username. More...
 
std::string mqttPassword
 MQTT broker password. More...
 
std::string ftpHost
 FTP hostname. More...
 
std::string ftpUser
 FTP username. More...
 
std::string ftpPassword
 FTP password. More...
 

Detailed Description

Node configuration options for both getting and setting values.

Handles all device configuration commands. This includes measurement and uplink intervals, MQTT configuration and SDI-12 configuration. Values are stored in SPIFFS storage.

Constructor & Destructor Documentation

◆ DeviceConfig() [1/2]

DeviceConfig::DeviceConfig ( )
private

Device configuration constructor with default values.

Todo:
Several values here are not initialised

◆ DeviceConfig() [2/2]

DeviceConfig::DeviceConfig ( const DeviceConfig )
privatedelete

Avoid operations that would make copies of the singleton instance.

Member Function Documentation

◆ dumpConfig()

void DeviceConfig::dumpConfig ( Stream &  stream)

Print out device configuration to a stream.

Parameters
streamOutput stream.

◆ get()

static DeviceConfig & DeviceConfig::get ( )
inlinestatic

Provides an instance to other functions (MQTT and uplink intervals) to access (set, get) device configuration.

Returns
A static instance of the current device configuration.

◆ getBootCount()

uint32_t DeviceConfig::getBootCount ( void  )

Method to get the number of times the ESP32 has rebooted. bootCount is incremented when the singleton is created, meaning at power-on it will be 1 by the time any code can ask for it. It is easier to do modulo arithmetic with a 0-based bootCount so adjust it before returning it.

Returns
Boot counter.

◆ getFtpHost()

std::string & DeviceConfig::getFtpHost ( )
inline

Get the FTP hostname.

◆ getFtpPassword()

std::string & DeviceConfig::getFtpPassword ( )
inline

Get the FTP password.

◆ getFtpUser()

std::string & DeviceConfig::getFtpUser ( )
inline

Get the FTP username.

◆ getMeasureInterval()

uint16_t DeviceConfig::getMeasureInterval ( )
inline

◆ getMqttHost()

std::string & DeviceConfig::getMqttHost ( )
inline

Get the MQTT hostname.

◆ getMqttPassword()

std::string & DeviceConfig::getMqttPassword ( )
inline

Get the MQTT broker password.

◆ getMqttPort()

uint16_t DeviceConfig::getMqttPort ( )
inline

Get the MQTT port.

◆ getMqttUser()

std::string & DeviceConfig::getMqttUser ( )
inline

Get the MQTT broker username.

◆ getMsgFilePrefix()

static const char * DeviceConfig::getMsgFilePrefix ( void  )
inlinestatic

◆ getSDI12Defns()

const JsonDocument & DeviceConfig::getSDI12Defns ( void  )

Get the SDI-12 device definitions from SPIFFS storage.

Returns
SDI-12 device definitions as a JSONDocument.

◆ getSleepAdjustment()

float DeviceConfig::getSleepAdjustment ( )
inline

◆ getUplinkInterval()

uint16_t DeviceConfig::getUplinkInterval ( )
inline

◆ load()

void DeviceConfig::load ( )

Load device configuration values from SPIFFS storage.

Load the DeviceConfig values from a file on the file system.

This function loads the DeviceConfig values from a file on the file system and sets any missing values to their default states. It also loads the SDI-12 sensor definitions from a file on the file system.

See also
reset
config_filename
sdi12defn_spiffs
sdi12Defns

◆ operator=()

DeviceConfig & DeviceConfig::operator= ( const DeviceConfig )
privatedelete

◆ reset()

void DeviceConfig::reset ( )

Reset device configuration values back to their default.

Reset the DeviceConfig values to their default states.

This function resets the measure interval, uplink interval, MAC address, and MQTT connection parameters (host, port, user, and password) to their default values.

See also
measure_interval
uplink_interval
mac
node_id
mqttHost
mqttPort
mqttUser
mqttPassword

◆ save()

void DeviceConfig::save ( )

Save device configuration values to SPIFFS storage.

Save device configuration to SPIFFS storage.

◆ setFtpHost()

void DeviceConfig::setFtpHost ( const std::string &  host)
inline

Set the FTP hostname.

◆ setFtpPassword()

void DeviceConfig::setFtpPassword ( const std::string &  password)
inline

Set the FTP password.

◆ setFtpUser()

void DeviceConfig::setFtpUser ( const std::string &  user)
inline

Set the FTP username.

◆ setMeasureInterval()

void DeviceConfig::setMeasureInterval ( const uint16_t  seconds)

Set the measurement interval.

Parameters
secondsTime in seconds.

◆ setMeasurementAndUplinkIntervals()

void DeviceConfig::setMeasurementAndUplinkIntervals ( const uint16_t  measurement_seconds,
const uint16_t  uplink_seconds 
)

Set both the measurement and uplink intervals.

Warning
The measurement interval should be divisible by the uplink interval with no remainder.
Parameters
measurement_secondsMeasurement interval in seconds.
uplink_secondsUplink interval in seconds.

◆ setMqttHost()

void DeviceConfig::setMqttHost ( const std::string &  host)
inline

Set the MQTT hostname.

◆ setMqttPassword()

void DeviceConfig::setMqttPassword ( const std::string &  password)
inline

Set the MQTT broker password.

◆ setMqttPort()

void DeviceConfig::setMqttPort ( uint16_t  port)
inline

Set the MQTT port.

◆ setMqttUser()

void DeviceConfig::setMqttUser ( const std::string &  user)
inline

Set the MQTT broker username.

◆ setSleepAdjustment()

void DeviceConfig::setSleepAdjustment ( float  _sleep_adjustment)
inline

◆ setUplinkInterval()

void DeviceConfig::setUplinkInterval ( const uint16_t  seconds)

Set the uplink interval.

Parameters
secondsTime in seconds.

Member Data Documentation

◆ ftpHost

std::string DeviceConfig::ftpHost
private

FTP hostname.

◆ ftpPassword

std::string DeviceConfig::ftpPassword
private

FTP password.

◆ ftpUser

std::string DeviceConfig::ftpUser
private

FTP username.

◆ mac

uint8_t DeviceConfig::mac[6]

◆ MAX_CONFIG_STR

constexpr size_t DeviceConfig::MAX_CONFIG_STR = 32
staticconstexpr

Maximum length of a configuration string.

◆ measure_interval

uint16_t DeviceConfig::measure_interval
private

How often to read the sensors, in seconds.

◆ mqtt_topic_template

char DeviceConfig::mqtt_topic_template[MAX_CONFIG_STR+1]

◆ mqttHost

std::string DeviceConfig::mqttHost
private

MQTT hostname.

◆ mqttPassword

std::string DeviceConfig::mqttPassword
private

MQTT broker password.

◆ mqttPort

uint16_t DeviceConfig::mqttPort
private

MQTT port.

◆ mqttUser

std::string DeviceConfig::mqttUser
private

MQTT broker username.

◆ node_id

char DeviceConfig::node_id[13]

◆ sleep_adjustment

float DeviceConfig::sleep_adjustment = 1.0f
private

Multiplier for the sleep time to account for clock speed variations.

◆ uplink_interval

uint16_t DeviceConfig::uplink_interval
private

How often to uplink the data, in seconds.


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