35 esp_ota_handle_t update_handle = 0; |
35 esp_ota_handle_t update_handle = 0; |
36 int timeout = 600; |
36 int timeout = 600; |
37 |
37 |
38 ESP_LOGI(TAG, "Update begin"); |
38 ESP_LOGI(TAG, "Update begin"); |
39 update_running = 1; |
39 update_running = 1; |
40 screen_updating("Stop tests", NULL); |
40 screen_updating("Stop meten", NULL); |
41 |
41 |
42 for (;;) { |
42 for (;;) { |
43 vTaskDelay(100 / portTICK_PERIOD_MS); |
43 vTaskDelay(100 / portTICK_PERIOD_MS); |
44 if (Main_Loop1 == ML1_DONE) |
44 if (Main_Loop1 == ML1_DONE) |
45 break; |
45 break; |
48 else { |
48 else { |
49 ESP_LOGE(TAG, "Timout request stop"); |
49 ESP_LOGE(TAG, "Timout request stop"); |
50 goto updateerr; |
50 goto updateerr; |
51 } |
51 } |
52 } |
52 } |
53 screen_updating("Tests stopped", NULL); |
53 |
54 |
54 screen_updating("Stop meten", "Start WiFi"); |
55 screen_updating("Stop tests", "Start WiFi"); |
|
56 requestWiFi_user(true); |
55 requestWiFi_user(true); |
57 timeout = 600; |
56 timeout = 600; |
58 for (;;) { |
57 for (;;) { |
59 vTaskDelay(100 / portTICK_PERIOD_MS); |
58 vTaskDelay(100 / portTICK_PERIOD_MS); |
60 if (ready_WiFi()) |
59 if (ready_WiFi()) |
65 ESP_LOGE(TAG, "Timout request WiFi"); |
64 ESP_LOGE(TAG, "Timout request WiFi"); |
66 goto updateerr; |
65 goto updateerr; |
67 } |
66 } |
68 } |
67 } |
69 ESP_LOGI(TAG, "System is ready for update"); |
68 ESP_LOGI(TAG, "System is ready for update"); |
70 screen_updating("Prepare update", NULL); |
69 screen_updating("Verbonden", NULL); |
71 |
70 |
72 const esp_partition_t *running = esp_ota_get_running_partition(); |
71 const esp_partition_t *running = esp_ota_get_running_partition(); |
73 |
72 |
74 /* |
73 /* |
75 * Don't use https because it costs more then 100K memory. |
74 * Don't use https because it costs more then 100K memory. |
152 goto updateok; |
151 goto updateok; |
153 } |
152 } |
154 } |
153 } |
155 |
154 |
156 if (memcmp(new_app_info.app_elf_sha256, running_app_info.app_elf_sha256, 32) == 0) { |
155 if (memcmp(new_app_info.app_elf_sha256, running_app_info.app_elf_sha256, 32) == 0) { |
157 screen_updating("No new update", NULL); |
156 screen_updating("Geen nieuwe versie", NULL); |
158 ESP_LOGI(TAG, "Current running version is the same as a new."); |
157 ESP_LOGI(TAG, "Current running version is the same as a new."); |
159 http_cleanup(client); |
158 http_cleanup(client); |
160 goto updateok; |
159 goto updateok; |
161 } |
160 } |
162 |
161 |
209 ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); |
208 ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)!", esp_err_to_name(err)); |
210 goto updateerr; |
209 goto updateerr; |
211 } |
210 } |
212 |
211 |
213 ESP_LOGI(TAG, "Prepare to restart system!"); |
212 ESP_LOGI(TAG, "Prepare to restart system!"); |
214 screen_updating("Reboot...", "...Reboot"); |
213 screen_updating("Herstar ...", "... Herstart"); |
215 vTaskDelay(1000 / portTICK_PERIOD_MS); |
214 vTaskDelay(1000 / portTICK_PERIOD_MS); |
216 update_running = 0; |
215 update_running = 0; |
217 esp_restart(); |
216 esp_restart(); |
218 return; |
217 return; |
219 |
218 |
220 updateerr: |
219 updateerr: |
221 screen_updating("** ERROR **", "Update failed"); |
220 screen_updating("** FOUT **", "Update mislukt"); |
222 |
221 |
223 updateok: |
222 updateok: |
224 update_running = 0; |
223 update_running = 0; |
225 requestWiFi_user(false); |
224 requestWiFi_user(false); |
226 vTaskDelay(3000 / portTICK_PERIOD_MS); |
225 vTaskDelay(3000 / portTICK_PERIOD_MS); |