20
20
#include " BootstrapManager.h"
21
21
22
22
23
- void BootstrapManager::littleFsInit () {
23
+ /* ********************************* BOOTSTRAP FUNCTIONS FOR SETUP() *****************************************/
24
+ void BootstrapManager::bootstrapSetup (void (*manageDisconnections)(), void (*manageHardwareButton)(), void (*callback)(char *, byte*, unsigned int )) {
25
+
24
26
#if defined(ESP8266)
25
27
if (!LittleFS.begin ()) {
26
28
#elif defined(ESP32)
27
- if (!LittleFS.begin (true )) {
29
+ if (!LittleFS.begin (true )) {
28
30
#endif
29
31
Serial.println (" LittleFS mount failed" );
30
32
return ;
31
33
}
32
- }
33
-
34
- /* ********************************* BOOTSTRAP FUNCTIONS FOR SETUP() *****************************************/
35
- void BootstrapManager::bootstrapSetup (void (*manageDisconnections)(), void (*manageHardwareButton)(), void (*callback)(char *, byte*, unsigned int )) {
36
34
37
- littleFsInit ();
38
35
if (isWifiConfigured () && !forceWebServer) {
39
36
isConfigFileOk = true ;
40
37
// Initialize Wifi manager
@@ -54,29 +51,6 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
54
51
55
52
}
56
53
57
- /* ********************************* BOOTSTRAP FUNCTIONS FOR SETUP() *****************************************/
58
- void BootstrapManager::bootstrapSetup (void (*manageDisconnections)(), void (*manageHardwareButton)(), void (*callback)(char *, byte*, unsigned int ), bool waitImprov, void (*listener)()) {
59
-
60
- littleFsInit ();
61
- if (isWifiConfigured () && !forceWebServer) {
62
- isConfigFileOk = true ;
63
- // Initialize Wifi manager
64
- wifiManager.setupWiFi (manageDisconnections, manageHardwareButton);
65
- // Initialize Queue Manager
66
- if (mqttIP.length () > 0 ) {
67
- QueueManager::setupMQTTQueue (callback);
68
- } else {
69
- Serial.println (F (" Skip MQTT connection." ));
70
- }
71
- // Initialize OTA manager
72
- WifiManager::setupOTAUpload ();
73
- } else {
74
- isConfigFileOk = false ;
75
- launchWebServerCustom (waitImprov, listener);
76
- }
77
-
78
- }
79
-
80
54
/* ********************************* BOOTSTRAP FUNCTIONS FOR LOOP() *****************************************/
81
55
bool rcpResponseSent = false ;
82
56
void BootstrapManager::bootstrapLoop (void (*manageDisconnections)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)()) {
@@ -470,6 +444,7 @@ bool BootstrapManager::isWifiConfigured() {
470
444
StaticJsonDocument<BUFFER_SIZE> mydoc = readLittleFS (" setup.json" );
471
445
if (mydoc.containsKey (" qsid" )) {
472
446
Serial.println (" Storage OK, restoring WiFi and MQTT config." );
447
+ deviceName = Helpers::getValue (mydoc[" deviceName" ]);
473
448
microcontrollerIP = Helpers::getValue (mydoc[" microcontrollerIP" ]);
474
449
qsid = Helpers::getValue (mydoc[" qsid" ]);
475
450
qpass = Helpers::getValue (mydoc[" qpass" ]);
@@ -479,7 +454,6 @@ bool BootstrapManager::isWifiConfigured() {
479
454
mqttuser = Helpers::getValue (mydoc[" mqttuser" ]);
480
455
mqttpass = Helpers::getValue (mydoc[" mqttpass" ]);
481
456
additionalParam = Helpers::getValue (mydoc[" additionalParam" ]);
482
- deviceName = Helpers::getValue (mydoc[" deviceName" ]);
483
457
return true ;
484
458
} else {
485
459
Serial.println (" No setup file" );
@@ -493,13 +467,6 @@ bool BootstrapManager::isWifiConfigured() {
493
467
void BootstrapManager::launchWebServerForOTAConfig () {
494
468
495
469
#if (IMPROV_ENABLED > 0)
496
- manageImprov ();
497
- #endif
498
- return WifiManager::launchWebServerForOTAConfig ();
499
-
500
- }
501
-
502
- void BootstrapManager::manageImprov () {
503
470
unsigned long timeNowStatus = 0 ;
504
471
bool switchToWebServer = false ;
505
472
// If WiFi is not configured, handle improv packet for 15 seconds, then switch to settinigs managed by web server
@@ -511,16 +478,8 @@ void BootstrapManager::manageImprov() {
511
478
}
512
479
wifiManager.manageImprovWifi ();
513
480
}
514
- }
515
-
516
- void BootstrapManager::launchWebServerCustom (bool waitImprov, void (*listener)()) {
517
-
518
- #if (IMPROV_ENABLED > 0)
519
- if (waitImprov) {
520
- manageImprov ();
521
- }
522
481
#endif
523
- return WifiManager::launchWebServerCustom (listener );
482
+ return WifiManager::launchWebServerForOTAConfig ( );
524
483
525
484
}
526
485
0 commit comments