From 5f81f2ca715fda2e9159f9001cd5700ce7bcb26d Mon Sep 17 00:00:00 2001 From: nhkefus Date: Wed, 19 Mar 2025 14:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=AB=A5=E9=94=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/http_server/app_httpd.c | 26 ++++++++++++-- TC1/http_server/app_httpd.h | 5 +-- TC1/http_server/web/index.html | 52 +++++++++++++++++++--------- TC1/main.c | 1 + TC1/main.h | 1 + TC1/mqtt_server/user_mqtt_client.c | 54 ++++++++++++++++++++++++++++++ TC1/mqtt_server/user_mqtt_client.h | 4 +++ TC1/user_gpio.c | 2 ++ 8 files changed, 126 insertions(+), 19 deletions(-) diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index 9641d5b..23ca149 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -163,7 +163,7 @@ static int HttpGetTc1Status(httpd_request_t *req) { user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT, MQTT_SERVER_USR, MQTT_SERVER_PWD, VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, user_config->mqtt_report_freq, - user_config->power_led_enabled, 0L,socket_names); + user_config->power_led_enabled, 0L,socket_names,childLockEnabled); OSStatus err = kNoErr; send_http(tc1_status, strlen(tc1_status), exit, &err); @@ -213,6 +213,27 @@ static int HttpSetSocketName(httpd_request_t *req) { return err; } +static int HttpSetChildLock(httpd_request_t *req) { + OSStatus err = kNoErr; + + int buf_size = 32; + char *buf = malloc(buf_size); + + err = httpd_get_data(req, buf, buf_size); + require_noerr(err, exit); + int enableLock; + sscanf(buf, "%d",&enableLock); + user_config->user[0] = enableLock; + childLockEnabled = enableLock; + mico_system_context_update(sys_config); + UserMqttSendChildLockState(); + send_http("OK", 2, exit, &err); + + exit: + if (buf) free(buf); + return err; +} + static int HttpGetPowerInfo(httpd_request_t *req) { OSStatus err = kNoErr; char buf[16]; @@ -243,7 +264,7 @@ static int HttpGetPowerInfo(httpd_request_t *req) { user_config->socket_names[4], user_config->socket_names[5]); sprintf(power_info_json, POWER_INFO_JSON, sockets, power_record.idx, PW_NUM, p_count, powers, - up_time,user_config->power_led_enabled,RelayOut()?1:0,socket_names,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago); + up_time,user_config->power_led_enabled,RelayOut()?1:0,socket_names,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago,childLockEnabled); send_http(power_info_json, strlen(power_info_json), exit, &err); if (socket_names) free(socket_names); exit: @@ -546,6 +567,7 @@ const struct httpd_wsgi_call g_app_handlers[] = { {"/led", HTTPD_HDR_DEFORT, 0, LedStatus, LedSetEnabled, NULL, NULL}, {"/socketAll", HTTPD_HDR_DEFORT, 0, NULL, TotalSocketSetEnabled, NULL, NULL}, {"/socketNames", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketName, NULL, NULL}, + {"/childLock", HTTPD_HDR_DEFORT, 0, NULL, HttpSetChildLock, NULL, NULL}, }; static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call); diff --git a/TC1/http_server/app_httpd.h b/TC1/http_server/app_httpd.h index 3e2c367..91fe06a 100644 --- a/TC1/http_server/app_httpd.h +++ b/TC1/http_server/app_httpd.h @@ -65,10 +65,11 @@ 'reportFreq':'%d',\ 'ledEnabled':%d,\ 'up_time':%ld,\ - 'socketNames':'%s'\ + 'socketNames':'%s',\ + 'child_lock_enabled':%d\ }" -#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%ld,'p_count_2_days_ago':%ld}" +#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%ld,'p_count_2_days_ago':%ld,'child_lock_enabled':%d}" int AppHttpdStart(void); diff --git a/TC1/http_server/web/index.html b/TC1/http_server/web/index.html index 68ae7a9..8182c60 100644 --- a/TC1/http_server/web/index.html +++ b/TC1/http_server/web/index.html @@ -122,6 +122,18 @@ -->