@@ -68,50 +68,35 @@ bool onSetModuleSetting(const String& id, const String& value) {
68
68
69
69
const char * password = doc[" password" ].as <const char *>();
70
70
const char * ssid = doc[" ssid" ].as <const char *>();
71
+ bool connectNow = doc[" connectNow" ] | false ;
71
72
72
73
if (id == SET_WIFI_PRIMARY) { // Set primary WiFi
73
74
spws.updatePrimarySettings (ssid, password);
74
75
} else if (id == SET_WIFI_SECONDARY) { // Set secondary WiFi
75
76
spws.updateSecondarySettings (ssid, password);
76
77
}
77
-
78
- bool connectNow = doc[" connectNow" ] | false ;
79
- if (connectNow) {
80
- return connectToWiFi (ssid, password);
81
- }
82
-
83
- return true ;
78
+
79
+ return connectNow ? connectToWiFi (ssid, password) : true ;
84
80
}
85
81
86
82
bool setupLittleFS () {
87
- // Sets up the LittleFS.
88
83
#if defined(ESP8266)
89
- if (!LittleFS.begin ()) {
84
+ if (!LittleFS.begin () && formatLittleFSIfFailed ) {
90
85
#elif defined(ESP32)
91
- if (!LittleFS.begin (true )) {
86
+ if (!LittleFS.begin (true ) && formatLittleFSIfFailed ) {
92
87
#endif
93
-
94
- Serial.println (" An Error has occurred while mounting LittleFS" );
95
-
96
- if (formatLittleFSIfFailed) {
97
- Serial.println (" Formatting LittleFS..." );
98
- if (LittleFS.format ()) {
99
- Serial.println (" LittleFS formatted successfully!" );
100
- return true ;
101
- } else {
102
- Serial.println (" LittleFS formatting error!" );
103
- return false ;
104
- }
88
+ Serial.println (" Formatting LittleFS..." );
89
+ if (LittleFS.format ()) {
90
+ Serial.println (" LittleFS formatted successfully!" );
91
+ return true ;
105
92
} else {
106
- Serial.println (" LittleFS error!" );
93
+ Serial.println (" LittleFS formatting error!" );
107
94
return false ;
108
95
}
109
96
} else {
110
97
Serial.println (" LittleFS Mount successful" );
111
98
return true ;
112
99
}
113
-
114
- return true ;
115
100
}
116
101
117
102
// setup function for WiFi connection
@@ -121,7 +106,7 @@ void setupWiFi() {
121
106
// Load settings from file or using defaults if loading fails.
122
107
spws.begin ();
123
108
124
- const SinricProWiFiSettings:: wifi_settings_t & settings = spws.getWiFiSettings ();
109
+ auto & settings = spws.getWiFiSettings ();
125
110
bool connected = false ;
126
111
127
112
if (spws.isValidSetting (settings.primarySSID , settings.primaryPassword )) {
@@ -131,6 +116,12 @@ void setupWiFi() {
131
116
if (!connected && spws.isValidSetting (settings.secondarySSID , settings.secondaryPassword )) {
132
117
connected = connectToWiFi (settings.secondarySSID , settings.secondaryPassword );
133
118
}
119
+
120
+ if (connected) {
121
+ Serial.println (" Connected to WiFi!" );
122
+ } else {
123
+ Serial.println (" Failed to connect to WiFi!" );
124
+ }
134
125
}
135
126
136
127
bool connectToWiFi (const char * ssid, const char * password) {
@@ -146,8 +137,6 @@ bool connectToWiFi(const char* ssid, const char* password) {
146
137
#elif defined(ESP8266)
147
138
WiFi.setSleepMode (WIFI_NONE_SLEEP);
148
139
WiFi.begin (ssid, password);
149
- #elif defined(ARDUINO_ARCH_RP2040)
150
- WiFi.begin (ssid, password);
151
140
#endif
152
141
153
142
int timeout = 0 ;
0 commit comments