mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-15 22:33:19 +08:00
在后台增加6个开关重命名功能,名称将同步到ha mqtt设备中
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
static bool is_http_init;
|
||||
static bool is_handlers_registered;
|
||||
const struct httpd_wsgi_call g_app_handlers[];
|
||||
char power_info_json[1552] = {0};
|
||||
char power_info_json[1952] = {0};
|
||||
char up_time[16] = "00:00:00";
|
||||
|
||||
/*
|
||||
@@ -149,13 +149,21 @@ static int HttpGetAssets(httpd_request_t *req) {
|
||||
|
||||
static int HttpGetTc1Status(httpd_request_t *req) {
|
||||
char *sockets = GetSocketStatus();
|
||||
char *tc1_status = malloc(512);
|
||||
char *tc1_status = malloc(1024);
|
||||
char *socket_names = malloc(512);
|
||||
sprintf(socket_names, "%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]);
|
||||
sprintf(tc1_status, TC1_STATUS_JSON, sockets, ip_status.mode,
|
||||
sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key,
|
||||
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);
|
||||
user_config->power_led_enabled, 0L,socket_names);
|
||||
|
||||
OSStatus err = kNoErr;
|
||||
send_http(tc1_status, strlen(tc1_status), exit, &err);
|
||||
@@ -183,6 +191,31 @@ static int HttpSetSocketStatus(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetSocketName(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 512;
|
||||
char *buf = malloc(buf_size);
|
||||
|
||||
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]);
|
||||
mico_system_context_update(sys_config);
|
||||
registerMqttEvents();
|
||||
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];
|
||||
@@ -204,8 +237,16 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||
|
||||
char *powers = GetPowerRecord(idx);
|
||||
char *sockets = GetSocketStatus();
|
||||
char *socket_names = malloc(512);
|
||||
sprintf(socket_names, "%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]);
|
||||
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);
|
||||
up_time,user_config->power_led_enabled,RelayOut()?1:0,socket_names);
|
||||
send_http(power_info_json, strlen(power_info_json), exit, &err);
|
||||
exit:
|
||||
return err;
|
||||
@@ -502,6 +543,7 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{"/ota", HTTPD_HDR_DEFORT, 0, Otastatus, OtaStart, NULL, NULL},
|
||||
{"/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},
|
||||
};
|
||||
|
||||
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
||||
|
||||
@@ -64,10 +64,11 @@
|
||||
'gateway':'%s',\
|
||||
'reportFreq':'%d',\
|
||||
'ledEnabled':%d,\
|
||||
'up_time':%ld\
|
||||
'up_time':%ld,\
|
||||
'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}"
|
||||
#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);
|
||||
|
||||
|
||||
@@ -147,7 +147,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-1
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-1</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -159,7 +166,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-2
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-2</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -171,7 +185,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-3
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-3</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -183,7 +204,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-4
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-4</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -195,7 +223,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-5
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-5</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -207,7 +242,14 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Socket">插座</span>-6
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<span class="lang" langKey="Socket">插座</span><span class="socket-index">-6</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
@@ -544,6 +586,10 @@
|
||||
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</g>
|
||||
<g id="icon-edit">
|
||||
<path d="M5,3C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19H5V5H12V3H5M17.78,4C17.61,4 17.43,4.07 17.3,4.2L16.08,5.41L18.58,7.91L19.8,6.7C20.06,6.44 20.06,6 19.8,5.75L18.25,4.2C18.12,4.07 17.95,4 17.78,4M15.37,6.12L8,13.5V16H10.5L17.87,8.62L15.37,6.12Z" />
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</g>
|
||||
<g id="icon-translate">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"/>
|
||||
@@ -731,12 +777,18 @@
|
||||
HttpGet("/status", function (re) {
|
||||
var status = JSON.parse(re);
|
||||
var status_arr = status.sockets.split(",");
|
||||
var names_arr = status.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i].MaterialSwitch.on();
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[i].MaterialSwitch.off();
|
||||
switch_lables[i+2].MaterialSwitch.off();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,6 +866,38 @@
|
||||
}, checkboxs[0].checked ? "1" : "0");
|
||||
|
||||
});
|
||||
|
||||
$(".edit-socket-name").on("click", function () {
|
||||
// 获取当前按钮所在的 li 元素
|
||||
var $li = $(this).closest(".mdl-list__item");
|
||||
|
||||
// 获取当前索引
|
||||
var index = $(".edit-socket-name").index(this);
|
||||
|
||||
// 获取 lang 名称和 socket-index 元素
|
||||
var $lang = $li.find(".lang");
|
||||
var $index = $li.find(".socket-index");
|
||||
|
||||
// 原名称
|
||||
var oldName = $lang.text().trim();
|
||||
|
||||
// 弹窗编辑
|
||||
var newName = prompt("请输入新的插座名称", oldName);
|
||||
if (newName && newName.trim() !== "") {
|
||||
$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);});
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("list-switch-all").addEventListener("click", function() {
|
||||
HttpPost("/socketAll", function (re) {
|
||||
}, checkboxs[1].checked ? "1" : "0");});
|
||||
@@ -979,8 +1063,14 @@
|
||||
switch_lables[1].MaterialSwitch.off();
|
||||
}
|
||||
var status_arr = power.sockets.split(",");
|
||||
var names_arr = power.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
} else {
|
||||
|
||||
@@ -24,7 +24,7 @@ user_config_t *user_config;
|
||||
mico_gpio_t Relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
|
||||
|
||||
/* MICO system callback: Restore default configuration provided by application */
|
||||
void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
void appRestoreDefault_callback1(void *const user_config_data, uint32_t size) {
|
||||
UNUSED_PARAMETER(size);
|
||||
|
||||
mico_system_context_get()->micoSystemConfig.name[0] = 1; //在下次重启时使用默认名称
|
||||
@@ -47,6 +47,7 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
userConfigDefault->socket_status[i] = 1;
|
||||
snprintf(userConfigDefault->socket_names[i], SOCKET_NAME_LENGTH, "插座-%d", i+1);
|
||||
}
|
||||
for (i = 0; i < MAX_TASK_NUM; i++) {
|
||||
userConfigDefault->timed_tasks[i].on_use = false;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define USER_CONFIG_VERSION 8
|
||||
#define SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。
|
||||
|
||||
#define SOCKET_NAME_LENGTH 32
|
||||
#define SOCKET_NAME_LENGTH 64
|
||||
#define SOCKET_NUM 6 //插座数量
|
||||
|
||||
#define Led MICO_GPIO_5
|
||||
@@ -51,6 +51,7 @@ typedef struct
|
||||
{
|
||||
char version;
|
||||
char mqtt_ip[SETTING_MQTT_STRING_LENGTH_MAX];
|
||||
char socket_names[SOCKET_NUM][SOCKET_NAME_LENGTH];
|
||||
int mqtt_port;
|
||||
int mqtt_report_freq;
|
||||
char mqtt_user[SETTING_MQTT_STRING_LENGTH_MAX];
|
||||
@@ -75,4 +76,6 @@ extern system_config_t* sys_config;
|
||||
extern user_config_t* user_config;
|
||||
extern mico_gpio_t Relay[Relay_NUM];
|
||||
|
||||
extern void appRestoreDefault_callback1(void *const user_config_data, uint32_t size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -174,6 +174,10 @@ static OSStatus MqttMsgPublish(Client *c, const char *topic, char qos, char reta
|
||||
return err;
|
||||
}
|
||||
|
||||
void registerMqttEvents(void) {
|
||||
mico_start_timer(&timer_handle);
|
||||
}
|
||||
|
||||
void MqttClientThread(mico_thread_arg_t arg) {
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
@@ -261,7 +265,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
UserMqttSendLedState();
|
||||
|
||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||
mico_start_timer(&timer_handle);
|
||||
registerMqttEvents();
|
||||
/* 5. client loop for recv msg && keepalive */
|
||||
while (1) {
|
||||
isconnect = true;
|
||||
@@ -504,7 +508,7 @@ void UserMqttHassAuto(char socket_id) {
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/config", str_mac, socket_id);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_Socket_%d\","
|
||||
"{\"name\":\"%s\","
|
||||
"\"uniq_id\":\"%s_s%d\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/socket_%d/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
@@ -515,7 +519,8 @@ void UserMqttHassAuto(char socket_id) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, socket_id + 1, str_mac, socket_id, str_mac, socket_id, str_mac,
|
||||
user_config->socket_names[socket_id], str_mac, socket_id, str_mac, socket_id,
|
||||
str_mac,
|
||||
socket_id, str_mac, socket_id, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
@@ -533,7 +538,7 @@ void UserMqttHassAutoLed(void) {
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_Led\","
|
||||
"{\"name\":\"LED指示灯\","
|
||||
"\"uniq_id\":\"%s_led\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/led/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
@@ -544,7 +549,7 @@ void UserMqttHassAutoLed(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
@@ -561,7 +566,7 @@ void UserMqttHassAutoTotalSocket(void) {
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/total_socket/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_TotalSocket\","
|
||||
"{\"name\":\"总开关\","
|
||||
"\"uniq_id\":\"%s_total_socket\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/total_socket/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
@@ -572,7 +577,7 @@ void UserMqttHassAutoTotalSocket(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
@@ -590,7 +595,7 @@ void UserMqttHassAutoPower(void) {
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_Power\","
|
||||
"{\"name\":\"功率\","
|
||||
"\"uniq_id\":\"%s_p\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/power/state\","
|
||||
"\"unit_of_measurement\":\"W\","
|
||||
@@ -600,11 +605,11 @@ void UserMqttHassAutoPower(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumption/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_PowerConsumption\","
|
||||
"{\"name\":\"总耗电量\","
|
||||
"\"uniq_id\":\"%s_pc\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumption/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
@@ -614,12 +619,12 @@ void UserMqttHassAutoPower(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_powerConsumptionToday\","
|
||||
"{\"name\":\"今日耗电量\","
|
||||
"\"uniq_id\":\"%s_pc_today\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionToday/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
@@ -629,12 +634,12 @@ void UserMqttHassAutoPower(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionYesterday/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_powerConsumptionYesterday\","
|
||||
"{\"name\":\"昨日耗电量\","
|
||||
"\"uniq_id\":\"%s_pc_yesterday\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionYesterday/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
@@ -644,7 +649,7 @@ void UserMqttHassAutoPower(void) {
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac + 8, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf) free(send_buf);
|
||||
|
||||
@@ -43,4 +43,6 @@ extern void UserMqttHassAutoLed(void);
|
||||
|
||||
extern void UserMqttHassAutoTotalSocket(void);
|
||||
|
||||
extern void registerMqttEvents(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -113,7 +113,7 @@ static void KeyLongPress(void)
|
||||
static void KeyLong10sPress(void)
|
||||
{
|
||||
key_log("WARNGIN: user params restored!");
|
||||
appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
||||
appRestoreDefault_callback1(user_config, sizeof(user_config_t));
|
||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
mico_system_context_update(mico_system_context_get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user