修复ota可能无法使用的问题

This commit is contained in:
Your Name
2025-04-12 16:03:34 +08:00
parent 34e1cabc53
commit 5623b632c7
6 changed files with 155 additions and 129 deletions

View File

@@ -77,6 +77,7 @@ void UserMqttTimerFunc(void *arg) {
UserMqttHassAutoLed();
UserMqttHassAutoTotalSocket();
UserMqttHassAutoChildLock();
UserMqttHassAutoRebootButton();
break;
case 1:
case 2:
@@ -422,6 +423,8 @@ void ProcessHaCmd(char *cmd) {
childLockEnabled = on;
UserMqttSendChildLockState();
mico_system_context_update(sys_config);
}else if (strcmp(cmd, "reboot") == 0) {
MicoSystemReboot(); // 立即重启设备
}
}
@@ -530,7 +533,7 @@ void UserMqttHassAuto(char socket_id) {
socket_id--;
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = (char *) malloc(800);
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);
@@ -542,6 +545,7 @@ void UserMqttHassAuto(char socket_id) {
"\"cmd_t\":\"device/ztc1/set\","
"\"pl_on\":\"set socket %s %d 1\","
"\"pl_off\":\"set socket %s %d 0\","
"\"device_class\":\"outlet\","
"\"device\":{"
"\"identifiers\":[\"tc1_%s\"],"
"\"name\":\"%s\","
@@ -558,6 +562,33 @@ void UserMqttHassAuto(char socket_id) {
free(topic_buf);
}
void UserMqttHassAutoRebootButton(void) {
char *send_buf = NULL;
char *topic_buf = NULL;
send_buf = (char *) malloc(600);
topic_buf = (char *) malloc(64);
if (send_buf != NULL && topic_buf != NULL) {
// 重启按钮配置
sprintf(topic_buf, "homeassistant/button/%s/reboot/config", str_mac);
sprintf(send_buf,
"{\"name\":\"重启设备\","
"\"uniq_id\":\"tc1_%s_reboot\","
"\"object_id\":\"tc1_%s_reboot\","
"\"cmd_t\":\"device/ztc1/set\","
"\"pl_prs\":\"reboot\","
"\"device_class\":\"outlet\","
"\"device\":{"
"\"identifiers\":[\"tc1_%s\"],"
"\"name\":\"%s\","
"\"model\":\"TC1\","
"\"manufacturer\":\"PHICOMM\"}}",
str_mac,str_mac,str_mac, sys_config->micoSystemConfig.name);
UserMqttSendTopic(topic_buf, send_buf, 1);
}
if (send_buf) free(send_buf);
if (topic_buf) free(topic_buf);
}
void UserMqttHassAutoLed(void) {
char *send_buf = NULL;
char *topic_buf = NULL;
@@ -573,6 +604,7 @@ void UserMqttHassAutoLed(void) {
"\"cmd_t\":\"device/ztc1/set\","
"\"pl_on\":\"set led %s 1\","
"\"pl_off\":\"set led %s 0\","
"\"device_class\":\"outlet\","
"\"device\":{"
"\"identifiers\":[\"tc1_%s\"],"
"\"name\":\"%s\","
@@ -602,6 +634,7 @@ void UserMqttHassAutoChildLock(void) {
"\"cmd_t\":\"device/ztc1/set\","
"\"pl_on\":\"set childLock %s 1\","
"\"pl_off\":\"set childLock %s 0\","
"\"device_class\":\"outlet\","
"\"device\":{"
"\"identifiers\":[\"tc1_%s\"],"
"\"name\":\"%s\","
@@ -631,6 +664,7 @@ void UserMqttHassAutoTotalSocket(void) {
"\"cmd_t\":\"device/ztc1/set\","
"\"pl_on\":\"set total_socket %s 1\","
"\"pl_off\":\"set total_socket %s 0\","
"\"device_class\":\"outlet\","
"\"device\":{"
"\"identifiers\":[\"tc1_%s\"],"
"\"name\":\"%s\","