Wombat Environmental Node 1.0
An environmental node for SDI-12 and digital sensors.
Loading...
Searching...
No Matches
DeviceConfig.h
Go to the documentation of this file.
1
8#ifndef WOMBAT_DEVICE_CONFIG_H
9#define WOMBAT_DEVICE_CONFIG_H
10
11#include <Arduino.h>
12#include <ArduinoJson.h>
13
22public:
24 static constexpr size_t MAX_CONFIG_STR = 32;
25
26 // mac and node_id are populated in the constructor.
27 uint8_t mac[6];
28 char node_id[13];
30
37 static DeviceConfig& get() {
38 static DeviceConfig instance;
39 return instance;
40 }
41
43 void reset();
44
46 void load();
47
49 void save();
50
51 uint32_t getBootCount(void);
52
53 uint16_t getMeasureInterval() { return measure_interval; }
54
55 void setMeasureInterval(const uint16_t seconds);
56
57 uint16_t getUplinkInterval() { return uplink_interval; }
58
59 void setUplinkInterval(const uint16_t seconds);
60
61 void setMeasurementAndUplinkIntervals(const uint16_t measurement_seconds,
62 const uint16_t uplink_seconds);
63
65 void setMqttHost(const std::string& host) { mqttHost = host; }
67 void setMqttPort(uint16_t port) { mqttPort = port; }
69 void setMqttUser(const std::string& user) { mqttUser = user; }
71 void setMqttPassword(const std::string& password) { mqttPassword = password; }
72
74 std::string& getMqttHost() { return mqttHost; }
76 uint16_t getMqttPort() { return mqttPort; }
78 std::string& getMqttUser() { return mqttUser; }
80 std::string& getMqttPassword() { return mqttPassword; }
81
83 void setFtpHost(const std::string& host) { ftpHost = host; }
85 void setFtpUser(const std::string& user) { ftpUser = user; }
87 void setFtpPassword(const std::string& password) { ftpPassword = password; }
88
90 std::string& getFtpHost() { return ftpHost; }
92 std::string& getFtpUser() { return ftpUser; }
94 std::string& getFtpPassword() { return ftpPassword; }
95
97 void setSleepAdjustment(float _sleep_adjustment) {
98 sleep_adjustment = _sleep_adjustment;
99 }
100
101 void dumpConfig(Stream& stream);
102
103 const JsonDocument& getSDI12Defns(void);
104
105 static const char* getMsgFilePrefix(void) {
106 return "msg_";
107 }
108
109private:
110 DeviceConfig();
111
113 DeviceConfig(const DeviceConfig&) = delete;
115
117 float sleep_adjustment = 1.0f;
123 std::string mqttHost;
125 uint16_t mqttPort;
127 std::string mqttUser;
129 std::string mqttPassword;
130
132 std::string ftpHost;
134 std::string ftpUser;
136 std::string ftpPassword;
137};
138
139
140#endif //WOMBAT_DEVICE_CONFIG_H
Node configuration options for both getting and setting values.
Definition: DeviceConfig.h:21
void load()
Load device configuration values from SPIFFS storage.
Definition: DeviceConfig.cpp:92
std::string & getMqttHost()
Get the MQTT hostname.
Definition: DeviceConfig.h:74
std::string & getMqttPassword()
Get the MQTT broker password.
Definition: DeviceConfig.h:80
void save()
Save device configuration values to SPIFFS storage.
Definition: DeviceConfig.cpp:149
uint16_t getUplinkInterval()
Definition: DeviceConfig.h:57
static constexpr size_t MAX_CONFIG_STR
Maximum length of a configuration string.
Definition: DeviceConfig.h:24
void setMeasurementAndUplinkIntervals(const uint16_t measurement_seconds, const uint16_t uplink_seconds)
Set both the measurement and uplink intervals.
Definition: DeviceConfig.cpp:214
DeviceConfig()
Device configuration constructor with default values.
Definition: DeviceConfig.cpp:43
void dumpConfig(Stream &stream)
Print out device configuration to a stream.
Definition: DeviceConfig.cpp:164
std::string & getMqttUser()
Get the MQTT broker username.
Definition: DeviceConfig.h:78
uint16_t getMeasureInterval()
Definition: DeviceConfig.h:53
DeviceConfig & operator=(const DeviceConfig &)=delete
DeviceConfig(const DeviceConfig &)=delete
Avoid operations that would make copies of the singleton instance.
uint32_t getBootCount(void)
Method to get the number of times the ESP32 has rebooted. bootCount is incremented when the singleton...
Definition: DeviceConfig.cpp:178
uint16_t getMqttPort()
Get the MQTT port.
Definition: DeviceConfig.h:76
std::string mqttPassword
MQTT broker password.
Definition: DeviceConfig.h:129
void setMqttUser(const std::string &user)
Set the MQTT broker username.
Definition: DeviceConfig.h:69
static DeviceConfig & get()
Provides an instance to other functions (MQTT and uplink intervals) to access (set,...
Definition: DeviceConfig.h:37
char node_id[13]
Definition: DeviceConfig.h:28
void setFtpUser(const std::string &user)
Set the FTP username.
Definition: DeviceConfig.h:85
std::string ftpPassword
FTP password.
Definition: DeviceConfig.h:136
std::string & getFtpHost()
Get the FTP hostname.
Definition: DeviceConfig.h:90
uint8_t mac[6]
Definition: DeviceConfig.h:27
uint16_t measure_interval
How often to read the sensors, in seconds.
Definition: DeviceConfig.h:119
std::string & getFtpUser()
Get the FTP username.
Definition: DeviceConfig.h:92
void setSleepAdjustment(float _sleep_adjustment)
Definition: DeviceConfig.h:97
void setFtpPassword(const std::string &password)
Set the FTP password.
Definition: DeviceConfig.h:87
std::string & getFtpPassword()
Get the FTP password.
Definition: DeviceConfig.h:94
std::string ftpUser
FTP username.
Definition: DeviceConfig.h:134
uint16_t uplink_interval
How often to uplink the data, in seconds.
Definition: DeviceConfig.h:121
const JsonDocument & getSDI12Defns(void)
Get the SDI-12 device definitions from SPIFFS storage.
Definition: DeviceConfig.cpp:229
float getSleepAdjustment()
Definition: DeviceConfig.h:96
void setUplinkInterval(const uint16_t seconds)
Set the uplink interval.
Definition: DeviceConfig.cpp:196
void setMeasureInterval(const uint16_t seconds)
Set the measurement interval.
Definition: DeviceConfig.cpp:187
float sleep_adjustment
Multiplier for the sleep time to account for clock speed variations.
Definition: DeviceConfig.h:117
std::string mqttUser
MQTT broker username.
Definition: DeviceConfig.h:127
std::string mqttHost
MQTT hostname.
Definition: DeviceConfig.h:123
std::string ftpHost
FTP hostname.
Definition: DeviceConfig.h:132
static const char * getMsgFilePrefix(void)
Definition: DeviceConfig.h:105
void setMqttHost(const std::string &host)
Set the MQTT hostname.
Definition: DeviceConfig.h:65
void setFtpHost(const std::string &host)
Set the FTP hostname.
Definition: DeviceConfig.h:83
uint16_t mqttPort
MQTT port.
Definition: DeviceConfig.h:125
char mqtt_topic_template[MAX_CONFIG_STR+1]
Definition: DeviceConfig.h:29
void reset()
Reset device configuration values back to their default.
Definition: DeviceConfig.cpp:65
void setMqttPort(uint16_t port)
Set the MQTT port.
Definition: DeviceConfig.h:67
void setMqttPassword(const std::string &password)
Set the MQTT broker password.
Definition: DeviceConfig.h:71