diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index e6f5462..32453e2 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -39,12 +39,14 @@ #include "app_httpd.h" #include "user_gpio.h" #include "user_wifi.h" +#include "user_power.h" #include "main.h" #include "web_data.c" static bool is_http_init; static bool is_handlers_registered; struct httpd_wsgi_call g_app_handlers[]; +char power_info_json[1130] = { 0 }; static int HttpGetIndexPage(httpd_request_t *req) { @@ -95,6 +97,16 @@ exit: return err; } +static int HttpGetPowerInfo(httpd_request_t *req) +{ + char* powers = GetPowerRecord(); + sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, powers); + OSStatus err = kNoErr; + send_http(power_info_json, strlen(power_info_json), exit, &err); +exit: + return err; +} + static int HttpGetWifiConfig(httpd_request_t *req) { OSStatus err = kNoErr; @@ -160,6 +172,7 @@ struct httpd_wsgi_call g_app_handlers[] = { {"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL}, {"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL}, {"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL}, + {"/power", HTTPD_HDR_DEFORT, 0, HttpGetPowerInfo, NULL, NULL, NULL}, {"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL}, {"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL}, }; diff --git a/TC1/http_server/app_httpd.h b/TC1/http_server/app_httpd.h index 5b9c225..b45494f 100644 --- a/TC1/http_server/app_httpd.h +++ b/TC1/http_server/app_httpd.h @@ -56,6 +56,8 @@ 'gateway':'%s'\ }" +#define POWER_INFO_JSON "{'idx':%d, 'powers:[%s]'}" + int AppHttpdStart(void); int AppHttpdStop(); diff --git a/TC1/http_server/index.html b/TC1/http_server/index.html index e101fab..045ec4e 100644 --- a/TC1/http_server/index.html +++ b/TC1/http_server/index.html @@ -22,6 +22,8 @@ #power_div{margin-top:10px;border-left:1px solid #000;border-bottom:1px solid #000;} #power_line{height:100px;position:relative;overflow:scroll;margin-top:-100px;} .power_pre{position:absolute;bottom:0;float:left;height:76px;width:0;border-left:1px solid #000;border-right:1px solid #000;} + .power_by{text-align:center;} + .power_by a{text-decoration:none;} @@ -175,6 +177,8 @@ +

power by github/zTC1

+