-
Notifications
You must be signed in to change notification settings - Fork 0
/
IAQ_Configuration.cpp
132 lines (112 loc) · 3.42 KB
/
IAQ_Configuration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "IAQ_Configuration.h"
bool Configuration::save() {
if (SPIFFS.begin()) {
File f = SPIFFS.open("/iaq.cfg", "w");
if (!f) {
DEBUG_PRINT(F("failed to write config file (1)"));
return false;
};
//const size_t capacity = JSON_OBJECT_SIZE(3);
DEBUG_PRINT(F("save config"));
//DynamicJsonDocument doc(255); //heap
StaticJsonDocument<512> doc;
doc["mqtt_server"] = _mqtt_server;
doc["mqtt_port"] = _mqtt_port;
doc["mqtt_name"] = _mqtt_name;
serializeJson(doc, Serial);
serializeJson(doc, f);
f.close();
SPIFFS.end();
changed = false;
return true;
};
return false;
};
bool Configuration::load() {
if (SPIFFS.begin()) {
File f = SPIFFS.open("/iaq.cfg", "r");
if (!f) {
DEBUG_PRINT(F("failed to read config file (1)"));
return false;
};
//const size_t capacity = JSON_OBJECT_SIZE(3);
DEBUG_PRINT(F("read config"));
StaticJsonDocument<512> doc;
DeserializationError error = deserializeJson(doc, f);
if (error) {
DEBUG_PRINT(F("failed to read config file (1)"));
return false;
};
strlcpy(_mqtt_server, doc["mqtt_server"], sizeof(_mqtt_server));
strlcpy(_mqtt_port, doc["mqtt_port"], sizeof(_mqtt_port));
strlcpy(_mqtt_name, doc["mqtt_name"], sizeof(_mqtt_name));
f.close();
SPIFFS.end();
changed = false;
return true;
};
return false;
};
void Configuration::get_mqtt_server(char buffer[]) {
strlcpy(buffer, _mqtt_server, sizeof(_mqtt_server));
};
Configuration& Configuration::set_mqtt_server(const char* newValue) {
uint16_t bsize = sizeof(_mqtt_server);
if (strlcpy(_mqtt_server, newValue, bsize) >= bsize) {
_mqtt_server[0] = '\0';
};
};
void Configuration::get_mqtt_port(char buffer[]) {
strlcpy(buffer, _mqtt_port, sizeof(_mqtt_port));
};
Configuration& Configuration::set_mqtt_port(const char* newValue) {
uint16_t bsize = sizeof(_mqtt_port);
if (strlcpy(_mqtt_port, newValue, bsize) >= bsize) {
_mqtt_port[0] = '\0';
};
};
void Configuration::get_mqtt_name(char buffer[]) {
strlcpy(buffer, _mqtt_name, sizeof(_mqtt_name));
};
Configuration& Configuration::set_mqtt_name(const char* newValue) {
uint16_t bsize = sizeof(_mqtt_name);
if (strlcpy(_mqtt_name, newValue, bsize) >= bsize) {
_mqtt_name[0] = '\0';
};
};
const float& Configuration::led0_vLow() const {
return _led0_vLow;
};
Configuration& Configuration::led0_vLow(const float& newValue) {
_led0_vLow = newValue;
};
const float& Configuration::led0_vMedium() const {
return _led0_vMedium;
};
Configuration& Configuration::led0_vMedium(const float& newValue) {
_led0_vMedium = newValue;
};
const float& Configuration::led0_vHigh() const {
return _led0_vHigh;
};
Configuration& Configuration::led0_vHigh(const float& newValue) {
_led0_vHigh = newValue;
};
const float& Configuration::led0_cLow() const {
return _led0_cLow;
};
Configuration& Configuration::led0_cLow(const float& newValue) {
_led0_cLow = newValue;
};
const float& Configuration::led0_cMedium() const {
return _led0_cMedium;
};
Configuration& Configuration::led0_cMedium(const float& newValue) {
_led0_cMedium = newValue;
};
const float& Configuration::led0_cHigh() const {
return _led0_cHigh;
};
Configuration& Configuration::led0_cHigh(const float& newValue) {
_led0_cHigh = newValue;
};