ota tested

This commit is contained in:
ok-home
2023-09-26 19:48:52 +07:00
parent d366ee19a2
commit 2f95d3e60a
7 changed files with 47 additions and 33 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.vscode/
.devcontainer/
build/
example_ota_ws/sdkconfig
example_ota_ws/sdkconfig.old

View File

@@ -0,0 +1,9 @@
dependencies:
idf:
component_hash: null
source:
type: idf
version: 5.2.0
manifest_hash: 2ac596d0d5a708817329b21531cbf3574c7c8daaf36dca979b5dd32a78fc2857
target: esp32s3
version: 1.0.0

View File

@@ -0,0 +1,11 @@
{
"folders": [
{
"path": "."
},
{
"path": ".."
}
],
"settings": {}
}

View File

@@ -1,7 +1,5 @@
#pragma once
#include "ota_ws_private.h"
#ifdef __cplusplus
extern "C"
{

View File

@@ -115,8 +115,6 @@
reader.onload = function () {
otaData = new Uint8Array(reader.result);
// console.log(reader.result);
// console.log(otaData.length);
document.getElementById("otaStartVisible").style.display = "block";
document.getElementById("otaProgressVisible").style.display = "none";
document.getElementById("otaReStartVisible").style.display = "none";
@@ -132,18 +130,14 @@
if (otaData.length > 0 && otaStarted == 0) {
socket.send(JSON.stringify({ name: "otaSize", value: otaData.length }));
//console.log(JSON.stringify({ name: "otaSize", value: otaData.length }));
otaStarted = 1;
this.innerHTML = "Click to Cancel";
document.getElementById("otaFileSelect").disabled = true;
document.getElementById("otaProgressVisible").style.display = "block";
document.getElementById("otaPogress").max = otaData.length;
//tstReceive();
}
else {
otaStarted = 0;
//receiveWsData(JSON.stringify({ name: "otaCancel", value: "Cancel" }));
socket.send(JSON.stringify({ name: "otaCancel", value: "Cancel" }));
}
@@ -155,10 +149,9 @@
});
document.getElementById("otaReStart").addEventListener("click", function (e) {
socket.send(JSON.stringify({ name: "otaRestartEsp", value: "restart" }));
//console.log(JSON.stringify({ name: "otaRestartEsp", value: "restart" }));
});
/*
/* // debug -> test sample
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@@ -171,7 +164,6 @@
}
otaStartsegment += otaSetChunkSize;
}
//console.log(otaStartsegment + " " + otaSetChunkSize + " " + otaData.length + " " + (otaData.length - otaStartsegment));
if (otaStarted == 1) {
receiveWsData(JSON.stringify({ name: "otaGetChunk", value: otaStartsegment }));
receiveWsData(JSON.stringify({ name: "otaEnd", value: "OK" }));
@@ -181,7 +173,6 @@
function receiveWsData(data) {
try {
let obj = JSON.parse(data);
//console.log(data);
switch (obj.name) {
case "otaSetChunkSize":
otaSetChunkSize = obj.value;
@@ -190,7 +181,6 @@
let otaDataSend = otaData.subarray(obj.value, obj.value + otaSetChunkSize);
document.getElementById("otaPogress").value = obj.value;
document.getElementById("otaStartCancel").innerHTML = "Ota download. Size = " + otaData.length + " Segment = " + obj.value + " Click to Cancel";
//console.log("sock send " + obj.value + " " + otaDataSend.length);
socket.send(otaDataSend);
break;
case "otaEnd":
@@ -224,7 +214,7 @@
}
catch
{
console.log(data + " catch");
console.log(data + "Error msg");
}
};
</script>
@@ -234,14 +224,12 @@
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "false" }));
document.getElementById("rollback").style.display = "none";
document.getElementById("update").style.display = "block";
console.log(JSON.stringify({ name: "otaProcessRollback", value: "false" }));
});
document.getElementById("otaRollback").addEventListener("click", function (e) {
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "true" }));
document.getElementById("rollback").style.display = "none";
document.getElementById("update").style.display = "block";
console.log(JSON.stringify({ name: "otaProcessRollback", value: "true" }));
});
</script>
@@ -256,14 +244,15 @@
<script> // события WS
socket.onopen = function () {
console.log("connect");
console.log("connect ws");
};
socket.onclose = function (event) {
console.log("close");
document.location.reload();
console.log("close ws");
};
socket.onerror = function () {
document.location.reload();
console.log("error");
console.log("error ws");
};
socket.onmessage = function (event) {
receiveWsData(event.data);

View File

@@ -10,7 +10,7 @@
#include "esp_partition.h"
#include "esp_image_format.h"
#include "ota_ws_private.h"
#include "ota_ws_update_private.h"
static const char *TAG = "ota_ws_esp";
@@ -27,6 +27,11 @@ esp_err_t start_ota_ws(void)
const esp_partition_t *configured = esp_ota_get_boot_partition();
const esp_partition_t *running = esp_ota_get_running_partition();
if(configured==NULL || running == NULL)
{
ESP_LOGE(TAG,"OTA data not found");
return ESP_FAIL;
}
if (configured != running)
{

View File

@@ -5,8 +5,8 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "ota_ws_private.h"
#include "ota_ws.h"
#include "ota_ws_update_private.h"
#include "ota_ws_update.h"
#include "freertos/task.h"
#include "freertos/queue.h"
@@ -234,11 +234,11 @@ _recv_ret:
// send http initial page and js code
static esp_err_t ota_get_handler(httpd_req_t *req)
{
extern const unsigned char ota_ws_html_start[] asm("_binary_ota_ws_html_start");
extern const unsigned char ota_ws_html_end[] asm("_binary_ota_ws_html_end");
const size_t ota_ws_html_size = (ota_ws_html_end - ota_ws_html_start);
extern const unsigned char ota_ws_update_html_start[] asm("_binary_ota_ws_update_html_start");
extern const unsigned char ota_ws_update_html_end[] asm("_binary_ota_ws_update_html_end");
const size_t ota_ws_update_html_size = (ota_ws_update_html_end - ota_ws_update_html_start);
httpd_resp_send_chunk(req, (const char *)ota_ws_html_start, ota_ws_html_size);
httpd_resp_send_chunk(req, (const char *)ota_ws_update_html_start, ota_ws_update_html_size);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}