mirror of
https://github.com/ok-home/ota_ws_update.git
synced 2025-11-13 22:03:27 +03:00
ota tested
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
.devcontainer/
|
.devcontainer/
|
||||||
build/
|
build/
|
||||||
|
example_ota_ws/sdkconfig
|
||||||
|
example_ota_ws/sdkconfig.old
|
||||||
|
|||||||
9
example_ota_ws/dependencies.lock
Normal file
9
example_ota_ws/dependencies.lock
Normal 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
|
||||||
11
example_ota_ws/example_ota_ws.code-workspace
Normal file
11
example_ota_ws/example_ota_ws.code-workspace
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": ".."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ota_ws_private.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,8 +115,6 @@
|
|||||||
|
|
||||||
reader.onload = function () {
|
reader.onload = function () {
|
||||||
otaData = new Uint8Array(reader.result);
|
otaData = new Uint8Array(reader.result);
|
||||||
// console.log(reader.result);
|
|
||||||
// console.log(otaData.length);
|
|
||||||
document.getElementById("otaStartVisible").style.display = "block";
|
document.getElementById("otaStartVisible").style.display = "block";
|
||||||
document.getElementById("otaProgressVisible").style.display = "none";
|
document.getElementById("otaProgressVisible").style.display = "none";
|
||||||
document.getElementById("otaReStartVisible").style.display = "none";
|
document.getElementById("otaReStartVisible").style.display = "none";
|
||||||
@@ -132,18 +130,14 @@
|
|||||||
if (otaData.length > 0 && otaStarted == 0) {
|
if (otaData.length > 0 && otaStarted == 0) {
|
||||||
|
|
||||||
socket.send(JSON.stringify({ name: "otaSize", value: otaData.length }));
|
socket.send(JSON.stringify({ name: "otaSize", value: otaData.length }));
|
||||||
//console.log(JSON.stringify({ name: "otaSize", value: otaData.length }));
|
|
||||||
|
|
||||||
otaStarted = 1;
|
otaStarted = 1;
|
||||||
this.innerHTML = "Click to Cancel";
|
this.innerHTML = "Click to Cancel";
|
||||||
document.getElementById("otaFileSelect").disabled = true;
|
document.getElementById("otaFileSelect").disabled = true;
|
||||||
document.getElementById("otaProgressVisible").style.display = "block";
|
document.getElementById("otaProgressVisible").style.display = "block";
|
||||||
document.getElementById("otaPogress").max = otaData.length;
|
document.getElementById("otaPogress").max = otaData.length;
|
||||||
//tstReceive();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
otaStarted = 0;
|
otaStarted = 0;
|
||||||
//receiveWsData(JSON.stringify({ name: "otaCancel", value: "Cancel" }));
|
|
||||||
socket.send(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) {
|
document.getElementById("otaReStart").addEventListener("click", function (e) {
|
||||||
socket.send(JSON.stringify({ name: "otaRestartEsp", value: "restart" }));
|
socket.send(JSON.stringify({ name: "otaRestartEsp", value: "restart" }));
|
||||||
//console.log(JSON.stringify({ name: "otaRestartEsp", value: "restart" }));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/* // debug -> test sample
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
@@ -171,7 +164,6 @@
|
|||||||
}
|
}
|
||||||
otaStartsegment += otaSetChunkSize;
|
otaStartsegment += otaSetChunkSize;
|
||||||
}
|
}
|
||||||
//console.log(otaStartsegment + " " + otaSetChunkSize + " " + otaData.length + " " + (otaData.length - otaStartsegment));
|
|
||||||
if (otaStarted == 1) {
|
if (otaStarted == 1) {
|
||||||
receiveWsData(JSON.stringify({ name: "otaGetChunk", value: otaStartsegment }));
|
receiveWsData(JSON.stringify({ name: "otaGetChunk", value: otaStartsegment }));
|
||||||
receiveWsData(JSON.stringify({ name: "otaEnd", value: "OK" }));
|
receiveWsData(JSON.stringify({ name: "otaEnd", value: "OK" }));
|
||||||
@@ -181,7 +173,6 @@
|
|||||||
function receiveWsData(data) {
|
function receiveWsData(data) {
|
||||||
try {
|
try {
|
||||||
let obj = JSON.parse(data);
|
let obj = JSON.parse(data);
|
||||||
//console.log(data);
|
|
||||||
switch (obj.name) {
|
switch (obj.name) {
|
||||||
case "otaSetChunkSize":
|
case "otaSetChunkSize":
|
||||||
otaSetChunkSize = obj.value;
|
otaSetChunkSize = obj.value;
|
||||||
@@ -190,7 +181,6 @@
|
|||||||
let otaDataSend = otaData.subarray(obj.value, obj.value + otaSetChunkSize);
|
let otaDataSend = otaData.subarray(obj.value, obj.value + otaSetChunkSize);
|
||||||
document.getElementById("otaPogress").value = obj.value;
|
document.getElementById("otaPogress").value = obj.value;
|
||||||
document.getElementById("otaStartCancel").innerHTML = "Ota download. Size = " + otaData.length + " Segment = " + obj.value + " Click to Cancel";
|
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);
|
socket.send(otaDataSend);
|
||||||
break;
|
break;
|
||||||
case "otaEnd":
|
case "otaEnd":
|
||||||
@@ -224,7 +214,7 @@
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
console.log(data + " catch");
|
console.log(data + "Error msg");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -234,14 +224,12 @@
|
|||||||
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "false" }));
|
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "false" }));
|
||||||
document.getElementById("rollback").style.display = "none";
|
document.getElementById("rollback").style.display = "none";
|
||||||
document.getElementById("update").style.display = "block";
|
document.getElementById("update").style.display = "block";
|
||||||
console.log(JSON.stringify({ name: "otaProcessRollback", value: "false" }));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("otaRollback").addEventListener("click", function (e) {
|
document.getElementById("otaRollback").addEventListener("click", function (e) {
|
||||||
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "true" }));
|
socket.send(JSON.stringify({ name: "otaProcessRollback", value: "true" }));
|
||||||
document.getElementById("rollback").style.display = "none";
|
document.getElementById("rollback").style.display = "none";
|
||||||
document.getElementById("update").style.display = "block";
|
document.getElementById("update").style.display = "block";
|
||||||
console.log(JSON.stringify({ name: "otaProcessRollback", value: "true" }));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -256,14 +244,15 @@
|
|||||||
|
|
||||||
<script> // события WS
|
<script> // события WS
|
||||||
socket.onopen = function () {
|
socket.onopen = function () {
|
||||||
console.log("connect");
|
console.log("connect ws");
|
||||||
};
|
};
|
||||||
socket.onclose = function (event) {
|
socket.onclose = function (event) {
|
||||||
console.log("close");
|
document.location.reload();
|
||||||
|
console.log("close ws");
|
||||||
};
|
};
|
||||||
socket.onerror = function () {
|
socket.onerror = function () {
|
||||||
document.location.reload();
|
document.location.reload();
|
||||||
console.log("error");
|
console.log("error ws");
|
||||||
};
|
};
|
||||||
socket.onmessage = function (event) {
|
socket.onmessage = function (event) {
|
||||||
receiveWsData(event.data);
|
receiveWsData(event.data);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
#include "esp_image_format.h"
|
#include "esp_image_format.h"
|
||||||
|
|
||||||
#include "ota_ws_private.h"
|
#include "ota_ws_update_private.h"
|
||||||
|
|
||||||
static const char *TAG = "ota_ws_esp";
|
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 *configured = esp_ota_get_boot_partition();
|
||||||
const esp_partition_t *running = esp_ota_get_running_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)
|
if (configured != running)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
#include "ota_ws_private.h"
|
#include "ota_ws_update_private.h"
|
||||||
#include "ota_ws.h"
|
#include "ota_ws_update.h"
|
||||||
|
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
@@ -234,11 +234,11 @@ _recv_ret:
|
|||||||
// send http initial page and js code
|
// send http initial page and js code
|
||||||
static esp_err_t ota_get_handler(httpd_req_t *req)
|
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_update_html_start[] asm("_binary_ota_ws_update_html_start");
|
||||||
extern const unsigned char ota_ws_html_end[] asm("_binary_ota_ws_html_end");
|
extern const unsigned char ota_ws_update_html_end[] asm("_binary_ota_ws_update_html_end");
|
||||||
const size_t ota_ws_html_size = (ota_ws_html_end - ota_ws_html_start);
|
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);
|
httpd_resp_sendstr_chunk(req, NULL);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user