Fri, 05 Jul 2019 20:06:31 +0200
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
0 | 1 | /** |
2 | * @file updates.c | |
4 | 3 | * @brief Updates management. It can download and install new firmware |
4 | * downloaded from the internet. | |
0 | 5 | */ |
6 | ||
7 | #include "config.h" | |
8 | ||
9 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
10 | #define BUFFSIZE 1024 ///< Download buffer size |
0 | 11 | static char ota_write_data[BUFFSIZE + 1] = { 0 }; |
12 | static const char *TAG = "update"; | |
13 | ||
14 | extern sButton Buttons[MAXBUTTONS]; | |
15 | extern int Main_Screen; | |
16 | ||
17 | ||
18 | static void http_cleanup(esp_http_client_handle_t client) | |
19 | { | |
20 | esp_http_client_close(client); | |
21 | esp_http_client_cleanup(client); | |
22 | } | |
23 | ||
24 | ||
25 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
26 | /** |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
27 | * @brief Run binary update procedure |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
28 | */ |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
29 | void bin_update(void) |
0 | 30 | { |
31 | char temp[64]; | |
32 | esp_err_t err; | |
33 | const esp_partition_t *update_partition = NULL; | |
34 | esp_ota_handle_t update_handle = 0; | |
35 | ||
36 | TFT_setFont(DEJAVU18_FONT, NULL); | |
37 | _fg = TFT_CYAN; | |
38 | const esp_partition_t *running = esp_ota_get_running_partition(); | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
39 | // snprintf(temp, 63, "Running part.type %d sub %d,\r\nat offset 0x%08x\r\n", |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
40 | // running->type, running->subtype, running->address); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
41 | // TFT_print(temp, 0, LASTY); |
0 | 42 | |
43 | /* | |
44 | * Don't use https because it costs more then 100K memory. | |
45 | */ | |
46 | esp_http_client_config_t update = { | |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
47 | .url = "http://update.mbse.eu/ap1/fw/brewboard.bin", |
0 | 48 | }; |
49 | ||
50 | esp_http_client_handle_t client = esp_http_client_init(&update); | |
51 | if (client == NULL) { | |
52 | ESP_LOGI(TAG, "Failed to init HTTP connection"); | |
53 | goto updateerr; | |
54 | } | |
55 | ||
56 | err = esp_http_client_open(client, 0); | |
57 | if (err != ESP_OK) { | |
58 | ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); | |
59 | esp_http_client_cleanup(client); | |
60 | goto updateerr; | |
61 | } | |
62 | ||
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
63 | int content_length = esp_http_client_fetch_headers(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
64 | int status_code = esp_http_client_get_status_code(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
65 | if (status_code != 200) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
66 | ESP_LOGE(TAG, "GET %s error %d", update.url, status_code); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
67 | esp_http_client_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
68 | goto updateerr; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
69 | } |
0 | 70 | update_partition = esp_ota_get_next_update_partition(NULL); |
71 | if (update_partition == NULL) { | |
72 | ESP_LOGE(TAG, "No update partition"); | |
73 | esp_http_client_cleanup(client); | |
74 | goto updateerr; | |
75 | } | |
76 | ESP_LOGI(TAG, "Update to partition subtype %d at offset 0x%x", update_partition->subtype, update_partition->address); | |
77 | ||
78 | err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); | |
79 | if (err != ESP_OK) { | |
80 | ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); | |
81 | http_cleanup(client); | |
82 | goto updateerr; | |
83 | } | |
84 | ||
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
85 | TFT_print((char *)"Begin firmware download.\r\n", 0, LASTY); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
86 | ESP_LOGI(TAG, "Download update %s size %d", update.url, content_length); |
0 | 87 | int binary_file_length = 0; |
88 | /*deal with all receive packet*/ | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
89 | bool image_header_was_checked = false; |
0 | 90 | while (1) { |
91 | int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE); | |
92 | if (data_read < 0) { | |
93 | ESP_LOGE(TAG, "Error: data read error"); | |
94 | http_cleanup(client); | |
95 | goto updateerr;; | |
96 | } else if (data_read > 0) { | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
97 | if (image_header_was_checked == false) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
98 | esp_app_desc_t new_app_info; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
99 | if (data_read > sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t)) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
100 | // check current version with downloading |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
101 | memcpy(&new_app_info, &ota_write_data[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t)); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
102 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
103 | esp_app_desc_t running_app_info; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
104 | if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
105 | ESP_LOGI(TAG, "Running firmware version: %s, %s %s", running_app_info.version, running_app_info.date, running_app_info.time); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
106 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
107 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
108 | const esp_partition_t* last_invalid_app = esp_ota_get_last_invalid_partition(); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
109 | esp_app_desc_t invalid_app_info; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
110 | if (esp_ota_get_partition_description(last_invalid_app, &invalid_app_info) == ESP_OK) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
111 | ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
112 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
113 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
114 | // check current sha256 with last invalid partition |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
115 | if (last_invalid_app != NULL) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
116 | if (memcmp(invalid_app_info.app_elf_sha256, new_app_info.app_elf_sha256, 32) == 0) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
117 | ESP_LOGW(TAG, "New version is the same as invalid version."); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
118 | ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
119 | ESP_LOGW(TAG, "The firmware has been rolled back to the previous version."); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
120 | http_cleanup(client); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
121 | goto updateok; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
122 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
123 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
124 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
125 | if (memcmp(new_app_info.app_elf_sha256, running_app_info.app_elf_sha256, 32) == 0) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
126 | ESP_LOGI(TAG, "Current running version is the same as a new."); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
127 | http_cleanup(client); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
128 | goto updateok; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
129 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
130 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
131 | image_header_was_checked = true; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
132 | |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
133 | err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
134 | if (err != ESP_OK) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
135 | ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
136 | http_cleanup(client); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
137 | goto updateerr; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
138 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
139 | ESP_LOGI(TAG, "Continue upgrade application"); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
140 | } else { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
141 | ESP_LOGE(TAG, "Received package is not fit len"); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
142 | http_cleanup(client); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
143 | goto updateerr; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
144 | } |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
145 | } |
0 | 146 | err = esp_ota_write( update_handle, (const void *)ota_write_data, data_read); |
147 | if (err != ESP_OK) { | |
148 | http_cleanup(client); | |
149 | goto updateerr;; | |
150 | } | |
151 | binary_file_length += data_read; | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
152 | ESP_LOGD(TAG, "Written image length %d", binary_file_length); |
0 | 153 | } else if (data_read == 0) { |
154 | break; | |
155 | } | |
156 | } | |
157 | ||
158 | ESP_LOGI(TAG, "Download complete, binary data length: %d", binary_file_length); | |
159 | http_cleanup(client); | |
160 | ||
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
161 | if (binary_file_length != content_length) { |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
162 | ESP_LOGE(TAG, "Incomplete file"); |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
163 | goto updateerr; |
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
164 | } |
0 | 165 | if (esp_ota_end(update_handle) != ESP_OK) { |
166 | ESP_LOGE(TAG, "esp_ota_end failed!"); | |
167 | goto updateerr; | |
168 | } | |
169 | snprintf(temp, 63, "Received image %d bytes\r\n", binary_file_length); | |
170 | TFT_print(temp, 0, LASTY); | |
171 | ||
172 | /* | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
173 | * Here we have new version, install and boot it. |
0 | 174 | */ |
175 | err = esp_ota_set_boot_partition(update_partition); | |
176 | if (err != ESP_OK) { | |
177 | ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); | |
178 | goto updateerr; | |
179 | } | |
180 | ||
181 | ESP_LOGI(TAG, "Prepare to restart system!"); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
182 | TFT_print((char *)"Rebooting ...", 0, LASTY); |
0 | 183 | vTaskDelay(1000 / portTICK_PERIOD_MS); |
184 | esp_restart(); | |
67
4badc7e7d629
Use the sha256 in the application version to see if it's a different version. Stop the upgrade download if it's not a new version.
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
185 | return; |
0 | 186 | |
187 | updateerr: | |
188 | _fg = TFT_RED; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
189 | TFT_print((char *)"Error\r\n", 0, LASTY); |
0 | 190 | |
191 | updateok: | |
192 | vTaskDelay(3000 / portTICK_PERIOD_MS); | |
193 | } | |
194 | ||
195 | ||
196 | ||
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
197 | /** |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
198 | * @brief Download a file to /spiffs |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
199 | * @param filename The name and path of the file to download. |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
200 | * @return Return 0 if ok, negative if errors. |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
201 | */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
202 | int DownloadSpiffs(char *filename) |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
203 | { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
204 | esp_err_t err; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
205 | static char theurl[73], thefile[41]; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
206 | FILE *f; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
207 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
208 | // static char todel[41]; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
209 | // snprintf(todel, 40, "/spiffs//%s", filename); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
210 | // unlink(todel); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
211 | // return 0; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
212 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
213 | snprintf(theurl, 72, "http://update.mbse.eu/ap1/image/%s", filename); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
214 | snprintf(thefile, 40, "/spiffs/%s", filename); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
215 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
216 | esp_http_client_config_t update = { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
217 | .url = theurl, |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
218 | }; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
219 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
220 | esp_http_client_handle_t client = esp_http_client_init(&update); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
221 | if (client == NULL) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
222 | ESP_LOGE(TAG, "Failed to init HTTP connection"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
223 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
224 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
225 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
226 | err = esp_http_client_open(client, 0); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
227 | if (err != ESP_OK) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
228 | ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
229 | esp_http_client_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
230 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
231 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
232 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
233 | int content_length = esp_http_client_fetch_headers(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
234 | int status_code = esp_http_client_get_status_code(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
235 | if (status_code != 200) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
236 | ESP_LOGE(TAG, "GET %s error %d", update.url, status_code); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
237 | esp_http_client_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
238 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
239 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
240 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
241 | /* |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
242 | * Remove a possible stale download. |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
243 | */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
244 | unlink("/spiffs/tmpfile"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
245 | f = fopen("/spiffs/tmpfile", "w"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
246 | if (f == NULL) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
247 | ESP_LOGE(TAG, "Cannot create /spiffs/tmpfile"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
248 | esp_http_client_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
249 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
250 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
251 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
252 | int read_length = 0; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
253 | int write_length = 0; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
254 | while (1) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
255 | int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
256 | if (data_read < 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
257 | ESP_LOGE(TAG, "Error: data read error %s", theurl); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
258 | http_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
259 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
260 | } else if (data_read > 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
261 | size_t bytes = fwrite(ota_write_data, 1, data_read, f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
262 | if (bytes != data_read) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
263 | ESP_LOGE(TAG, "fwrite %s %d/%d at %d", theurl, bytes, data_read, write_length); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
264 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
265 | write_length += bytes; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
266 | read_length += data_read; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
267 | } else if (data_read == 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
268 | break; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
269 | } |
42 | 270 | vTaskDelay(10 / portTICK_PERIOD_MS); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
271 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
272 | fclose(f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
273 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
274 | if (content_length != write_length) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
275 | ESP_LOGE(TAG, "Download %s size %d but got %d bytes", theurl, content_length, write_length); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
276 | unlink("/spiffs/tmpfile"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
277 | return -1; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
278 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
279 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
280 | ESP_LOGI(TAG, "Download %s size %d Ok", theurl, content_length); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
281 | unlink(thefile); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
282 | rename("/spiffs/tmpfile", thefile); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
283 | esp_http_client_cleanup(client); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
284 | return 0; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
285 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
286 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
287 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
288 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
289 | /** |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
290 | * @brief Update /spiffs filesystem |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
291 | */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
292 | void spiffs_update(void) |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
293 | { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
294 | int rc; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
295 | FILE *f; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
296 | char v1[12], v2[12], fn[41]; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
297 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
298 | TFT_setFont(DEJAVU18_FONT, NULL); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
299 | _fg = TFT_CYAN; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
300 | TFT_print((char *)"Update /spiffs ", 0, 25); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
301 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
302 | rc = rename("/spiffs/version.txt", "/spiffs/version.old"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
303 | if ((rc != 0) && (errno == ENOENT)) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
304 | /* No old file. */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
305 | ESP_LOGI(TAG, "No old /spiffs/version.txt"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
306 | /* Download, install old and new */ |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
307 | DownloadSpiffs((char *)"version.txt"); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
308 | rename("/spiffs/version.txt", "/spiffs/version.old"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
309 | DownloadSpiffs((char *)"version.txt"); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
310 | goto spiffs_update; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
311 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
312 | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
313 | if (DownloadSpiffs((char *)"version.txt") < 0) |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
314 | goto spiffs_error; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
315 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
316 | /* Compare spiffs/version.old and /spiffs/version.txt */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
317 | v1[0] = '\0'; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
318 | v2[0] = '\0'; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
319 | f = fopen("/spiffs/version.old", "r"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
320 | if (f) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
321 | fgets(v1, 11, f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
322 | fclose(f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
323 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
324 | f = fopen("/spiffs/version.txt", "r"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
325 | if (f) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
326 | fgets(v2, 11, f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
327 | fclose(f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
328 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
329 | if (strcmp(v1, v2) == 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
330 | ESP_LOGI(TAG, "/spiffs is up to date"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
331 | TFT_print((char *)"Ok\r\n", LASTX, LASTY); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
332 | unlink("/spiffs/version.old"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
333 | return; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
334 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
335 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
336 | spiffs_update: |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
337 | /* |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
338 | * Run the update, get the filelist. |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
339 | */ |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
340 | ESP_LOGI(TAG, "Full /spiffs update"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
341 | rc = DownloadSpiffs((char *)"files.list"); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
342 | if (rc < 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
343 | unlink("/spiffs/version.txt"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
344 | rename("/spiffs/version.old", "/spiffs/version.txt"); // So next time we try again. |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
345 | goto spiffs_error; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
346 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
347 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
348 | f = fopen("/spiffs/files.list", "r"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
349 | while (fgets(fn, 40, f)) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
350 | fn[strlen(fn)-1] = '\0'; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
351 | rc = DownloadSpiffs(fn); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
352 | if (rc < 0) { |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
353 | ESP_LOGE(TAG, "Updates failed"); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
354 | fclose(f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
355 | goto spiffs_error; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
356 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
357 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
358 | fclose(f); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
359 | unlink("/spiffs/version.old"); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
360 | TFT_print((char *)"updated\r\n", LASTX, LASTY); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
361 | return; |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
362 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
363 | spiffs_error: |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
364 | _fg = TFT_RED; |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
365 | TFT_print((char *)"error\r\n", LASTX, LASTY); |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
366 | } |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
367 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
368 | |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
369 | |
0 | 370 | /* |
371 | * Files init function, only runs once a new screen is entered. | |
372 | */ | |
373 | void Updates_Init(void) | |
374 | { | |
375 | switch (Main_Screen) { | |
376 | case MAIN_TOOLS_UPDATES: | |
377 | _bg = TFT_BLACK; | |
378 | TFT_fillScreen(_bg); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
379 | TopMessage((char *)"Update"); |
0 | 380 | break; |
381 | ||
382 | default: break; | |
383 | } | |
384 | } | |
385 | ||
386 | ||
387 | ||
388 | /* | |
389 | * Updates management loop, non-blocking. | |
390 | */ | |
391 | void Updates_Loop(void) | |
392 | { | |
393 | switch (Main_Screen) { | |
394 | ||
395 | case MAIN_TOOLS_UPDATES: | |
13
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
396 | spiffs_update(); |
8f01b74bf1dd
Update /spiffs via internet. http://update.mbse.eu is now the update server.
Michiel Broek <mbroek@mbse.eu>
parents:
4
diff
changeset
|
397 | bin_update(); |
0 | 398 | Main_Screen = MAIN_TOOLS; |
399 | break; | |
400 | ||
401 | default: break; | |
402 | } | |
403 | } | |
404 | ||
405 |