@@ -52,23 +52,59 @@ HTTPUpdateResult HTTPUpdate::update(NetworkClient &client, const String &url, co
52
52
if (!http.begin (client, url)) {
53
53
return HTTP_UPDATE_FAILED;
54
54
}
55
- return handleUpdate (http, currentVersion, false , requestCB);
55
+ return handleUpdate (http, currentVersion, U_FLASH, requestCB);
56
+ }
57
+
58
+ HTTPUpdateResult HTTPUpdate::updateFs (HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
59
+ return handleUpdate (httpClient, currentVersion, U_FLASHFS, requestCB);
56
60
}
57
61
58
62
HTTPUpdateResult HTTPUpdate::updateSpiffs (HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
59
- return handleUpdate (httpClient, currentVersion, true , requestCB);
63
+ return handleUpdate (httpClient, currentVersion, U_SPIFFS, requestCB);
64
+ }
65
+
66
+ HTTPUpdateResult HTTPUpdate::updateFatfs (HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
67
+ return handleUpdate (httpClient, currentVersion, U_FATFS, requestCB);
68
+ }
69
+
70
+ HTTPUpdateResult HTTPUpdate::updateLittlefs (HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
71
+ return handleUpdate (httpClient, currentVersion, U_LITTLEFS, requestCB);
72
+ }
73
+
74
+ HTTPUpdateResult HTTPUpdate::updateFs (NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
75
+ HTTPClient http;
76
+ if (!http.begin (client, url)) {
77
+ return HTTP_UPDATE_FAILED;
78
+ }
79
+ return handleUpdate (http, currentVersion, U_FLASHFS, requestCB);
60
80
}
61
81
62
82
HTTPUpdateResult HTTPUpdate::updateSpiffs (NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
63
83
HTTPClient http;
64
84
if (!http.begin (client, url)) {
65
85
return HTTP_UPDATE_FAILED;
66
86
}
67
- return handleUpdate (http, currentVersion, true , requestCB);
87
+ return handleUpdate (http, currentVersion, U_SPIFFS, requestCB);
88
+ }
89
+
90
+ HTTPUpdateResult HTTPUpdate::updateFatfs (NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
91
+ HTTPClient http;
92
+ if (!http.begin (client, url)) {
93
+ return HTTP_UPDATE_FAILED;
94
+ }
95
+ return handleUpdate (http, currentVersion, U_FATFS, requestCB);
96
+ }
97
+
98
+ HTTPUpdateResult HTTPUpdate::updateLittlefs (NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
99
+ HTTPClient http;
100
+ if (!http.begin (client, url)) {
101
+ return HTTP_UPDATE_FAILED;
102
+ }
103
+ return handleUpdate (http, currentVersion, U_LITTLEFS, requestCB);
68
104
}
69
105
70
106
HTTPUpdateResult HTTPUpdate::update (HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) {
71
- return handleUpdate (httpClient, currentVersion, false , requestCB);
107
+ return handleUpdate (httpClient, currentVersion, U_FLASH , requestCB);
72
108
}
73
109
74
110
HTTPUpdateResult
@@ -77,7 +113,7 @@ HTTPUpdateResult
77
113
if (!http.begin (client, host, port, uri)) {
78
114
return HTTP_UPDATE_FAILED;
79
115
}
80
- return handleUpdate (http, currentVersion, false , requestCB);
116
+ return handleUpdate (http, currentVersion, U_FLASH , requestCB);
81
117
}
82
118
83
119
/* *
@@ -158,7 +194,7 @@ String getSketchSHA256() {
158
194
* @param currentVersion const char *
159
195
* @return HTTPUpdateResult
160
196
*/
161
- HTTPUpdateResult HTTPUpdate::handleUpdate (HTTPClient &http, const String ¤tVersion, bool spiffs , HTTPUpdateRequestCB requestCB) {
197
+ HTTPUpdateResult HTTPUpdate::handleUpdate (HTTPClient &http, const String ¤tVersion, uint8_t type , HTTPUpdateRequestCB requestCB) {
162
198
163
199
HTTPUpdateResult ret = HTTP_UPDATE_FAILED;
164
200
@@ -187,8 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤
187
223
http.addHeader (" x-ESP32-chip-size" , String (ESP.getFlashChipSize ()));
188
224
http.addHeader (" x-ESP32-sdk-version" , ESP.getSdkVersion ());
189
225
190
- if (spiffs ) {
226
+ if (type == U_SPIFFS ) {
191
227
http.addHeader (" x-ESP32-mode" , " spiffs" );
228
+ } else if (type == U_FATFS) {
229
+ http.addHeader (" x-ESP32-mode" , " fatfs" );
230
+ } else if (type == U_LITTLEFS) {
231
+ http.addHeader (" x-ESP32-mode" , " littlefs" );
232
+ } else if (type == U_FLASHFS) {
233
+ http.addHeader (" x-ESP32-mode" , " flashfs" );
192
234
} else {
193
235
http.addHeader (" x-ESP32-mode" , " sketch" );
194
236
}
@@ -251,8 +293,24 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤
251
293
case HTTP_CODE_OK: // /< OK (Start Update)
252
294
if (len > 0 ) {
253
295
bool startUpdate = true ;
254
- if (spiffs) {
255
- const esp_partition_t *_partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL );
296
+ if (type != U_FLASH) {
297
+ const esp_partition_t *_partition = NULL ;
298
+ if (type == U_SPIFFS) {
299
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL );
300
+ } else if (type == U_FATFS) {
301
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL );
302
+ } else if (type == U_LITTLEFS) {
303
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL );
304
+ } else if (type == U_FLASHFS) {
305
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL );
306
+ if (!_partition) {
307
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL );
308
+ }
309
+ if (!_partition) {
310
+ _partition = esp_partition_find_first (ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL );
311
+ }
312
+ }
313
+
256
314
if (!_partition) {
257
315
_lastError = HTTP_UE_NO_PARTITION;
258
316
return HTTP_UPDATE_FAILED;
@@ -291,17 +349,15 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤
291
349
292
350
delay (100 );
293
351
294
- int command;
352
+ int command = type ;
295
353
296
- if (spiffs) {
297
- command = U_SPIFFS;
298
- log_d (" runUpdate spiffs...\n " );
299
- } else {
300
- command = U_FLASH;
354
+ if (type == U_FLASH) {
301
355
log_d (" runUpdate flash...\n " );
356
+ } else {
357
+ log_d (" runUpdate file system...\n " );
302
358
}
303
359
304
- if (!spiffs ) {
360
+ if (type == U_FLASH ) {
305
361
/* To do
306
362
uint8_t buf[4];
307
363
if(tcp->peekBytes(&buf[0], 4) != 4) {
@@ -341,7 +397,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤
341
397
_cbEnd ();
342
398
}
343
399
344
- if (_rebootOnUpdate && !spiffs ) {
400
+ if (_rebootOnUpdate && type == U_FLASH ) {
345
401
ESP.restart ();
346
402
}
347
403
0 commit comments