修复插座命名功能的一些问题

This commit is contained in:
Your Name
2025-03-18 23:43:17 +08:00
parent b36fce48f5
commit 4a20713693
6 changed files with 798 additions and 734 deletions

View File

@@ -169,6 +169,7 @@ static int HttpGetTc1Status(httpd_request_t *req) {
send_http(tc1_status, strlen(tc1_status), exit, &err);
exit:
if (socket_names) free(socket_names);
if (tc1_status) free(tc1_status);
return err;
}
@@ -199,14 +200,10 @@ static int HttpSetSocketName(httpd_request_t *req) {
err = httpd_get_data(req, buf, buf_size);
require_noerr(err, exit);
sscanf(buf, "%s,%s,%s,%s,%s,%s",
user_config->socket_names[0],
user_config->socket_names[1],
user_config->socket_names[2],
user_config->socket_names[3],
user_config->socket_names[4],
user_config->socket_names[5]);
int index;
char name[64];
sscanf(buf, "%d %s",&index,name);
strcpy(user_config->socket_names[index],name);
mico_system_context_update(sys_config);
registerMqttEvents();
send_http("OK", 2, exit, &err);
@@ -248,6 +245,7 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
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);
send_http(power_info_json, strlen(power_info_json), exit, &err);
if (socket_names) free(socket_names);
exit:
return err;
}
@@ -369,6 +367,7 @@ static int HttpGetMqttReportFreq(httpd_request_t *req) {
send_http(freq, strlen(freq), exit, &err);
exit:
if(freq) free(freq);
return err;
}
@@ -419,6 +418,7 @@ static int HttpAddTask(httpd_request_t *req) {
char *mess = (re == 4 && AddTask(task)) ? "OK" : "NO";
send_http(mess, strlen(mess), exit, &err);
if(mess) free(mess);
exit:
return err;
}
@@ -438,6 +438,7 @@ static int HttpDelTask(httpd_request_t *req) {
send_http(mess, strlen(mess), exit, &err);
exit:
if(time_str) free(time_str);
return err;
}
@@ -450,6 +451,7 @@ static int LedStatus(httpd_request_t *req) {
send_http(led, strlen(led), exit, &err);
exit:
if(led) free(led);
return err;
}

View File

@@ -65,10 +65,10 @@
'reportFreq':'%d',\
'ledEnabled':%d,\
'up_time':%ld,\
'socketNames':%s\
'socketNames':'%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}"
#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'}"
int AppHttpdStart(void);

View File

@@ -885,18 +885,19 @@
// 弹窗编辑
var newName = prompt("请输入新的插座名称", oldName);
if (newName && newName.trim() !== "") {
if(newName.trim().includes(" ")){
ShowToast("名称不能包含空格");
return;
}
if(newName.trim().length>16){
ShowToast("名称不能超过16个字");
return;
}
$lang.text(newName.trim());
// 可选:更新序号
$index.text("");
// 🔸 编辑完成后,获取所有名称并拼接
var allNames = [];
$(".mdl-list__item .lang").each(function () {
allNames.push('"' + $(this).text().trim() + '"');
});
var nameString = allNames.join(',');
HttpPost("/socketNames", function (re) {
}, nameString);});
}
}, index+' '+newName.trim());}
});
document.getElementById("list-switch-all").addEventListener("click", function() {

File diff suppressed because it is too large Load Diff

View File

@@ -503,7 +503,7 @@ void UserMqttHassAuto(char socket_id) {
socket_id--;
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = (char *) malloc(1024);
send_buf = (char *) malloc(600);
topic_buf = (char *) malloc(64);
if (send_buf != NULL && topic_buf != NULL) {
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/config", str_mac, socket_id);
@@ -533,7 +533,7 @@ void UserMqttHassAuto(char socket_id) {
void UserMqttHassAutoLed(void) {
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = (char *) malloc(1024);
send_buf = (char *) malloc(600);
topic_buf = (char *) malloc(64);
if (send_buf != NULL && topic_buf != NULL) {
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
@@ -561,7 +561,7 @@ void UserMqttHassAutoLed(void) {
void UserMqttHassAutoTotalSocket(void) {
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = (char *) malloc(1024);
send_buf = (char *) malloc(600);
topic_buf = (char *) malloc(64);
if (send_buf != NULL && topic_buf != NULL) {
sprintf(topic_buf, "homeassistant/switch/%s/total_socket/config", str_mac);
@@ -590,7 +590,7 @@ void UserMqttHassAutoTotalSocket(void) {
void UserMqttHassAutoPower(void) {
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = malloc(1024);
send_buf = malloc(600);
topic_buf = malloc(128);
if (send_buf != NULL && topic_buf != NULL) {
sprintf(topic_buf, "homeassistant/sensor/%s/power/config", str_mac);

View File

@@ -153,7 +153,7 @@ static void KeyTimeoutHandler(void* arg)
{
//any button pressed
key_time++;
if (key_time <= BUTTON_LONG_PRESS_TIME)
if (key_time > BUTTON_LONG_PRESS_TIME)
{
key_log("button long pressed:%d",key_time);