main/updates.c

changeset 54
7b134c27fadb
parent 42
c6a1a6ca5437
child 67
4badc7e7d629
equal deleted inserted replaced
53:cf91a3a20d0d 54:7b134c27fadb
80 ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); 80 ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
81 http_cleanup(client); 81 http_cleanup(client);
82 goto updateerr; 82 goto updateerr;
83 } 83 }
84 84
85 TFT_print("Begin download.\r\n", 0, LASTY); 85 TFT_print((char *)"Begin download.\r\n", 0, LASTY);
86 ESP_LOGI(TAG, "Download update %s size %d", update.url, content_length); 86 ESP_LOGI(TAG, "Download update %s size %d", update.url, content_length);
87 int binary_file_length = 0; 87 int binary_file_length = 0;
88 /*deal with all receive packet*/ 88 /*deal with all receive packet*/
89 while (1) { 89 while (1) {
90 int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE); 90 int data_read = esp_http_client_read(client, ota_write_data, BUFFSIZE);
115 snprintf(temp, 63, "Received image %d bytes\r\n", binary_file_length); 115 snprintf(temp, 63, "Received image %d bytes\r\n", binary_file_length);
116 TFT_print(temp, 0, LASTY); 116 TFT_print(temp, 0, LASTY);
117 117
118 if (esp_partition_check_identity(esp_ota_get_running_partition(), update_partition) == true) { 118 if (esp_partition_check_identity(esp_ota_get_running_partition(), update_partition) == true) {
119 ESP_LOGI(TAG, "Already the latest version"); 119 ESP_LOGI(TAG, "Already the latest version");
120 TFT_print("Already the latest version.\r\n", LASTX, LASTY); 120 TFT_print((char *)"Already the latest version.\r\n", LASTX, LASTY);
121 goto updateok; 121 goto updateok;
122 } 122 }
123 123
124 /* 124 /*
125 * Here we have a different and hopefully newer version, install and boot it. 125 * Here we have a different and hopefully newer version, install and boot it.
129 ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); 129 ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err));
130 goto updateerr; 130 goto updateerr;
131 } 131 }
132 132
133 ESP_LOGI(TAG, "Prepare to restart system!"); 133 ESP_LOGI(TAG, "Prepare to restart system!");
134 TFT_print("Rebooting ...", 0, LASTY); 134 TFT_print((char *)"Rebooting ...", 0, LASTY);
135 vTaskDelay(1000 / portTICK_PERIOD_MS); 135 vTaskDelay(1000 / portTICK_PERIOD_MS);
136 esp_restart(); 136 esp_restart();
137 return ; 137 return ;
138 138
139 updateerr: 139 updateerr:
140 _fg = TFT_RED; 140 _fg = TFT_RED;
141 TFT_print("Error\r\n", 0, LASTY); 141 TFT_print((char *)"Error\r\n", 0, LASTY);
142 142
143 updateok: 143 updateok:
144 vTaskDelay(3000 / portTICK_PERIOD_MS); 144 vTaskDelay(3000 / portTICK_PERIOD_MS);
145 } 145 }
146 146
247 FILE *f; 247 FILE *f;
248 char v1[12], v2[12], fn[41]; 248 char v1[12], v2[12], fn[41];
249 249
250 TFT_setFont(DEJAVU18_FONT, NULL); 250 TFT_setFont(DEJAVU18_FONT, NULL);
251 _fg = TFT_CYAN; 251 _fg = TFT_CYAN;
252 TFT_print("Update /spiffs ", 0, 25); 252 TFT_print((char *)"Update /spiffs ", 0, 25);
253 253
254 rc = rename("/spiffs/version.txt", "/spiffs/version.old"); 254 rc = rename("/spiffs/version.txt", "/spiffs/version.old");
255 if ((rc != 0) && (errno == ENOENT)) { 255 if ((rc != 0) && (errno == ENOENT)) {
256 /* No old file. */ 256 /* No old file. */
257 ESP_LOGI(TAG, "No old /spiffs/version.txt"); 257 ESP_LOGI(TAG, "No old /spiffs/version.txt");
258 /* Download, install old and new */ 258 /* Download, install old and new */
259 DownloadSpiffs("version.txt"); 259 DownloadSpiffs((char *)"version.txt");
260 rename("/spiffs/version.txt", "/spiffs/version.old"); 260 rename("/spiffs/version.txt", "/spiffs/version.old");
261 DownloadSpiffs("version.txt"); 261 DownloadSpiffs((char *)"version.txt");
262 goto spiffs_update; 262 goto spiffs_update;
263 } 263 }
264 264
265 if (DownloadSpiffs("version.txt") < 0) 265 if (DownloadSpiffs((char *)"version.txt") < 0)
266 goto spiffs_error; 266 goto spiffs_error;
267 267
268 /* Compare spiffs/version.old and /spiffs/version.txt */ 268 /* Compare spiffs/version.old and /spiffs/version.txt */
269 v1[0] = '\0'; 269 v1[0] = '\0';
270 v2[0] = '\0'; 270 v2[0] = '\0';
278 fgets(v2, 11, f); 278 fgets(v2, 11, f);
279 fclose(f); 279 fclose(f);
280 } 280 }
281 if (strcmp(v1, v2) == 0) { 281 if (strcmp(v1, v2) == 0) {
282 ESP_LOGI(TAG, "/spiffs is up to date"); 282 ESP_LOGI(TAG, "/spiffs is up to date");
283 TFT_print("Ok\r\n", LASTX, LASTY); 283 TFT_print((char *)"Ok\r\n", LASTX, LASTY);
284 unlink("/spiffs/version.old"); 284 unlink("/spiffs/version.old");
285 return; 285 return;
286 } 286 }
287 287
288 spiffs_update: 288 spiffs_update:
289 /* 289 /*
290 * Run the update, get the filelist. 290 * Run the update, get the filelist.
291 */ 291 */
292 ESP_LOGI(TAG, "Full /spiffs update"); 292 ESP_LOGI(TAG, "Full /spiffs update");
293 rc = DownloadSpiffs("files.list"); 293 rc = DownloadSpiffs((char *)"files.list");
294 if (rc < 0) { 294 if (rc < 0) {
295 unlink("/spiffs/version.txt"); 295 unlink("/spiffs/version.txt");
296 rename("/spiffs/version.old", "/spiffs/version.txt"); // So next time we try again. 296 rename("/spiffs/version.old", "/spiffs/version.txt"); // So next time we try again.
297 goto spiffs_error; 297 goto spiffs_error;
298 } 298 }
308 } 308 }
309 // vTaskDelay(10 / portTICK_PERIOD_MS); 309 // vTaskDelay(10 / portTICK_PERIOD_MS);
310 } 310 }
311 fclose(f); 311 fclose(f);
312 unlink("/spiffs/version.old"); 312 unlink("/spiffs/version.old");
313 TFT_print("updated\r\n", LASTX, LASTY); 313 TFT_print((char *)"updated\r\n", LASTX, LASTY);
314 return; 314 return;
315 315
316 spiffs_error: 316 spiffs_error:
317 _fg = TFT_RED; 317 _fg = TFT_RED;
318 TFT_print("error\r\n", LASTX, LASTY); 318 TFT_print((char *)"error\r\n", LASTX, LASTY);
319 319
320 } 320 }
321 321
322 322
323 323
328 { 328 {
329 switch (Main_Screen) { 329 switch (Main_Screen) {
330 case MAIN_TOOLS_UPDATES: 330 case MAIN_TOOLS_UPDATES:
331 _bg = TFT_BLACK; 331 _bg = TFT_BLACK;
332 TFT_fillScreen(_bg); 332 TFT_fillScreen(_bg);
333 TopMessage("Update"); 333 TopMessage((char *)"Update");
334 break; 334 break;
335 335
336 default: break; 336 default: break;
337 } 337 }
338 } 338 }

mercurial