14
14
#define PUB_PERIOD 10000 // Publication period, ms
15
15
#define SECONDARY_PERIOD 300U // second handler timer, ms
16
16
17
+ // Update defs
18
+ #define FW_MAGIC 0xe9
19
+ #ifdef ESP32
20
+ #define U_FS U_SPIFFS
21
+ #endif
22
+
17
23
EmbUI embui;
18
24
19
25
void section_main_frame (Interface *interf, JsonObject *data) {}
20
26
void pubCallback (Interface *interf){}
21
27
String httpCallback (const String ¶m, const String &value, bool isSet) { return String (); }
22
- void uploadProgress (size_t len, size_t total){
23
- static int prev = 0 ;
24
- float part = total / 50.0 ;
25
- int curr = len / part;
26
- if (curr != prev) {
27
- prev = curr;
28
- for (int i = 0 ; i < curr; i++){
29
- LOG (print, " =" );
30
- }
31
- LOG (print, " \n " );
32
- }
33
- }
34
28
35
29
void onWsEvent (AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len){
36
30
if (type == WS_EVT_CONNECT){
@@ -291,8 +285,7 @@ void EmbUI::begin(){
291
285
request->send (200 , FPSTR (PGmimetxt), out);
292
286
});
293
287
294
- #ifndef ESP32
295
- // Simple Firmware Update Form (ESP32 ota broken)
288
+ // Simple Firmware Update Form
296
289
server.on (PSTR (" /update" ), HTTP_GET, [](AsyncWebServerRequest *request){
297
290
request->send (200 , FPSTR (PGmimehtml), F (" <form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>" ));
298
291
});
@@ -308,10 +301,17 @@ void EmbUI::begin(){
308
301
}
309
302
},[](AsyncWebServerRequest *request, String filename, size_t index , uint8_t *data, size_t len, bool final ){
310
303
if (!index ) {
311
- Update.runAsync (true );
312
- int type = (data[0 ] == 0xe9 || data[0 ] == 0x1f )? U_FLASH : U_FS;
313
- size_t size = (type == U_FLASH)? ((ESP.getFreeSketchSpace () - 0x1000 ) & 0xFFFFF000 ) : (uintptr_t )&_FS_end - (uintptr_t )&_FS_start;
314
- LOG (printf_P, PSTR (" Update %s Start (%u)\n " ), (type == U_FLASH)? F (" Firmware" ) : F (" Filesystem" ), request->contentLength ());
304
+ int type = (data[0 ] == FW_MAGIC)? U_FLASH : U_FS;
305
+
306
+ #ifdef ESP8266
307
+ Update.runAsync (true );
308
+ // TODO: разобраться почему под littlefs образ генерится чуть больше чем размер доступной памяти по константам
309
+ size_t size = (type == U_FLASH)? request->contentLength () : (uintptr_t )&_FS_end - (uintptr_t )&_FS_start;
310
+ #endif
311
+ #ifdef ESP32
312
+ size_t size = (type == U_FLASH)? request->contentLength () : UPDATE_SIZE_UNKNOWN;
313
+ #endif
314
+ LOG (printf_P, PSTR (" Updating %s, file size:%u\n " ), (type == U_FLASH)? F (" Firmware" ) : F (" Filesystem" ), request->contentLength ());
315
315
316
316
if (!Update.begin (size, type)) {
317
317
Update.printError (Serial);
@@ -329,9 +329,8 @@ void EmbUI::begin(){
329
329
Update.printError (Serial);
330
330
}
331
331
}
332
- uploadProgress (index + len, request->contentLength ());
332
+ embui. uploadProgress (index + len, request->contentLength ());
333
333
});
334
- #endif
335
334
336
335
// First request will return 0 results unless you start scan from somewhere else (loop/setup)
337
336
// Do not request more often than 3-5 seconds
@@ -429,4 +428,19 @@ void EmbUI::set_callback(CallBack set, CallBack action, callback_function_t call
429
428
default :
430
429
return ;
431
430
}
432
- };
431
+ };
432
+
433
+ /*
434
+ * OTA update progress
435
+ */
436
+ uint8_t EmbUI::uploadProgress (size_t len, size_t total){
437
+ static int prev = 0 ;
438
+ float part = total / 25.0 ; // logger chunks
439
+ int curr = len / part;
440
+ uint8_t progress = 100 *len/total;
441
+ if (curr != prev) {
442
+ prev = curr;
443
+ LOG (printf_P, PSTR (" %u%%.." ), progress );
444
+ }
445
+ return progress;
446
+ }
0 commit comments