mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 21:48:25 +08:00
后台增加重启功能。修复已知问题
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <httpd.h>
|
||||
#include <http_parse.h>
|
||||
#include <http-strings.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "mico.h"
|
||||
#include "httpd_priv.h"
|
||||
@@ -286,6 +287,19 @@ exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetRebootSystem(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
char c[1] = { 0 };
|
||||
sprintf(c, "reboot now !%s", "reboot");
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetMqttConfig(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
@@ -306,6 +320,7 @@ exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int HttpSetMqttReportFreq(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
@@ -453,6 +468,7 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{ "/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL },
|
||||
{ "/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL },
|
||||
{ "/mqtt/config", HTTPD_HDR_DEFORT, 0, NULL, HttpSetMqttConfig, NULL, NULL },
|
||||
{ "/reboot", HTTPD_HDR_DEFORT, 0, NULL, HttpSetRebootSystem, NULL, NULL },
|
||||
{ "/mqtt/report/freq", HTTPD_HDR_DEFORT, 0, HttpGetMqttReportFreq, HttpSetMqttReportFreq, NULL, NULL },
|
||||
{ "/log", HTTPD_HDR_DEFORT, 0, HttpGetLog, NULL, NULL, NULL },
|
||||
{ "/task", HTTPD_HDR_DEFORT, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetTasks, HttpAddTask, NULL, HttpDelTask },
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
<li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>
|
||||
<li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>
|
||||
</ul>
|
||||
<div>
|
||||
<a href="javascript:reboot();" class="mdl-button mdl-js-button mdl-js-ripple-effect">
|
||||
重启
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="demo-drawer mdl-layout__drawer mdl-color--blue-grey-900 mdl-color-text--blue-grey-50">
|
||||
@@ -974,6 +979,20 @@ function GetReportFreq() {
|
||||
}
|
||||
GetReportFreq();
|
||||
|
||||
function reboot(){
|
||||
var r=confirm("确定要重启吗?");
|
||||
if (r==true)
|
||||
{
|
||||
setRebootSystem();
|
||||
}
|
||||
}
|
||||
|
||||
function setRebootSystem() {
|
||||
HttpPost("/reboot", function (re) {
|
||||
ShowToast("已重启");
|
||||
}, "000");
|
||||
}
|
||||
|
||||
function setReportFreq(seconds) {
|
||||
if(!seconds||seconds==0){
|
||||
seconds=1;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -72,18 +72,21 @@ void schedule_p_count_task(mico_thread_arg_t arg){
|
||||
struct tm next_run;
|
||||
time(&now);
|
||||
struct tm *current_time = localtime(&now);
|
||||
tc1_log("local time %s", asctime(current_time));
|
||||
// 计算下次执行时间,目标是 0 点 0 分
|
||||
next_run = *current_time;
|
||||
next_run.tm_hour = 0;
|
||||
next_run.tm_min = 0;
|
||||
next_run.tm_sec = 0;
|
||||
next_run.tm_mday += 1; // 第二天
|
||||
|
||||
tc1_log("next time %s", asctime(&next_run));
|
||||
// 计算时间间隔(秒数)
|
||||
time_t next_time = mktime(&next_run);
|
||||
now = mktime(current_time);
|
||||
double seconds_until_next_run = difftime(next_time, now);
|
||||
if (seconds_until_next_run > 0) {
|
||||
// 休眠直到目标时间
|
||||
tc1_log("record p_count after %f seconds", seconds_until_next_run);
|
||||
mico_rtos_thread_sleep(seconds_until_next_run);
|
||||
}else{
|
||||
mico_rtos_thread_sleep(1);
|
||||
|
||||
@@ -390,6 +390,7 @@ void ProcessHaCmd(char* cmd)
|
||||
mqtt_log("set socket[%d] on[%d]", i, on);
|
||||
UserRelaySet(i, on);
|
||||
UserMqttSendSocketState(i);
|
||||
mico_system_context_update(sys_config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user