Skip to content

Commit 7e31995

Browse files
committed
Fixed minor issue I used for testing when no device is connected
Refactored OTA view for better readability Added a delay before returning from flashing to give MCU time for rebooting Old and new Version is now shown after flashing
1 parent 42dc133 commit 7e31995

File tree

2 files changed

+80
-26
lines changed

2 files changed

+80
-26
lines changed

main/web_server.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ static esp_err_t ota_start_handler(httpd_req_t *req)
255255
httpd_resp_set_type(req, "text/plain");
256256

257257
int ret = ts_serial_ota(flash_size->valueint, page_size->valueint);
258+
259+
/* Give it time to reboot, otherwise subsequent request could fail */
260+
vTaskDelay(pdMS_TO_TICKS(1000));
261+
258262
if (ret != ESP_FAIL) {
259263
httpd_resp_sendstr(req, "OTA successful.");
260264
}
@@ -275,7 +279,7 @@ esp_err_t ota_upload_handler(httpd_req_t *req)
275279

276280
unsigned int bytes_received = 0;
277281
unsigned int bytes_written = 0;
278-
int buffer_size = 8*1024;
282+
int buffer_size = 8 * 1024;
279283
char * buf = malloc(buffer_size);
280284
FILE *fd = fopen("/stm_ota/firmware.bin", "w");
281285
if (fd == NULL) {

webapp/src/views/Ota.vue

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
</div>
1313
</v-col>
1414
</v-row>
15+
<v-row justify="center" dense>
16+
<v-col cols=10>
17+
<div class="ma-auto">
18+
Current Version: {{ fw_version_old }}
19+
</div>
20+
</v-col>
21+
</v-row>
1522
<v-row justify="center">
1623
<v-col cols=10 >
1724
<v-file-input
@@ -78,9 +85,14 @@ export default {
7885
file: null,
7986
status: null,
8087
alert: false,
81-
success: false
88+
success: false,
89+
fw_version_old: null,
90+
fw_version_new: null
8291
}
8392
},
93+
mounted() {
94+
this.fetch_data("old")
95+
},
8496
computed: {
8597
flash_disabled() {
8698
return this.disable_flash_btn;
@@ -92,13 +104,13 @@ export default {
92104
methods: {
93105
upload: function() {
94106
this.uploading = !this.uploading;
95-
this.disable_upload_btn = true
107+
this.disable("upload")
96108
var reader = new FileReader();
97109
if(!this.file) {
98110
this.status = "No file selected"
99-
this.alert = true
111+
this.show_alert()
100112
this.uploading = !this.uploading;
101-
this.disable_upload_btn = false
113+
this.enable("upload")
102114
return;
103115
}
104116
reader.readAsArrayBuffer(this.file);
@@ -107,44 +119,82 @@ export default {
107119
.post('api/v1/ota/upload', reader.result)
108120
.then(res => {
109121
this.status = "Image upload successfull";
110-
this.disable_flash_btn = false;
111-
this.disable_upload_btn = false
122+
this.enable("flash");
123+
this.enable("upload")
112124
this.uploading = !this.uploading;
113-
this.alert=false
114-
this.success=true
125+
this.show_success()
115126
})
116127
.catch(error => {
117128
this.status = "Could not upload image - Statuscode: " + error.response.status
118129
this.uploading = !this.uploading;
119-
this.disable_upload_btn = false
120-
this.disable_flash_btn = true
121-
this.alert=true
122-
this.success=false
130+
this.enable("upload")
131+
this.disable("flash")
132+
this.show_alert()
123133
});
124134
}},
125135
flash: function() {
126136
this.flashing = !this.flashing;
127-
this.disable_flash_btn = true
137+
this.disable("flash")
128138
let id = this.$store.state.active_device_id
129139
this.$ajax
130-
.get('api/v1/ota/' + 'kk8a4zv')
140+
.get('api/v1/ota/' + id)
131141
.then(res => {
132-
this.status = "Image flashed successfully";
133-
this.disable_flash_btn = false;
134-
this.disable_upload_btn = false
135-
this.flashing = !this.uploading;
136-
this.alert=false
137-
this.success=true
142+
this.disable("flash");
143+
this.enable("upload")
144+
this.flashing = !this.flashing;
145+
this.fetch_data("new")
138146
})
139147
.catch(error => {
140148
this.status = "Could not be flashed: " + error.response.status + "-" + error.response.data
141149
this.flashing = !this.flashing;
142-
this.disable_flash_btn = false
143-
this.disable_upload_btn = false
144-
this.success=false
145-
this.alert=true
150+
this.enable("flash")
151+
this.enable("upload")
152+
this.show_alert()
146153
});
154+
},
155+
fetch_data: function(target) {
156+
let id = this.$store.state.active_device_id
157+
this.$ajax
158+
.get("api/v1/ts/" + id + "/info")
159+
.then(res => {
160+
if (target == "old") {
161+
this.fw_version_old = res.data.FirmwareVersion;
162+
} else if (target == "new") {
163+
this.fw_version_new = res.data.FirmwareVersion;
164+
this.status = "Updated successfully from " + this.fw_version_old + " --> " + this.fw_version_new;
165+
this.show_success()
166+
}
167+
return
168+
})
169+
.catch(error => {
170+
this.status = "Device Information could not be fetched: " + error.response.status + "-" + error.response.data
171+
this.show_alert()
172+
return
173+
});
174+
},
175+
enable: function(btn) {
176+
if(btn == "flash") {
177+
this.disable_flash_btn = false
178+
} else if (btn == "upload") {
179+
this.disable_upload_btn = false
180+
}
181+
},
182+
disable: function(btn) {
183+
if(btn == "flash") {
184+
this.disable_flash_btn = true
185+
} else if (btn == "upload") {
186+
this.disable_upload_btn = true
187+
}
188+
},
189+
show_alert: function() {
190+
this.success = false
191+
this.alert = true
192+
},
193+
show_success: function() {
194+
this.alert = false
195+
this.success = true
147196
}
197+
148198
}
149199
}
150-
</script>
200+
</script>

0 commit comments

Comments
 (0)