# HG changeset patch # User Michiel Broek # Date 1540415704 -7200 # Node ID 8f01b74bf1ddd51b46b5e1fcee8c7503947f1279 # Parent 063a21ca11f7900a3eab91988bf22162e7a9780a Update /spiffs via internet. http://update.mbse.eu is now the update server. diff -r 063a21ca11f7 -r 8f01b74bf1dd image/files.list --- a/image/files.list Wed Oct 24 11:55:39 2018 +0200 +++ b/image/files.list Wed Oct 24 23:15:04 2018 +0200 @@ -1,81 +1,75 @@ -/fonts/BigFont.fon -/fonts/DejaVuSans12.fon -/fonts/DejaVuSans18.fon -/fonts/DejaVuSans24.fon -/fonts/DotMatrix_M.fon -/fonts/Grotesk24x48.fon -/fonts/SmallFont.fon -/fonts/Ubuntu.fon -/fonts/arial_bold.fon -/fonts/ocrfont.c -/fonts/swiss721_outline.fon -/www/app/error-handler.js.gz -/www/app/localization.js.gz -/www/app/ui.js.gz -/www/app/webutil.js.gz -/www/app/images/clipboard.svg.gz -/www/app/images/connect.svg.gz -/www/app/images/disconnect.svg.gz -/www/app/images/drag.svg.gz -/www/app/images/error.svg.gz -/www/app/images/expander.svg.gz -/www/app/images/fullscreen.svg.gz -/www/app/images/handle.svg.gz -/www/app/images/handle_bg.svg.gz -/www/app/images/info.svg.gz -/www/app/images/mouse_left.svg.gz -/www/app/images/mouse_middle.svg.gz -/www/app/images/mouse_none.svg.gz -/www/app/images/mouse_right.svg.gz -/www/app/images/settings.svg.gz -/www/app/images/warning.svg.gz -/www/app/locale/de.json -/www/app/locale/el.json -/www/app/locale/es.json -/www/app/locale/nl.json -/www/app/locale/pl.json -/www/app/locale/sv.json -/www/app/locale/tr.json -/www/app/locale/zh.json -/www/app/sounds/bell.mp3 -/www/app/sounds/bell.oga -/www/app/styles/base.css -/www/app/styles/web.css -/www/core/base64.js.gz -/www/core/des.js.gz -/www/core/display.js.gz -/www/core/encodings.js.gz -/www/core/inflator.js.gz -/www/core/rfb.js.gz -/www/core/websock.js.gz -/www/core/input/mouse.js.gz -/www/core/util/browser.js.gz -/www/core/util/events.js.gz -/www/core/util/eventtarget.js.gz -/www/core/util/logging.js.gz -/www/core/util/polyfill.js.gz -/www/core/util/strings.js.gz -www/css/style.css -www/js/Chart.min.js.gz -www/js/ch-plug-anno.min.js.gz -www/js/jquery-1.12.4.min.js.gz -www/js/webui.js -www/js/modl/babel.js.gz -www/js/modl/brloader.js.gz -www/js/utils/common.js.gz -www/js/zlib/adler32.js.gz -www/js/zlib/constants.js.gz -www/js/zlib/crc32.js.gz -www/js/zlib/deflate.js.gz -www/js/zlib/gzheader.js.gz -www/js/zlib/inffast.js.gz -www/js/zlib/inflate.js.gz -www/js/zlib/inftrees.js.gz -www/js/zlib/messages.js.gz -www/js/zlib/trees.js.gz -www/js/zlib/zstream.js.gz -www/chart.html -www/index.html -www/logs.html -www/vnc.html.gz -www/webui.html +fonts/DejaVuSans18.fon +fonts/DejaVuSans24.fon +fonts/Grotesk24x48.fon +fonts/SmallFont.fon +fonts/Ubuntu.fon +w/app/error-handler.js.gz +w/app/localization.js.gz +w/app/ui.js.gz +w/app/webutil.js.gz +w/app/images/clipboard.svg.gz +w/app/images/connect.svg.gz +w/app/images/disconnect.svg.gz +w/app/images/drag.svg.gz +w/app/images/error.svg.gz +w/app/images/expander.svg.gz +w/app/images/fullscreen.svg.gz +w/app/images/handle.svg.gz +w/app/images/handle_bg.svg.gz +w/app/images/info.svg.gz +w/app/images/mouse_left.svg.gz +w/app/images/mouse_middle.svg.gz +w/app/images/mouse_none.svg.gz +w/app/images/mouse_right.svg.gz +w/app/images/settings.svg.gz +w/app/images/warning.svg.gz +w/app/locale/de.json +w/app/locale/el.json +w/app/locale/es.json +w/app/locale/nl.json +w/app/locale/pl.json +w/app/locale/sv.json +w/app/locale/tr.json +w/app/locale/zh.json +w/app/sounds/bell.mp3 +w/app/sounds/bell.oga +w/app/styles/base.css +w/app/styles/web.css +w/core/base64.js.gz +w/core/des.js.gz +w/core/display.js.gz +w/core/encodings.js.gz +w/core/inflator.js.gz +w/core/rfb.js.gz +w/core/websock.js.gz +w/core/input/mouse.js.gz +w/core/util/browser.js.gz +w/core/util/events.js.gz +w/core/util/eventtarget.js.gz +w/core/util/logging.js.gz +w/core/util/polyfill.js.gz +w/core/util/strings.js.gz +w/css/style.css +w/js/Chart.min.js.gz +w/js/ch-plug-anno.min.js.gz +w/js/jquery-1.12.4.min.js.gz +w/js/webui.js +w/js/modl/babel.js.gz +w/js/modl/brloader.js.gz +w/js/utils/common.js.gz +w/js/zlib/adler32.js.gz +w/js/zlib/constants.js.gz +w/js/zlib/crc32.js.gz +w/js/zlib/deflate.js.gz +w/js/zlib/gzheader.js.gz +w/js/zlib/inffast.js.gz +w/js/zlib/inflate.js.gz +w/js/zlib/inftrees.js.gz +w/js/zlib/messages.js.gz +w/js/zlib/trees.js.gz +w/js/zlib/zstream.js.gz +w/chart.html +w/index.html.gz +w/logs.html +w/vnc.html.gz +w/webui.html diff -r 063a21ca11f7 -r 8f01b74bf1dd image/version.txt --- a/image/version.txt Wed Oct 24 11:55:39 2018 +0200 +++ b/image/version.txt Wed Oct 24 23:15:04 2018 +0200 @@ -1,1 +1,1 @@ -0.2.4 +0.0.g diff -r 063a21ca11f7 -r 8f01b74bf1dd image/w/chart.html --- a/image/w/chart.html Wed Oct 24 11:55:39 2018 +0200 +++ b/image/w/chart.html Wed Oct 24 23:15:04 2018 +0200 @@ -1,34 +1,35 @@ - Brew Log - - - - - - - - + -
+
-
-
+ - - - - - - - - - - - - - - -
-
-
noVNC encountered an error:
-
-
-
-
- - -
- -
-
- -
- -

