@@ -28,7 +28,6 @@ void setup()
2828 initTimers ();
2929 initBLE ();
3030 initWiFi ();
31- updateFromRemote (); // Check for pending remote firmware updates
3231
3332 delay (1000 );
3433 Serial.println (" Connection Type: " + String (config.getUChar (" connection_type" )));
@@ -37,74 +36,88 @@ void setup()
3736 {
3837 initTCP ();
3938 }
40- if ( (config.getUChar (" connection_type" ) == CONNECTION_TYPE_WIFI) )
39+
40+ if (updatesPending ())
4141 {
42- // Init file system
43- if (!SPIFFS.begin (true )) {
44- Serial.println (" An error has occurred while mounting SPIFFS" );
45- }
46- initSSE ();
47- initSerialData ();
48-
49- // Init the web server
50- // Web Server Root URL
42+ // When updates are pending, only show the minimum pages
43+ server.on (" /updateStatus" , HTTP_GET, [](AsyncWebServerRequest *request) {
44+ request->send (200 , " text/json" , update_progress_json (request));
45+ });
5146 server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
52- request->send (SPIFFS, " /index.html" , " text/html" );
53- });
54-
55- server.on (" /data" , HTTP_GET, [](AsyncWebServerRequest *request) {
56- String jsonOutput;
57- serializeJson (readings_JSON, jsonOutput);
58- // request->send(200, "text/json", JSON.stringify(readings_JSON));
59- request->send (200 , " text/json" , jsonOutput.c_str ());
60- });
61-
62- server.serveStatic (" /" , SPIFFS, " /" );
63-
47+ request->send (200 , " text/html" , updateInProgressPage ());
48+ });
6449 }
6550 else
6651 {
67- // If not using the web dash then the root URL will produce the config page
68- server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
69- request->send (200 , " text/html" , webConfigRequest (request));
70- });
71- }
52+ if ( (config.getUChar (" connection_type" ) == CONNECTION_TYPE_WIFI) && (updatesPending () == false ) )
53+ {
54+ // Init file system
55+ if (!SPIFFS.begin (true )) {
56+ Serial.println (" An error has occurred while mounting SPIFFS" );
57+ }
58+ initSSE ();
59+ initSerialData ();
60+
61+ // Init the web server
62+ // Web Server Root URL
63+ server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
64+ request->send (SPIFFS, " /index.html" , " text/html" );
65+ });
66+
67+ server.on (" /data" , HTTP_GET, [](AsyncWebServerRequest *request) {
68+ String jsonOutput;
69+ serializeJson (readings_JSON, jsonOutput);
70+ // request->send(200, "text/json", JSON.stringify(readings_JSON));
71+ request->send (200 , " text/json" , jsonOutput.c_str ());
72+ });
73+
74+ server.serveStatic (" /" , SPIFFS, " /" );
7275
73- server.on (WEB_CONFIG_URL, HTTP_GET, [](AsyncWebServerRequest *request) {
74- request->send (200 , " text/html" , webConfigRequest (request));
75- });
76-
77- server.on (WEB_CONFIG_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
78- request->send (200 , " text/html" , webConfigPOSTRequest (request));
79- });
80-
81- // Updates the firmware AND data from remote URLs
82- server.on (UPDATE_REMOTE_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
83- request->send (200 , " text/html" , saveRemoteFW_URLs (request));
84- ESP.restart ();
85- });
86- // Scan the wifi networks and return them as JSON
87- server.on (" /wifi" , HTTP_GET, [](AsyncWebServerRequest *request) {
88- request->send (200 , " text/json" , scanWifi (request));
89- });
90-
91- server.on (UPDATE_DATA_UPLOAD_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
76+ }
77+ else
78+ {
79+ // If not using the web dash then the root URL will produce the config page
80+ server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
81+ request->send (200 , " text/html" , webConfigRequest (request));
82+ });
83+ }
84+
85+ server.on (WEB_CONFIG_URL, HTTP_GET, [](AsyncWebServerRequest *request) {
86+ request->send (200 , " text/html" , webConfigRequest (request));
87+ });
88+
89+ server.on (WEB_CONFIG_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
90+ request->send (200 , " text/html" , webConfigPOSTRequest (request));
91+ });
92+
93+ // Updates the firmware AND data from remote URLs
94+ server.on (UPDATE_REMOTE_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
95+ request->send (200 , " text/html" , saveRemoteFW_URLs (request));
96+ delay (1000 ); // Wait 1 second to allow the page to be sent before restarting
97+ ESP.restart ();
98+ });
99+ // Scan the wifi networks and return them as JSON
100+ server.on (" /wifi" , HTTP_GET, [](AsyncWebServerRequest *request) {
101+ request->send (200 , " text/json" , scanWifi (request));
102+ });
103+
104+ server.on (UPDATE_DATA_UPLOAD_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
105+ // This runs when the uplaod is completed
106+ partitionUploadComplete (request);
107+ },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final ) {
108+ // This runs each time a new chunk is received
109+ partitionUploadChunk (request, filename, index, data, len, final , U_SPIFFS);
110+ }
111+ );
112+ server.on (UPDATE_FW_UPLOAD_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
92113 // This runs when the uplaod is completed
93114 partitionUploadComplete (request);
94- },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final ) {
115+ },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final ) {
95116 // This runs each time a new chunk is received
96- partitionUploadChunk (request, filename, index, data, len, final , U_SPIFFS);
97- }
98- );
99- server.on (UPDATE_FW_UPLOAD_URL, HTTP_POST, [](AsyncWebServerRequest *request) {
100- // This runs when the uplaod is completed
101- partitionUploadComplete (request);
102- },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final ) {
103- // This runs each time a new chunk is received
104- partitionUploadChunk (request, filename, index, data, len, final , U_FLASH);
105- }
106- );
107-
117+ partitionUploadChunk (request, filename, index, data, len, final , U_FLASH);
118+ }
119+ );
120+ }
108121
109122
110123 // Start server
@@ -116,6 +129,7 @@ void setup()
116129
117130 server.begin ();
118131
132+ updateFromRemote (); // Check for pending remote firmware updates
119133
120134 // By default the ESP32-C3 will output a bunch of diag messages on bootup over UART.
121135 // This messes up the secondary serial on the Speeduino so these bootup messages are disabled.
0 commit comments