@@ -10,6 +10,9 @@ settingsManager::settingsManager(const char* _f) {
10
10
this ->_pwd = new char [16 ];
11
11
this ->_ntp = new char [32 ];
12
12
this ->_file = new char [32 ];
13
+ #ifdef DEBUG_INSECURE
14
+ this ->_debug = NULL ;
15
+ #endif
13
16
if (_f == NULL ) memset (this ->_file , 0 , 32 );
14
17
else this ->setField (this ->_file , _f, 32 );
15
18
this ->_dhcp = true ;
@@ -18,12 +21,8 @@ settingsManager::settingsManager(const char* _f) {
18
21
this ->timezone = 0 ;
19
22
this ->readInterval = 5 ;
20
23
this ->tokenLifespan = 600 ;
21
- #ifdef DEBUG_INSECURE
22
- this ->_debug = NULL ;
23
- #endif
24
24
}
25
25
26
-
27
26
settingsManager::~settingsManager () {
28
27
delete[] _name;
29
28
delete[] _ssid;
@@ -48,8 +47,7 @@ void settingsManager::ntpServer(const char* _ntp) {
48
47
}
49
48
50
49
void settingsManager::save () {
51
- if (this ->_file [0 ] == 0 ) return ;
52
- SPIFFS.remove (this ->_file );
50
+ if (this ->_file == NULL ) return ;
53
51
fs::File _toSave = SPIFFS.open (this ->_file , " w" );
54
52
_toSave.print (F (" {\" SN\" :\" " ));
55
53
_toSave.print (this ->_name );
@@ -140,37 +138,40 @@ bool settingsManager::load() {
140
138
this ->_print (F (" Found file" ));
141
139
#endif
142
140
fs::File _toSave = SPIFFS.open (this ->_file , " r" );
143
- // Longest config i could create
144
- StaticJsonBuffer<800 > _ld;
145
- JsonObject& _data = _ld.parseObject (_toSave);
146
- _toSave.close ();
147
- if (!_data.success ()) {
141
+ // (about the) Longest config i could create
142
+ StaticJsonDocument<800 > _ld;
143
+
144
+ DeserializationError err = deserializeJson (_ld, _toSave);
145
+
146
+ if (err || !_toSave) {
148
147
#ifdef DEBUG_INSECURE
149
148
this ->_print (F (" Load error" ));
150
149
#endif
150
+ _toSave.close ();
151
151
return false ;
152
152
}
153
153
154
- this ->setField (this ->_name , _data [" SN" ], 32 );
155
- this ->setField (this ->_user , _data [" SL" ], 16 );
156
- this ->setField (this ->_pwd , _data [" SPL" ], 16 );
157
- this ->setField (this ->_ssid , _data [" OS" ], 32 );
158
- this ->setField (this ->_pass , _data [" OP" ], 32 );
159
- this ->setField (this ->_ssidap , _data [" SS" ], 32 );
160
- this ->setField (this ->_passap , _data [" SPA" ], 32 );
161
- this ->_ip = stringToIP (_data [" OI" ]);
162
- this ->_gw = stringToIP (_data [" OG" ]);
163
- this ->_mask = stringToIP (_data [" OM" ]);
164
- this ->_dhcp = _data [" OD" ]. as < bool >() ;
165
- this ->useNTP = _data [" UN" ]. as < bool >() ;
166
- this ->setField (this ->_ntp , _data [" NS" ], 32 );
167
- this ->lastUpdate = _data [" LU" ]. as < uint32_t >() ;
168
- this ->timezone = _data [" TZ" ]. as < int8_t >() ;
169
- this ->readInterval = _data [" RI" ]. as < uint16_t >() ;
170
- this ->tokenLifespan = _data [" TL" ]. as < uint16_t >() ;
154
+ this ->setField (this ->_name , _ld [" SN" ], 32 );
155
+ this ->setField (this ->_user , _ld [" SL" ], 16 );
156
+ this ->setField (this ->_pwd , _ld [" SPL" ], 16 );
157
+ this ->setField (this ->_ssid , _ld [" OS" ], 32 );
158
+ this ->setField (this ->_pass , _ld [" OP" ], 32 );
159
+ this ->setField (this ->_ssidap , _ld [" SS" ], 32 );
160
+ this ->setField (this ->_passap , _ld [" SPA" ], 32 );
161
+ this ->_ip = stringToIP (_ld [" OI" ]);
162
+ this ->_gw = stringToIP (_ld [" OG" ]);
163
+ this ->_mask = stringToIP (_ld [" OM" ]);
164
+ this ->_dhcp = _ld [" OD" ];
165
+ this ->useNTP = _ld [" UN" ];
166
+ this ->setField (this ->_ntp , _ld [" NS" ], 32 );
167
+ this ->lastUpdate = _ld [" LU" ];
168
+ this ->timezone = _ld [" TZ" ];
169
+ this ->readInterval = _ld [" RI" ];
170
+ this ->tokenLifespan = _ld [" TL" ];
171
171
#ifdef DEBUG_INSECURE
172
172
this ->_print (F (" Loaded successfully" ));
173
173
#endif
174
+ _toSave.close ();
174
175
return true ;
175
176
}
176
177
@@ -224,9 +225,9 @@ void settingsManager::printConfig() {
224
225
this ->_debug ->print (this ->lastUpdate );
225
226
this ->_debug ->print (F (" ,\" TZ\" :" ));
226
227
this ->_debug ->print (this ->timezone );
227
- this ->_debug ->print (F (" \" ,\" RI\" :" ));
228
+ this ->_debug ->print (F (" ,\" RI\" :" ));
228
229
this ->_debug ->print (this ->readInterval );
229
- this ->_debug ->print (F (" \" ,\" TL\" :" ));
230
+ this ->_debug ->print (F (" ,\" TL\" :" ));
230
231
this ->_debug ->print (this ->tokenLifespan );
231
232
this ->_debug ->print (F (" }\r\n " ));
232
233
return void ();
0 commit comments