no
VNC

- - - - - -
- - - - - -
- - -
- -
-
- - - - - -
-
-
- - - -
-
-
- Power -
- - - -
-
- - - -
-
-
- Clipboard -
- -
- -
-
- - - - - - -
-
-
    -
  • - Settings -
  • -
  • - -
  • -
  • - -
  • -

  • -
  • - -
  • -
  • - - -
  • -

  • -
  • -
    Advanced
    -
      -
    • - - -
    • -
    • -
      WebSocket
      -
        -
      • - -
      • -
      • - - -
      • -
      • - - -
      • -
      • - - -
      • -
      -
    • -

    • -
    • - -
    • -
    • - - -
    • -

    • - -
    • - -
    • -
    -
  • -
-
-
- - - - -
-
- -
- -
- - -
- - -
-
- -
- Connect -
-
-
- - -
-
-
    -
  • - - -
  • -
  • - -
  • -
-
-
- - -
-
-
- -
-
-
- - -
- - -
- - - - diff -r 063a21ca11f7 -r 8f01b74bf1dd main/task_sdcard.c --- a/main/task_sdcard.c Wed Oct 24 11:55:39 2018 +0200 +++ b/main/task_sdcard.c Wed Oct 24 23:15:04 2018 +0200 @@ -374,6 +374,7 @@ * @param fromdir Source directory * @param todir Destination directory */ +#if 0 void SyncDirs(char *fromdir, char *todir) { char ff[64], tf[64]; @@ -425,6 +426,7 @@ } closedir(dir); } +#endif @@ -499,15 +501,14 @@ DIR* dir = opendir("/sdcard/w/log"); if (dir == NULL) { ret = mkdir("/sdcard/w/log", 0755); - printf("Dir created ret=%d\n", ret); } else { closedir(dir); } - SyncDirs("/sdcard/w", "/spiffs/w"); - SyncDirs("/sdcard/w/js", "/spiffs/w/js"); - SyncDirs("/sdcard/w/css", "/spiffs/w/css"); +// SyncDirs("/sdcard/w", "/spiffs/w"); +// SyncDirs("/sdcard/w/js", "/spiffs/w/js"); +// SyncDirs("/sdcard/w/css", "/spiffs/w/css"); // SyncDirs("/sdcard/w/js/modl" , "/spiffs/w/js/modl"); // // SyncDirs("/sdcard/w/js/utils", "/spiffs/w/js/utils"); // SyncDirs("/sdcard/w/js/zlib", "/spiffs/w/js/zlib"); @@ -518,7 +519,7 @@ // SyncDirs("/sdcard/w/app/images", "/spiffs/w/app/images"); // SyncDirs("/sdcard/w/app/locale", "/spiffs/w/app/locale"); // SyncDirs("/sdcard/w/app/sounds", "/spiffs/w/app/sounds"); // - SyncDirs("/sdcard/w/app/styles", "/spiffs/w/app/styles"); +// SyncDirs("/sdcard/w/app/styles", "/spiffs/w/app/styles"); // SyncDirs("/sdcard/fonts", "/spiffs/fonts"); // } diff -r 063a21ca11f7 -r 8f01b74bf1dd main/updates.c --- a/main/updates.c Wed Oct 24 11:55:39 2018 +0200 +++ b/main/updates.c Wed Oct 24 23:15:04 2018 +0200 @@ -24,9 +24,9 @@ /** - * @brief Run update procedure + * @brief Run binary update procedure */ -void run_update(void) +void bin_update(void) { char temp[64]; esp_err_t err; @@ -38,13 +38,13 @@ const esp_partition_t *running = esp_ota_get_running_partition(); snprintf(temp, 63, "Running part.type %d sub %d,\r\nat offset 0x%08x\r\n", running->type, running->subtype, running->address); - TFT_print(temp, 0, 25); + TFT_print(temp, 0, LASTY); /* * Don't use https because it costs more then 100K memory. */ esp_http_client_config_t update = { - .url = "http://seaport.mbse.ym/update/brewboard.bin", + .url = "http://update.mbse.eu/ap1/fw/brewboard.bin", }; esp_http_client_handle_t client = esp_http_client_init(&update); @@ -60,7 +60,13 @@ goto updateerr; } - esp_http_client_fetch_headers(client); + int content_length = esp_http_client_fetch_headers(client); + int status_code = esp_http_client_get_status_code(client); + if (status_code != 200) { + ESP_LOGE(TAG, "GET %s error %d", update.url, status_code); + esp_http_client_cleanup(client); + goto updateerr; + } update_partition = esp_ota_get_next_update_partition(NULL); if (update_partition == NULL) { ESP_LOGE(TAG, "No update partition"); @@ -77,7 +83,7 @@ } TFT_print("Begin download.\r\n", 0, LASTY); - ESP_LOGI(TAG, "Download update %s", update.url); + ESP_LOGI(TAG, "Download update %s size %d", update.url, content_length); int binary_file_length = 0; /*deal with all receive packet*/ while (1) { @@ -140,6 +146,183 @@ +/** + * @brief Download a file to /spiffs + * @param filename The name and path of the file to download. + * @return Return 0 if ok, negative if errors. + */ +int DownloadSpiffs(char *filename) +{ + esp_err_t err; + static char theurl[73], thefile[41]; + FILE *f; + +// static char todel[41]; +// snprintf(todel, 40, "/spiffs//%s", filename); +// unlink(todel); +// return 0; + + snprintf(theurl, 72, "http://update.mbse.eu/ap1/image/%s", filename); + snprintf(thefile, 40, "/spiffs/%s", filename); + + esp_http_client_config_t update = { + .url = theurl, + }; + + esp_http_client_handle_t client = esp_http_client_init(&update); + if (client == NULL) { + ESP_LOGE(TAG, "Failed to init HTTP connection"); + return -1; + } + + err = esp_http_client_open(client, 0); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); + esp_http_client_cleanup(client); + return -1; + } + + int content_length = esp_http_client_fetch_headers(client); + int status_code = esp_http_client_get_status_code(client); + if (status_code != 200) { + ESP_LOGE(TAG, "GET %s error %d", update.url, status_code); + esp_http_client_cleanup(client); + return -1; + } + + /* + * Remove a possible stale download. + */ + unlink("/spiffs/tmpfile"); + f = fopen("/spiffs/tmpfile", "w"); + if (f == NULL) { + ESP_LOGE(TAG, "Cannot create /spiffs/tmpfile"); + esp_http_client_cleanup(client); + return -1; + } + + int read_length = 0; + int write_length = 0; + while (1) { + int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE); + if (data_read < 0) { + ESP_LOGE(TAG, "Error: data read error %s", theurl); + http_cleanup(client); + return -1; + } else if (data_read > 0) { + size_t bytes = fwrite(ota_write_data, 1, data_read, f); + if (bytes != data_read) { + ESP_LOGE(TAG, "fwrite %s %d/%d at %d", theurl, bytes, data_read, write_length); + } + write_length += bytes; + read_length += data_read; + } else if (data_read == 0) { + break; + } + vTaskDelay(5 / portTICK_PERIOD_MS); + } + fclose(f); + + if (content_length != write_length) { + ESP_LOGE(TAG, "Download %s size %d but got %d bytes", theurl, content_length, write_length); + unlink("/spiffs/tmpfile"); + return -1; + } + + ESP_LOGI(TAG, "Download %s size %d Ok", theurl, content_length); + unlink(thefile); + rename("/spiffs/tmpfile", thefile); + esp_http_client_cleanup(client); + return 0; +} + + + +/** + * @brief Update /spiffs filesystem + */ +void spiffs_update(void) +{ + int rc; + FILE *f; + char v1[12], v2[12], fn[41]; + + TFT_setFont(DEJAVU18_FONT, NULL); + _fg = TFT_CYAN; + TFT_print("Update /spiffs ", 0, 25); + + rc = rename("/spiffs/version.txt", "/spiffs/version.old"); + if ((rc != 0) && (errno == ENOENT)) { + /* No old file. */ + ESP_LOGI(TAG, "No old /spiffs/version.txt"); + /* Download, install old and new */ + DownloadSpiffs("version.txt"); + rename("/spiffs/version.txt", "/spiffs/version.old"); + DownloadSpiffs("version.txt"); + goto spiffs_update; + } + + if (DownloadSpiffs("version.txt") < 0) + goto spiffs_error; + + /* Compare spiffs/version.old and /spiffs/version.txt */ + v1[0] = '\0'; + v2[0] = '\0'; + f = fopen("/spiffs/version.old", "r"); + if (f) { + fgets(v1, 11, f); + fclose(f); + } + f = fopen("/spiffs/version.txt", "r"); + if (f) { + fgets(v2, 11, f); + fclose(f); + } +// ESP_LOG_BUFFER_HEXDUMP(TAG, v1, strlen(v1), ESP_LOG_INFO); +// ESP_LOG_BUFFER_HEXDUMP(TAG, v2, strlen(v2), ESP_LOG_INFO); + if (strcmp(v1, v2) == 0) { + ESP_LOGI(TAG, "/spiffs is up to date"); + TFT_print("Ok\r\n", LASTX, LASTY); + unlink("/spiffs/version.old"); + return; + } + +spiffs_update: + /* + * Run the update, get the filelist. + */ + ESP_LOGI(TAG, "Full /spiffs update"); + rc = DownloadSpiffs("files.list"); + if (rc < 0) { + unlink("/spiffs/version.txt"); + rename("/spiffs/version.old", "/spiffs/version.txt"); // So next time we try again. + goto spiffs_error; + } + + f = fopen("/spiffs/files.list", "r"); + while (fgets(fn, 40, f)) { + fn[strlen(fn)-1] = '\0'; + rc = DownloadSpiffs(fn); + if (rc < 0) { + ESP_LOGE(TAG, "Updates failed"); + fclose(f); + goto spiffs_error; + } +// vTaskDelay(10 / portTICK_PERIOD_MS); + } + fclose(f); + unlink("/spiffs/version.old"); + TFT_print("updated\r\n", LASTX, LASTY); + return; + +spiffs_error: + _fg = TFT_RED; + TFT_print("error\r\n", LASTX, LASTY); + +} + + + /* * Files init function, only runs once a new screen is entered. */ @@ -166,7 +349,8 @@ switch (Main_Screen) { case MAIN_TOOLS_UPDATES: - run_update(); + spiffs_update(); + bin_update(); Main_Screen = MAIN_TOOLS; break;