mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 13:08:13 +08:00
显示OTA进度
This commit is contained in:
@@ -297,6 +297,16 @@ exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int Otastatus(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
char buf[16] = { 0 };
|
||||
sprintf(buf, "%.2f", ota_progress);
|
||||
send_http(buf, strlen(buf), exit, &err);
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int OtaStart(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
@@ -321,7 +331,7 @@ struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{ "/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL },
|
||||
{ "/log", HTTPD_HDR_DEFORT, 0, HttpGetLog, NULL, NULL, NULL },
|
||||
{ "/task", HTTPD_HDR_DEFORT, 0, HttpGetTasks, HttpAddTask, NULL, HttpDelTask },
|
||||
{ "/ota", HTTPD_HDR_DEFORT, 0, NULL, OtaStart, NULL, NULL },
|
||||
{ "/ota", HTTPD_HDR_DEFORT, 0, Otastatus, OtaStart, NULL, NULL },
|
||||
};
|
||||
|
||||
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
<br>
|
||||
<button class="submit_bt" onclick="OtaStart()">Update</button>
|
||||
<span class="status_sp success">OK</span>
|
||||
<span class="info" id="ota_status"></span>
|
||||
</fieldset>
|
||||
|
||||
<p class="power_by">power by <a id="end" href="https://github.com/zogodo/zTC1" target="_blank">github/zTC1</a></p>
|
||||
@@ -305,6 +306,8 @@ var uptime = document.getElementById("uptime");
|
||||
var sys_log = document.getElementById("sys_log");
|
||||
var log_div = document.getElementsByClassName("log_div")[0];
|
||||
|
||||
var ota_status = document.getElementById("ota_status");
|
||||
|
||||
var mode = -1;
|
||||
var ap_name = "";
|
||||
var ap_pswd = "";
|
||||
@@ -568,6 +571,14 @@ function OtaStart() {
|
||||
SetIng(4);
|
||||
HttpPost("/ota", function (re) {
|
||||
SetOK(4);
|
||||
OtaStatus();
|
||||
}, ato_url);
|
||||
}
|
||||
|
||||
function OtaStatus() {
|
||||
HttpGet("/ota", function (re) {
|
||||
ota_status.innerHTML = " ota progress: " + re + "%";
|
||||
window.setTimeout(OtaStatus, 1000);
|
||||
}, ato_url);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,17 +8,21 @@
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
#include "mqtt_server/user_function.h"
|
||||
|
||||
float ota_progress = 0;
|
||||
|
||||
static void ota_server_status_handler(OTA_STATE_E state, float progress)
|
||||
{
|
||||
char str[64] = { 0 };
|
||||
switch (state)
|
||||
{
|
||||
case OTA_LOADING:
|
||||
ota_progress = progress;
|
||||
os_log("ota server is loading, progress %.2f%%", progress);
|
||||
if (((int) progress)%10 == 1)
|
||||
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":%d}", strMac,((int) progress));
|
||||
break;
|
||||
case OTA_SUCCE:
|
||||
ota_progress = 100;
|
||||
os_log("ota server daemons success");
|
||||
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":100}", strMac);
|
||||
break;
|
||||
@@ -37,6 +41,7 @@ static void ota_server_status_handler(OTA_STATE_E state, float progress)
|
||||
|
||||
void user_ota_start(char *url, char *md5)
|
||||
{
|
||||
ota_progress = 0;
|
||||
os_log("ready to ota:%s",url);
|
||||
ota_server_start(url, md5, ota_server_status_handler);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __USER_OTA_H_
|
||||
#define __USER_OTA_H_
|
||||
|
||||
extern float ota_progress;
|
||||
|
||||
void user_ota_start(char *url, char *md5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user