diff --git a/README.md b/README.md index aab1fc3..a45166e 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,9 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2 - [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作) - [x] 后台和ha mqtt增加总开关控制 - [x] 后台可以自定义6个插座的名称,名称将会自动同步到ha mqtt -- [x] 修复了原代码中电源按钮长按 重新配网和恢复出厂的逻辑错误 -- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,上电之前就按下的话会开启配网热点(原有逻辑) +- [x] 修复了原代码中电源按钮长按 (现在是5秒)重新配网和(10秒)恢复出厂的逻辑错误 +- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,上电时同时按住按钮的话会开启配网热点(防止开了童锁,wifi又嗝屁,导致插座功能暴毙的救命逻辑) +- [x] 后台可自定义设备名称,此名称将会同至ha mqtt作为mqtt中插座名称的前缀 # 编译固件 diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index 8417d18..3159daa 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,childLockEnabled); + user_config->power_led_enabled, 0L,socket_names,childLockEnabled,sys_config->micoSystemConfig.name); OSStatus err = kNoErr; send_http(tc1_status, strlen(tc1_status), exit, &err); @@ -195,7 +195,7 @@ static int HttpSetSocketStatus(httpd_request_t *req) { static int HttpSetSocketName(httpd_request_t *req) { OSStatus err = kNoErr; - int buf_size = 512; + int buf_size = 70; char *buf = malloc(buf_size); err = httpd_get_data(req, buf, buf_size); @@ -213,6 +213,26 @@ static int HttpSetSocketName(httpd_request_t *req) { return err; } +static int HttpSetDeviceName(httpd_request_t *req) { + OSStatus err = kNoErr; + + int buf_size = 70; + char *buf = malloc(buf_size); + + err = httpd_get_data(req, buf, buf_size); + require_noerr(err, exit); + char name[64]; + sscanf(buf, "%s",name); + strcpy(sys_config->micoSystemConfig.name,name); + mico_system_context_update(sys_config); + registerMqttEvents(); + send_http("OK", 2, exit, &err); + + exit: + if (buf) free(buf); + return err; +} + static int HttpSetChildLock(httpd_request_t *req) { OSStatus err = kNoErr; @@ -264,7 +284,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,childLockEnabled); + 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,sys_config->micoSystemConfig.name); send_http(power_info_json, strlen(power_info_json), exit, &err); if (socket_names) free(socket_names); exit: @@ -568,6 +588,7 @@ const struct httpd_wsgi_call g_app_handlers[] = { {"/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}, + {"/deviceName", HTTPD_HDR_DEFORT, 0, NULL, HttpSetDeviceName, 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 9ac38cb..20b9630 100644 --- a/TC1/http_server/app_httpd.h +++ b/TC1/http_server/app_httpd.h @@ -66,10 +66,11 @@ 'ledEnabled':%d,\ 'up_time':%ld,\ 'socketNames':'%s',\ - 'child_lock_enabled':%d\ + 'child_lock_enabled':%d,\ + 'deviceName':'%s'\ }" -#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':%d,'p_count_2_days_ago':%d,'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':%d,'p_count_2_days_ago':%d,'child_lock_enabled':%d,'deviceName':'%s'}" int AppHttpdStart(void); diff --git a/TC1/http_server/web/index.html b/TC1/http_server/web/index.html index caa0042..53e9114 100644 --- a/TC1/http_server/web/index.html +++ b/TC1/http_server/web/index.html @@ -25,6 +25,13 @@