mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-23 12:39:53 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a20713693 | ||
|
|
b36fce48f5 | ||
|
|
1b7d86f1f7 | ||
|
|
44ed1d2604 | ||
|
|
b5cb7b8218 | ||
|
|
b099618b91 | ||
|
|
160f4f5b7f | ||
|
|
168f89cc82 |
@@ -8,10 +8,10 @@
|
||||
|
||||
# 固件web界面
|
||||
|
||||
<img src="doc/2.png"><img src="doc/1.png">
|
||||
<img src="doc/IMG_0863.png"><img src="doc/1.png">
|
||||
|
||||
# HASS接入效果
|
||||
<img src="doc/3.png">
|
||||
<img src="doc/IMG_0862.png">
|
||||
|
||||
固件启动后, 会开启一个热点 TC1-AP-XXXXXX,连接热点后, 直接用浏览器访问: http://192.168.0.1 即可看到如上web界面.
|
||||
|
||||
@@ -53,6 +53,7 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
||||
- [x] HomeAssistant中增加总耗电量传感器,今日耗电量传感器,昨日耗电量传感器,数据来自于插座历史统计
|
||||
- [x] 可以设置mqtt数据上报频率,默认2秒
|
||||
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
|
||||
- [x] 后台和ha mqtt增加总开关控制
|
||||
|
||||
# 编译固件
|
||||
|
||||
|
||||
@@ -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,18 +149,27 @@ 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);
|
||||
|
||||
exit:
|
||||
if (socket_names) free(socket_names);
|
||||
if (tc1_status) free(tc1_status);
|
||||
return err;
|
||||
}
|
||||
@@ -183,6 +192,27 @@ 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);
|
||||
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);
|
||||
|
||||
exit:
|
||||
if (buf) free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
char buf[16];
|
||||
@@ -204,9 +234,18 @@ 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);
|
||||
if (socket_names) free(socket_names);
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
@@ -328,6 +367,7 @@ static int HttpGetMqttReportFreq(httpd_request_t *req) {
|
||||
send_http(freq, strlen(freq), exit, &err);
|
||||
|
||||
exit:
|
||||
if(freq) free(freq);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -378,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;
|
||||
}
|
||||
@@ -397,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;
|
||||
}
|
||||
|
||||
@@ -409,6 +451,7 @@ static int LedStatus(httpd_request_t *req) {
|
||||
send_http(led, strlen(led), exit, &err);
|
||||
|
||||
exit:
|
||||
if(led) free(led);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -502,6 +545,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"
|
||||
@@ -477,6 +519,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<span>提示:长按电源按钮5s可开启热点重新配网,10s恢复出厂设置</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
@@ -544,6 +587,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 +778,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 +867,39 @@
|
||||
}, 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() !== "") {
|
||||
if(newName.trim().includes(" ")){
|
||||
ShowToast("名称不能包含空格");
|
||||
return;
|
||||
}
|
||||
if(newName.trim().length>16){
|
||||
ShowToast("名称不能超过16个字");
|
||||
return;
|
||||
}
|
||||
$lang.text(newName.trim());
|
||||
// 可选:更新序号
|
||||
$index.text("");
|
||||
HttpPost("/socketNames", function (re) {
|
||||
}, index+' '+newName.trim());}
|
||||
});
|
||||
|
||||
document.getElementById("list-switch-all").addEventListener("click", function() {
|
||||
HttpPost("/socketAll", function (re) {
|
||||
}, checkboxs[1].checked ? "1" : "0");});
|
||||
@@ -979,8 +1065,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 {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
#include "time.h"
|
||||
#include "unistd.h"
|
||||
#include "TimeUtils.h"
|
||||
#include "mico_system.h"
|
||||
|
||||
#include "user_gpio.h"
|
||||
#include "user_wifi.h"
|
||||
@@ -47,6 +48,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;
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
#define ZTC1_NAME "zTC1-%s"
|
||||
|
||||
#define USER_CONFIG_VERSION 8
|
||||
#define USER_CONFIG_VERSION 9
|
||||
#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,5 @@ extern system_config_t* sys_config;
|
||||
extern user_config_t* user_config;
|
||||
extern mico_gpio_t Relay[Relay_NUM];
|
||||
|
||||
|
||||
#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;
|
||||
@@ -499,12 +503,12 @@ 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);
|
||||
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[(int)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);
|
||||
}
|
||||
@@ -528,12 +533,12 @@ 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);
|
||||
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)
|
||||
@@ -556,12 +561,12 @@ 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);
|
||||
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)
|
||||
@@ -585,12 +590,12 @@ 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);
|
||||
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
|
||||
|
||||
@@ -103,19 +103,20 @@ void UserRelaySetAll(char y)
|
||||
UserRelaySet(i, y);
|
||||
}
|
||||
|
||||
static void KeyLongPress(void)
|
||||
static void KeyLong5sPress(void)
|
||||
{
|
||||
// key_log("KeyLongPress");
|
||||
// UserLedSet(1);
|
||||
// UserMqttSend("mqtt test");
|
||||
key_log("WARNGIN: wifi ap started!");
|
||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
mico_system_context_update(mico_system_context_get());
|
||||
}
|
||||
|
||||
static void KeyLong10sPress(void)
|
||||
{
|
||||
key_log("WARNGIN: user params restored!");
|
||||
appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
mico_system_context_update(mico_system_context_get());
|
||||
mico_system_context_restore(sys_config);
|
||||
// appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
||||
// sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
// mico_system_context_update(mico_system_context_get());
|
||||
}
|
||||
static void KeyShortPress(void)
|
||||
{
|
||||
@@ -152,13 +153,13 @@ 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);
|
||||
|
||||
if (key_time == 30)
|
||||
if (key_time == 50)
|
||||
{
|
||||
KeyLongPress();
|
||||
KeyLong5sPress();
|
||||
}
|
||||
else if (key_time == 100)
|
||||
{
|
||||
|
||||
BIN
doc/IMG_0862.png
Normal file
BIN
doc/IMG_0862.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
BIN
doc/IMG_0863.png
Normal file
BIN
doc/IMG_0863.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 215 KiB |
Reference in New Issue
Block a user