Fix crash on startup when not configured - ESP32
This commit is contained in:
parent
142235c355
commit
cf2a20fbd4
83
src/main.cpp
83
src/main.cpp
@ -10,7 +10,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <esp_wifi.h>
|
||||||
#include <SecuritySettingsService.h>
|
#include <SecuritySettingsService.h>
|
||||||
#include <WiFiSettingsService.h>
|
#include <WiFiSettingsService.h>
|
||||||
#include <APSettingsService.h>
|
#include <APSettingsService.h>
|
||||||
@ -41,49 +41,58 @@ APStatus apStatus = APStatus(&server, &securitySettingsService);
|
|||||||
SystemStatus systemStatus = SystemStatus(&server, &securitySettingsService);;
|
SystemStatus systemStatus = SystemStatus(&server, &securitySettingsService);;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Disable wifi config persistance and auto reconnect
|
// Disable wifi config persistance and auto reconnect
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.setAutoReconnect(false);
|
WiFi.setAutoReconnect(false);
|
||||||
|
|
||||||
Serial.begin(SERIAL_BAUD_RATE);
|
#if defined(ESP_PLATFORM)
|
||||||
SPIFFS.begin();
|
// Init the wifi driver on ESP32
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
esp_err_t err = esp_wifi_init(&cfg);
|
||||||
|
if(err){
|
||||||
|
log_e("esp_wifi_init %d", err);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// start security settings service first
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
securitySettingsService.begin();
|
SPIFFS.begin();
|
||||||
|
|
||||||
// start services
|
// Start security settings service first
|
||||||
ntpSettingsService.begin();
|
securitySettingsService.begin();
|
||||||
otaSettingsService.begin();
|
|
||||||
apSettingsService.begin();
|
|
||||||
wifiSettingsService.begin();
|
|
||||||
|
|
||||||
// Serving static resources from /www/
|
// Start services
|
||||||
server.serveStatic("/js/", SPIFFS, "/www/js/");
|
ntpSettingsService.begin();
|
||||||
server.serveStatic("/css/", SPIFFS, "/www/css/");
|
otaSettingsService.begin();
|
||||||
server.serveStatic("/fonts/", SPIFFS, "/www/fonts/");
|
apSettingsService.begin();
|
||||||
server.serveStatic("/app/", SPIFFS, "/www/app/");
|
wifiSettingsService.begin();
|
||||||
server.serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico");
|
|
||||||
|
|
||||||
// Serving all other get requests with "/www/index.htm"
|
// Serving static resources from /www/
|
||||||
// OPTIONS get a straight up 200 response
|
server.serveStatic("/js/", SPIFFS, "/www/js/");
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
server.serveStatic("/css/", SPIFFS, "/www/css/");
|
||||||
if (request->method() == HTTP_GET) {
|
server.serveStatic("/fonts/", SPIFFS, "/www/fonts/");
|
||||||
request->send(SPIFFS, "/www/index.html");
|
server.serveStatic("/app/", SPIFFS, "/www/app/");
|
||||||
} else if (request->method() == HTTP_OPTIONS) {
|
server.serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico");
|
||||||
request->send(200);
|
|
||||||
} else {
|
|
||||||
request->send(404);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Disable CORS if required
|
// Serving all other get requests with "/www/index.htm"
|
||||||
#if defined(ENABLE_CORS)
|
// OPTIONS get a straight up 200 response
|
||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", CORS_ORIGIN);
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
|
if (request->method() == HTTP_GET) {
|
||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
|
request->send(SPIFFS, "/www/index.html");
|
||||||
#endif
|
} else if (request->method() == HTTP_OPTIONS) {
|
||||||
|
request->send(200);
|
||||||
|
} else {
|
||||||
|
request->send(404);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
server.begin();
|
// Disable CORS if required
|
||||||
|
#if defined(ENABLE_CORS)
|
||||||
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", CORS_ORIGIN);
|
||||||
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
|
||||||
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
Loading…
Reference in New Issue
Block a user