20
20
#define ConfigManager_h
21
21
22
22
#include " IotWebConf2.h"
23
- #if IOTWEBCONF_DEBUG_DISABLED == 0 && !PLATFORMIO
23
+ #if IOTWEBCONF_DEBUG_DISABLED == 0 && !PLATFORMIO
24
24
#error "Using Arduino IDE is not recommended, please follow this guide https://github.com/G4lile0/tinyGS/wiki/Arduino-IDE or edit /IotWebCong2/src/IotWebConf2Settings.h and add this line at the beggining of the file #define IOTWEBCONF_DEBUG_DISABLED 1"
25
25
#endif
26
26
#include " logos.h"
27
27
#include < Wire.h>
28
28
#include " html.h"
29
29
30
30
#ifdef ESP8266
31
- #include " ESP8266HTTPUpdateServer.h"
31
+ #include " ESP8266HTTPUpdateServer.h"
32
32
#elif defined(ESP32)
33
- #include " IotWebConf2ESP32HTTPUpdateServer.h"
33
+ #include " IotWebConf2ESP32HTTPUpdateServer.h"
34
34
#endif
35
35
36
36
constexpr auto STATION_NAME_LENGTH = 21 ;
@@ -46,7 +46,6 @@ constexpr auto MODEM_LEN = 256;
46
46
constexpr auto ADVANCED_LEN = 256 ;
47
47
constexpr auto CB_SELECTED_STR = " selected" ;
48
48
49
-
50
49
constexpr auto ROOT_URL = " /" ;
51
50
constexpr auto CONFIG_URL = " /config" ;
52
51
constexpr auto DASHBOARD_URL = " /dashboard" ;
@@ -56,18 +55,18 @@ constexpr auto REFRESH_CONSOLE_URL = "/cs";
56
55
57
56
const char TITLE_TEXT[] PROGMEM = " TinyGS Configuration" ;
58
57
59
-
60
58
constexpr auto thingName = " My TinyGS" ;
61
59
constexpr auto initialApPassword = " " ;
62
60
constexpr auto configVersion = " 0.05" ; // max 4 chars
63
61
64
62
#define MQTT_DEFAULT_SERVER " mqtt.tinygs.com"
65
- #define MQTT_DEFAULT_PORT " 8883"
63
+ #define MQTT_DEFAULT_PORT " 8883"
66
64
#define MODEM_DEFAULT " {\" mode\" :\" LoRa\" ,\" freq\" :436.703,\" bw\" :250.0,\" sf\" :10,\" cr\" :5,\" sw\" :18,\" pwr\" :5,\" cl\" :120,\" pl\" :8,\" gain\" :0,\" crc\" :true,\" fldro\" :1,\" sat\" :\" Norbi\" ,\" NORAD\" :46494}"
67
65
68
66
constexpr auto AP_TIMEOUT_MS = " 300000" ;
69
67
70
- enum boardNum {
68
+ enum boardNum
69
+ {
71
70
HELTEC_V1_LF = 0 ,
72
71
HELTEC_V1_HF,
73
72
HELTEC_V2_LF,
@@ -89,37 +88,38 @@ enum boardNum {
89
88
NUM_BOARDS // this line always has to be the last one
90
89
};
91
90
92
- typedef struct {
93
- uint8_t OLED__address;
94
- uint8_t OLED__SDA;
95
- uint8_t OLED__SCL;
96
- uint8_t OLED__RST;
97
- uint8_t PROG__BUTTON;
98
- uint8_t BOARD_LED;
99
- uint8_t L_SX127X; // 0 SX1262 1 SX1278
100
- uint8_t L_NSS; // CS
101
- uint8_t L_DI00;
102
- uint8_t L_DI01;
103
- uint8_t L_BUSSY;
104
- uint8_t L_RST;
105
- uint8_t L_MISO;
106
- uint8_t L_MOSI;
107
- uint8_t L_SCK;
108
- float L_TCXO_V;
109
- String BOARD;
91
+ typedef struct
92
+ {
93
+ uint8_t OLED__address;
94
+ uint8_t OLED__SDA;
95
+ uint8_t OLED__SCL;
96
+ uint8_t OLED__RST;
97
+ uint8_t PROG__BUTTON;
98
+ uint8_t BOARD_LED;
99
+ uint8_t L_SX127X; // 0 SX1262 1 SX1278
100
+ uint8_t L_NSS; // CS
101
+ uint8_t L_DI00;
102
+ uint8_t L_DI01;
103
+ uint8_t L_BUSSY;
104
+ uint8_t L_RST;
105
+ uint8_t L_MISO;
106
+ uint8_t L_MOSI;
107
+ uint8_t L_SCK;
108
+ float L_TCXO_V;
109
+ String BOARD;
110
110
} board_type;
111
111
112
- typedef struct {
112
+ typedef struct
113
+ {
113
114
bool flipOled = true ;
114
115
bool dnOled = true ;
115
116
bool lowPower = false ;
116
117
} AdvancedConfig;
117
118
118
-
119
119
class ConfigManager : public IotWebConf2
120
120
{
121
121
public:
122
- static ConfigManager& getInstance ()
122
+ static ConfigManager & getInstance ()
123
123
{
124
124
static ConfigManager instance;
125
125
return instance;
@@ -130,75 +130,126 @@ class ConfigManager : public IotWebConf2
130
130
boolean init ();
131
131
void printConfig ();
132
132
133
- uint16_t getMqttPort () { return (uint16_t ) atoi (mqttPort); }
134
- const char * getMqttServer () { return mqttServer; }
135
- const char * getMqttUser () { return mqttUser; }
136
- const char * getMqttPass () { return mqttPass; }
133
+ uint16_t getMqttPort () { return (uint16_t )atoi (mqttPort); }
134
+ const char * getMqttServer () { return mqttServer; }
135
+ const char * getMqttUser () { return mqttUser; }
136
+ const char * getMqttPass () { return mqttPass; }
137
137
float getLatitude () { return atof (latitude); }
138
138
float getLongitude () { return atof (longitude); }
139
- const char * getTZ () { return tz + 3 ; } // +3 removes the first 3 digits used for time zone deduplication
139
+ const char * getTZ () { return tz + 3 ; } // +3 removes the first 3 digits used for time zone deduplication
140
140
uint8_t getBoard () { return atoi (board); }
141
141
uint8_t getOledBright () { return atoi (oledBright); }
142
142
bool getAllowTx () { return !strcmp (allowTx, CB_SELECTED_STR); }
143
143
bool getRemoteTune () { return !strcmp (remoteTune, CB_SELECTED_STR); }
144
144
bool getTelemetry3rd () { return !strcmp (telemetry3rd, CB_SELECTED_STR); }
145
145
bool getTestMode () { return !strcmp (testMode, CB_SELECTED_STR); }
146
146
bool getAutoUpdate () { return !strcmp (autoUpdate, CB_SELECTED_STR); }
147
- void setAllowTx (bool status) { if (status) strcpy (allowTx, CB_SELECTED_STR); else allowTx[0 ] = ' \0 ' ; this ->saveConfig (); }
148
- void setRemoteTune (bool status) { if (status) strcpy (remoteTune, CB_SELECTED_STR); else remoteTune[0 ] = ' \0 ' ; this ->saveConfig (); }
149
- void setTelemetry3rd (bool status) { if (status) strcpy (telemetry3rd, CB_SELECTED_STR); else telemetry3rd[0 ] = ' \0 ' ; this ->saveConfig (); }
150
- void setTestMode (bool status) { if (status) strcpy (testMode, CB_SELECTED_STR); else testMode[0 ] = ' \0 ' ; this ->saveConfig (); }
151
- void setAutoUpdate (bool status) { if (status) strcpy (autoUpdate, CB_SELECTED_STR); else autoUpdate[0 ] = ' \0 ' ; this ->saveConfig (); }
152
- const char * getModemStartup () { return modemStartup; }
153
- void setModemStartup (const char * modemStr) { strcpy (modemStartup, modemStr); this ->saveConfig (); }
154
- const char * getAvancedConfig () { return advancedConfig; }
155
- void setAvancedConfig (const char * adv_prmStr) { strcpy (advancedConfig, adv_prmStr); this ->saveConfig (); }
156
- const char * getBoardTemplate () { return boardTemplate; }
157
- void setBoardTemplate (const char * boardTemplateStr) { strcpy (boardTemplate, boardTemplateStr); this ->saveConfig (); }
147
+ void setAllowTx (bool status)
148
+ {
149
+ if (status)
150
+ strcpy (allowTx, CB_SELECTED_STR);
151
+ else
152
+ allowTx[0 ] = ' \0 ' ;
153
+ this ->saveConfig ();
154
+ }
155
+ void setRemoteTune (bool status)
156
+ {
157
+ if (status)
158
+ strcpy (remoteTune, CB_SELECTED_STR);
159
+ else
160
+ remoteTune[0 ] = ' \0 ' ;
161
+ this ->saveConfig ();
162
+ }
163
+ void setTelemetry3rd (bool status)
164
+ {
165
+ if (status)
166
+ strcpy (telemetry3rd, CB_SELECTED_STR);
167
+ else
168
+ telemetry3rd[0 ] = ' \0 ' ;
169
+ this ->saveConfig ();
170
+ }
171
+ void setTestMode (bool status)
172
+ {
173
+ if (status)
174
+ strcpy (testMode, CB_SELECTED_STR);
175
+ else
176
+ testMode[0 ] = ' \0 ' ;
177
+ this ->saveConfig ();
178
+ }
179
+ void setAutoUpdate (bool status)
180
+ {
181
+ if (status)
182
+ strcpy (autoUpdate, CB_SELECTED_STR);
183
+ else
184
+ autoUpdate[0 ] = ' \0 ' ;
185
+ this ->saveConfig ();
186
+ }
187
+ const char *getModemStartup () { return modemStartup; }
188
+ void setModemStartup (const char *modemStr)
189
+ {
190
+ strcpy (modemStartup, modemStr);
191
+ this ->saveConfig ();
192
+ parseModemStartup ();
193
+ }
194
+ const char *getAvancedConfig () { return advancedConfig; }
195
+ void setAvancedConfig (const char *adv_prmStr)
196
+ {
197
+ strcpy (advancedConfig, adv_prmStr);
198
+ this ->saveConfig ();
199
+ }
200
+ const char *getBoardTemplate () { return boardTemplate; }
201
+ void setBoardTemplate (const char *boardTemplateStr)
202
+ {
203
+ strcpy (boardTemplate, boardTemplateStr);
204
+ this ->saveConfig ();
205
+ }
158
206
159
- const char * getWiFiSSID () { return getWifiSsidParameter ()->valueBuffer ; }
207
+ const char * getWiFiSSID () { return getWifiSsidParameter ()->valueBuffer ; }
160
208
bool isConnected () { return getState () == IOTWEBCONF_STATE_ONLINE; };
161
209
bool isApMode () { return (getState () != IOTWEBCONF_STATE_CONNECTING && getState () != IOTWEBCONF_STATE_ONLINE); }
162
- board_type getBoardConfig (){ return boards[getBoard ()]; }
163
- bool getFlipOled (){ return advancedConf.flipOled ; }
164
- bool getDayNightOled (){ return advancedConf.dnOled ; }
165
- bool getLowPower (){ return advancedConf.lowPower ; }
166
-
210
+ board_type getBoardConfig () { return boards[getBoard ()]; }
211
+ bool getFlipOled () { return advancedConf.flipOled ; }
212
+ bool getDayNightOled () { return advancedConf.dnOled ; }
213
+ bool getLowPower () { return advancedConf.lowPower ; }
214
+ void saveConfig ()
215
+ {
216
+ remoteSave = true ;
217
+ IotWebConf2::saveConfig ();
218
+ };
167
219
168
220
private:
169
-
170
221
class GSConfigHtmlFormatProvider : public iotwebconf2 ::HtmlFormatProvider
171
222
{
172
223
public:
173
- GSConfigHtmlFormatProvider (ConfigManager& x) : configManager(x) { }
224
+ GSConfigHtmlFormatProvider (ConfigManager &x) : configManager(x) {}
225
+
174
226
protected:
175
227
String getScriptInner () override
176
228
{
177
- return
178
- iotwebconf2::HtmlFormatProvider::getScriptInner ();
179
- // String(FPSTR(CUSTOMHTML_SCRIPT_INNER));
229
+ return iotwebconf2::HtmlFormatProvider::getScriptInner ();
230
+ // String(FPSTR(CUSTOMHTML_SCRIPT_INNER));
180
231
}
181
232
String getBodyInner () override
182
233
{
183
- return
184
- String (FPSTR (LOGO)) +
185
- iotwebconf2::HtmlFormatProvider::getBodyInner ();
234
+ return String (FPSTR (LOGO)) +
235
+ iotwebconf2::HtmlFormatProvider::getBodyInner ();
186
236
}
187
237
188
- ConfigManager& configManager;
238
+ ConfigManager & configManager;
189
239
};
190
240
191
241
ConfigManager ();
192
242
void handleRoot ();
193
243
void handleDashboard ();
194
244
void handleRefreshConsole ();
195
245
void handleRestart ();
196
- bool formValidator (iotwebconf2::WebRequestWrapper* webRequestWrapper);
246
+ bool formValidator (iotwebconf2::WebRequestWrapper * webRequestWrapper);
197
247
void boardDetection ();
198
248
void configSavedCallback ();
199
249
void parseAdvancedConf ();
200
-
201
- std::function<boolean(iotwebconf2::WebRequestWrapper*)> formValidatorStd;
250
+ void parseModemStartup ();
251
+
252
+ std::function<boolean(iotwebconf2::WebRequestWrapper *)> formValidatorStd;
202
253
DNSServer dnsServer;
203
254
WebServer server;
204
255
#ifdef ESP8266
@@ -207,9 +258,10 @@ class ConfigManager : public IotWebConf2
207
258
HTTPUpdateServer httpUpdater;
208
259
#endif
209
260
GSConfigHtmlFormatProvider gsConfigHtmlFormatProvider;
210
- board_type boards[NUM_BOARDS];
261
+ board_type boards[NUM_BOARDS];
211
262
AdvancedConfig advancedConf;
212
263
char savedThingName[IOTWEBCONF_WORD_LEN] = " " ;
264
+ bool remoteSave = false ;
213
265
214
266
char latitude[COORDINATE_LENGTH] = " " ;
215
267
char longitude[COORDINATE_LENGTH] = " " ;
@@ -231,24 +283,24 @@ class ConfigManager : public IotWebConf2
231
283
232
284
iotwebconf2::NumberParameter latitudeParam = iotwebconf2::NumberParameter(" Latitude (3 decimals, will be public)" , " lat" , latitude, COORDINATE_LENGTH, NULL , " 0.000" , " required min='-180' max='180' step='0.001'" );
233
285
iotwebconf2::NumberParameter longitudeParam = iotwebconf2::NumberParameter(" Longitude (3 decimals, will be public)" , " lng" , longitude, COORDINATE_LENGTH, NULL , " -0.000" , " required min='-180' max='180' step='0.001'" );
234
- iotwebconf2::SelectParameter tzParam = iotwebconf2::SelectParameter(" Time Zone" , " tz" , tz, TZ_LENGTH, (char *)TZ_VALUES, (char *)TZ_NAMES, sizeof (TZ_VALUES) / TZ_LENGTH, TZ_NAME_LENGTH);
286
+ iotwebconf2::SelectParameter tzParam = iotwebconf2::SelectParameter(" Time Zone" , " tz" , tz, TZ_LENGTH, (char *)TZ_VALUES, (char *)TZ_NAMES, sizeof (TZ_VALUES) / TZ_LENGTH, TZ_NAME_LENGTH);
235
287
236
- iotwebconf2::ParameterGroup groupMqtt = iotwebconf2::ParameterGroup(" MQTT credentials" , " MQTT credentials (get them <a href='https://t.me/joinchat/DmYSElZahiJGwHX6jCzB3Q'>here</a>)" );
288
+ iotwebconf2::ParameterGroup groupMqtt = iotwebconf2::ParameterGroup(" MQTT credentials" , " MQTT credentials (get them <a href='https://t.me/joinchat/DmYSElZahiJGwHX6jCzB3Q'>here</a>)" );
237
289
iotwebconf2::TextParameter mqttServerParam = iotwebconf2::TextParameter(" Server address" , " mqtt_server" , mqttServer, MQTT_SERVER_LENGTH, MQTT_DEFAULT_SERVER, MQTT_DEFAULT_SERVER, " required type=\" text\" maxlength=30" );
238
290
iotwebconf2::NumberParameter mqttPortParam = iotwebconf2::NumberParameter(" Server Port" , " mqtt_port" , mqttPort, MQTT_PORT_LENGTH, MQTT_DEFAULT_PORT, MQTT_DEFAULT_PORT, " required min=\" 0\" max=\" 65536\" step=\" 1\" " );
239
291
iotwebconf2::TextParameter mqttUserParam = iotwebconf2::TextParameter(" MQTT Username" , " mqtt_user" , mqttUser, MQTT_USER_LENGTH, NULL , NULL , " required type=\" text\" maxlength=30" );
240
292
iotwebconf2::TextParameter mqttPassParam = iotwebconf2::TextParameter(" MQTT Password" , " mqtt_pass" , mqttPass, MQTT_PASS_LENGTH, NULL , NULL , " required type=\" text\" maxlength=30" );
241
293
242
- iotwebconf2::ParameterGroup groupBoardConfig = iotwebconf2::ParameterGroup(" Board config" , " Board config" );
243
- iotwebconf2::SelectParameter boardParam = iotwebconf2::SelectParameter(" Board type" , " board" , board, BOARD_LENGTH, (char *)BOARD_VALUES, (char *)BOARD_NAMES, sizeof (BOARD_VALUES) / BOARD_LENGTH, BOARD_NAME_LENGTH);
294
+ iotwebconf2::ParameterGroup groupBoardConfig = iotwebconf2::ParameterGroup(" Board config" , " Board config" );
295
+ iotwebconf2::SelectParameter boardParam = iotwebconf2::SelectParameter(" Board type" , " board" , board, BOARD_LENGTH, (char *)BOARD_VALUES, (char *)BOARD_NAMES, sizeof (BOARD_VALUES) / BOARD_LENGTH, BOARD_NAME_LENGTH);
244
296
iotwebconf2::NumberParameter oledBrightParam = iotwebconf2::NumberParameter(" OLED Bright" , " oled_bright" , oledBright, NUMBER_LEN, " 100" , " 0..100" , " min='0' max='100' step='1'" );
245
- iotwebconf2::CheckboxParameter AllowTxParam = iotwebconf2::CheckboxParameter(" Enable TX (HAM licence/ no preamp)" , " tx" , allowTx, CHECKBOX_LENGTH, true );
246
- iotwebconf2::CheckboxParameter remoteTuneParam = iotwebconf2::CheckboxParameter(" Allow Automatic Tuning" ," remote_tune" ,remoteTune, CHECKBOX_LENGTH, true );
247
- iotwebconf2::CheckboxParameter telemetry3rdParam = iotwebconf2::CheckboxParameter(" Allow sending telemetry to third party" ," telemetry3rd" ,telemetry3rd, CHECKBOX_LENGTH, true );
248
- iotwebconf2::CheckboxParameter testParam = iotwebconf2::CheckboxParameter(" Test mode" ," test" ,testMode, CHECKBOX_LENGTH, false );
249
- iotwebconf2::CheckboxParameter autoUpdateParam = iotwebconf2::CheckboxParameter(" Automatic Firmware Update" ," auto_update" ,autoUpdate, CHECKBOX_LENGTH, true );
297
+ iotwebconf2::CheckboxParameter AllowTxParam = iotwebconf2::CheckboxParameter(" Enable TX (HAM licence/ no preamp)" , " tx" , allowTx, CHECKBOX_LENGTH, true );
298
+ iotwebconf2::CheckboxParameter remoteTuneParam = iotwebconf2::CheckboxParameter(" Allow Automatic Tuning" , " remote_tune" , remoteTune, CHECKBOX_LENGTH, true );
299
+ iotwebconf2::CheckboxParameter telemetry3rdParam = iotwebconf2::CheckboxParameter(" Allow sending telemetry to third party" , " telemetry3rd" , telemetry3rd, CHECKBOX_LENGTH, true );
300
+ iotwebconf2::CheckboxParameter testParam = iotwebconf2::CheckboxParameter(" Test mode" , " test" , testMode, CHECKBOX_LENGTH, false );
301
+ iotwebconf2::CheckboxParameter autoUpdateParam = iotwebconf2::CheckboxParameter(" Automatic Firmware Update" , " auto_update" , autoUpdate, CHECKBOX_LENGTH, true );
250
302
251
- iotwebconf2::ParameterGroup groupAdvanced = iotwebconf2::ParameterGroup(" Advanced config" , " Advanced Config (do not modify unless you know what you are doing)" );
303
+ iotwebconf2::ParameterGroup groupAdvanced = iotwebconf2::ParameterGroup(" Advanced config" , " Advanced Config (do not modify unless you know what you are doing)" );
252
304
iotwebconf2::TextParameter boardTemplateParam = iotwebconf2::TextParameter(" Board Template (requires manual restart)" , " board_template" , boardTemplate, TEMPLATE_LEN, NULL , NULL , " type=\" text\" maxlength=255" );
253
305
iotwebconf2::TextParameter modemParam = iotwebconf2::TextParameter(" Modem startup" , " modem_startup" , modemStartup, MODEM_LEN, MODEM_DEFAULT, MODEM_DEFAULT, " type=\" text\" maxlength=255" );
254
306
iotwebconf2::TextParameter advancedConfigParam = iotwebconf2::TextParameter(" Advanced parameters" , " advanced_config" , advancedConfig, ADVANCED_LEN, NULL , NULL , " type=\" text\" maxlength=255" );
0 commit comments