mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-23 20:49:55 +08:00
Compare commits
45 Commits
latest
...
dev_udp_re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8374484d0a | ||
|
|
c3d9db335e | ||
|
|
3470d373eb | ||
|
|
3caf76f4c6 | ||
|
|
982e82c2bb | ||
|
|
eece61e380 | ||
|
|
36861fadff | ||
|
|
f3b7477550 | ||
|
|
dfa8b1c475 | ||
|
|
c7d2f8d7d0 | ||
|
|
3f5078294f | ||
|
|
d7e2243a86 | ||
|
|
4e1b376b6a | ||
|
|
393af288ec | ||
|
|
e9f1448a69 | ||
|
|
004eaf28dd | ||
|
|
0e361111a5 | ||
|
|
026e058934 | ||
|
|
5623b632c7 | ||
|
|
34e1cabc53 | ||
|
|
e6d430c37c | ||
|
|
7c77be5455 | ||
|
|
6598250af1 | ||
|
|
60977f0327 | ||
|
|
f1ba19554e | ||
|
|
2b1577998c | ||
|
|
a5c9211fb6 | ||
|
|
e735afc6c5 | ||
|
|
f8d2b25d1e | ||
|
|
a342d4552a | ||
|
|
759a5ec5cc | ||
|
|
0ba50e9a52 | ||
|
|
f8fba89793 | ||
|
|
30a353c035 | ||
|
|
b470b0f8a0 | ||
|
|
76e8612007 | ||
|
|
6cf213a1b9 | ||
|
|
c214f0de30 | ||
|
|
bf7c8dd7fe | ||
|
|
b2bd368b2d | ||
|
|
56c9923336 | ||
|
|
2d34767cde | ||
|
|
2258158a0d | ||
|
|
f7b6b8ae0a | ||
|
|
b38f9f91d8 |
2
.gdbinit
2
.gdbinit
@@ -1,2 +1,2 @@
|
||||
set remotetimeout 20
|
||||
shell start /B C:\Users\ooo\Desktop\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt
|
||||
shell start /B F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/jlink_swd.cfg]
|
||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx.cfg]
|
||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]
|
||||
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/jlink_swd.cfg]
|
||||
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx.cfg]
|
||||
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
# 固件web界面
|
||||
|
||||
<img src="doc/IMG_0863.png"><img src="doc/1.png">
|
||||
<img src="doc/IMG_0863.png"><img src="doc/1.png"><img src="doc/IMG_0887.png">
|
||||
|
||||
# HASS接入效果
|
||||
<img src="doc/IMG_0862.png">
|
||||
<img src="doc/IMG_0888.png">
|
||||
|
||||
固件启动后, 会开启一个热点 TC1-AP-XXXXXX,连接热点后, 直接用浏览器访问: http://192.168.0.1 即可看到如上web界面.
|
||||
|
||||
@@ -56,8 +56,10 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
||||
- [x] 后台和ha mqtt增加总开关控制
|
||||
- [x] 后台可以自定义6个插座的名称,名称将会自动同步到ha mqtt
|
||||
- [x] 修复了原代码中电源按钮长按 (现在是5秒)重新配网和(10秒)恢复出厂的逻辑错误
|
||||
- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,上电时同时按住按钮的话会开启配网热点(防止开了童锁,wifi又嗝屁,导致插座功能暴毙的救命逻辑)
|
||||
- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,**上电时同时按住按钮的话会开启配网热点**(防止开了童锁,wifi又嗝屁,导致插座功能暴毙的救命逻辑)
|
||||
- [x] 后台可自定义设备名称,此名称将会同至ha mqtt作为mqtt中插座名称的前缀
|
||||
- [x] 后台可自定义按键连击,长按等功能
|
||||
- [x] 定时开关现在支持更多操作项,与按键功能自定义一样
|
||||
|
||||
# 编译固件
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ $(NAME)_SOURCES := main.c\
|
||||
user_power.c\
|
||||
timed_task/timed_task.c\
|
||||
http_server/web_log.c\
|
||||
http_server/app_httpd.c
|
||||
http_server/app_httpd.c\
|
||||
udp_server/udp_server.c
|
||||
|
||||
$(NAME)_COMPONENTS := protocols/SNTP\
|
||||
protocols/mqtt\
|
||||
|
||||
@@ -36,6 +36,11 @@
|
||||
#include <http-strings.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mico.h"
|
||||
#include "httpd_priv.h"
|
||||
#include "app_httpd.h"
|
||||
@@ -52,8 +57,11 @@
|
||||
static bool is_http_init;
|
||||
static bool is_handlers_registered;
|
||||
const struct httpd_wsgi_call g_app_handlers[];
|
||||
char power_info_json[1952] = {0};
|
||||
char power_info_json[2560] = {0};
|
||||
char up_time[16] = "00:00:00";
|
||||
#define CHUNK_SIZE 512 // 每次发送 512 字节,避免 buffer 太大
|
||||
#define OTA_BUFFER_SIZE 512
|
||||
#define MAX_OTA_SIZE 1024*1024
|
||||
|
||||
/*
|
||||
void GetPraFromUrl(char* url, char* pra, char* val)
|
||||
@@ -90,27 +98,30 @@ void GetPraFromUrl(char* url, char* pra, char* val)
|
||||
}
|
||||
*/
|
||||
|
||||
static int HttpGetIndexPage(httpd_request_t *req) {
|
||||
|
||||
static OSStatus send_in_chunks(int sock, const uint8_t *data, int total_len) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index headers."));
|
||||
|
||||
err = httpd_send_body(req->sock, web_index_html, sizeof(web_index_html));
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index body."));
|
||||
|
||||
exit:
|
||||
for (int offset = 0; offset < total_len; offset += CHUNK_SIZE) {
|
||||
int chunk_len = (total_len - offset > CHUNK_SIZE) ? CHUNK_SIZE : (total_len - offset);
|
||||
err = httpd_send_body(sock, data + offset, chunk_len);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Send chunk failed at offset %d", offset));
|
||||
}
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetDemoPage(httpd_request_t *req) {
|
||||
static int HttpGetIndexPage(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http demo headers."));
|
||||
int total_sz = sizeof(web_index_html);
|
||||
|
||||
err = httpd_send_body(req->sock, web_index_html, sizeof(web_index_html));
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http demo body."));
|
||||
exit:
|
||||
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, HTTP_CONTENT_HTML_ZIP);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send index headers."));
|
||||
|
||||
err = send_in_chunks(req->sock, web_index_html, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send index body."));
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -118,14 +129,15 @@ static int HttpGetAssets(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
char *file_name = strstr(req->filename, "/assets/");
|
||||
if (!file_name) { http_log("HttpGetAssets url[%s] err", req->filename);
|
||||
if (!file_name) {
|
||||
http_log("HttpGetAssets url[%s] err", req->filename);
|
||||
return err;
|
||||
}
|
||||
//http_log("HttpGetAssets url[%s] file_name[%s]", req->filename, file_name);
|
||||
|
||||
int total_sz = 0;
|
||||
const unsigned char *file_data = NULL;
|
||||
const char *content_type = HTTP_CONTENT_JS_ZIP;
|
||||
|
||||
if (strcmp(file_name + 8, "js_pack.js") == 0) {
|
||||
total_sz = sizeof(js_pack);
|
||||
file_data = js_pack;
|
||||
@@ -133,24 +145,32 @@ static int HttpGetAssets(httpd_request_t *req) {
|
||||
total_sz = sizeof(css_pack);
|
||||
file_data = css_pack;
|
||||
content_type = HTTP_CONTENT_CSS_ZIP;
|
||||
} else if (strcmp(file_name + 8, "index.html") == 0) {
|
||||
total_sz = sizeof(web_index_html);
|
||||
file_data = web_index_html;
|
||||
content_type = HTTP_CONTENT_HTML_ZIP;
|
||||
}
|
||||
|
||||
if (total_sz == 0 || file_data == NULL) {
|
||||
http_log("File not found: %s", req->filename);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (total_sz == 0) return err;
|
||||
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, content_type);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets headers."));
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset headers."));
|
||||
|
||||
err = httpd_send_body(req->sock, file_data, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets body."));
|
||||
err = send_in_chunks(req->sock, file_data, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset body."));
|
||||
|
||||
exit:
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetTc1Status(httpd_request_t *req) {
|
||||
char *sockets = GetSocketStatus();
|
||||
char *short_click_config = GetShortClickConfig();
|
||||
char *tc1_status = malloc(1024);
|
||||
char *short_click_config = GetButtonClickConfig();
|
||||
char *tc1_status = malloc(1500);
|
||||
char *socket_names = malloc(512);
|
||||
sprintf(socket_names, "%s,%s,%s,%s,%s,%s",
|
||||
user_config->socket_names[0],
|
||||
@@ -215,7 +235,7 @@ static int HttpSetSocketName(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetShortClickEvent(httpd_request_t *req) {
|
||||
static int HttpSetButtonEvent(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 10;
|
||||
@@ -225,8 +245,14 @@ static int HttpSetShortClickEvent(httpd_request_t *req) {
|
||||
require_noerr(err, exit);
|
||||
int index;
|
||||
int func;
|
||||
sscanf(buf, "%d %d", &index, &func);
|
||||
user_config->user[index + 1] = func;
|
||||
int longPress;
|
||||
sscanf(buf, "%d %d %d", &index, &func, &longPress);
|
||||
if (longPress == 1) {
|
||||
set_key_map(user_config->user,index, get_short_func(user_config->user[index]), func == -1 ? NO_FUNCTION : func);
|
||||
} else {
|
||||
set_key_map(user_config->user,index, func == -1 ? NO_FUNCTION : func, get_long_func(user_config->user[index]));
|
||||
}
|
||||
key_log("WARNGIN:set KEY func %d %d %d", index,get_short_func(user_config->user[index]),get_long_func(user_config->user[index]));
|
||||
mico_system_context_update(sys_config);
|
||||
|
||||
send_http("OK", 2, exit, &err);
|
||||
@@ -236,6 +262,90 @@ static int HttpSetShortClickEvent(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#define OTA_BUF_SIZE 5120
|
||||
|
||||
static int HttpSetOTAFile(httpd_request_t *req)
|
||||
{
|
||||
tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d, req.chunked=%d",
|
||||
req->hdr_parsed, req->remaining_bytes, req->body_nbytes, req->chunked);
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int total = 0;
|
||||
int ret = 0;
|
||||
|
||||
// req->chunked = 1;
|
||||
|
||||
int total1 = req->remaining_bytes;
|
||||
char *buffer = malloc(OTA_BUF_SIZE);
|
||||
if (!buffer) return kNoMemoryErr;
|
||||
uint32_t offset = 0;
|
||||
|
||||
mico_logic_partition_t* ota_partition = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
|
||||
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
|
||||
CRC16_Context crc_context;
|
||||
CRC16_Init(&crc_context);
|
||||
// 尝试读取全部 POST 数据
|
||||
while (1) {
|
||||
ret = httpd_get_data2(req, buffer,OTA_BUF_SIZE);
|
||||
|
||||
// ret = httpd_recv(req->sock, buffer, 128, 0);
|
||||
total += ret;
|
||||
// req->remaining_bytes -= ret;
|
||||
|
||||
if (ret > 0) {
|
||||
CRC16_Update(&crc_context, buffer, ret);
|
||||
err = MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (uint8_t *)buffer, ret);
|
||||
require_noerr_quiet(err, exit);
|
||||
tc1_log("[OTA] 本次读取 %d 字节,累计 %d 字节", ret, total);
|
||||
}
|
||||
|
||||
if (ret == 0 || req->remaining_bytes <= 0) {
|
||||
// 读取完毕
|
||||
tc1_log("[OTA] 数据读取完成, 总计 %d 字节", total);
|
||||
break;
|
||||
} else if (ret < 0) {
|
||||
tc1_log("[OTA] 数据读取失败, ret=%d", ret);
|
||||
err = kConnectionErr;
|
||||
break;
|
||||
}
|
||||
|
||||
mico_rtos_thread_msleep(100);
|
||||
|
||||
// tc1_log("[OTA] %x", buffer);
|
||||
// tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d",
|
||||
// req->hdr_parsed, req->remaining_bytes, req->body_nbytes);
|
||||
}
|
||||
// if (buffer) free(buffer);
|
||||
uint16_t crc16;
|
||||
CRC16_Final(&crc_context, &crc16);
|
||||
|
||||
|
||||
err = mico_ota_switch_to_new_fw(total, crc16);
|
||||
tc1_log("[OTA] mico_ota_switch_to_new_fw err=%d", err);
|
||||
require_noerr(err, exit);
|
||||
|
||||
char resp[128];
|
||||
snprintf(resp, sizeof(resp), "OK, total: %d bytes, req %d %d", total, req->body_nbytes, total1);
|
||||
send_http(resp, strlen(resp), exit, &err);
|
||||
|
||||
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
|
||||
exit:
|
||||
if (buffer) free(buffer);
|
||||
return err;
|
||||
|
||||
// ota_file_req = req;
|
||||
|
||||
// OSStatus err = kNoErr;
|
||||
// err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "OtaFileThread", OtaFileThread, 0x1000, 0);
|
||||
// char buf[16] = {0};
|
||||
// sprintf(buf, "%d", sizeof(ota_file_req));
|
||||
// send_http(buf, strlen(buf), exit, &err);
|
||||
|
||||
// exit:
|
||||
// if (buf) free(buf);
|
||||
// return err;
|
||||
}
|
||||
|
||||
static int HttpSetDeviceName(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
@@ -298,7 +408,7 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||
|
||||
char *powers = GetPowerRecord(idx);
|
||||
char *sockets = GetSocketStatus();
|
||||
char *short_click_config = GetShortClickConfig();
|
||||
char *short_click_config = GetButtonClickConfig();
|
||||
char *socket_names = malloc(512);
|
||||
sprintf(socket_names, "%s,%s,%s,%s,%s,%s",
|
||||
user_config->socket_names[0],
|
||||
@@ -325,19 +435,62 @@ static int HttpGetWifiConfig(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
// 单个十六进制字符转数字(安全)
|
||||
static int hex_char_to_int(char c) {
|
||||
if ('0' <= c && c <= '9') return c - '0';
|
||||
if ('a' <= c && c <= 'f') return c - 'a' + 10;
|
||||
if ('A' <= c && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 健壮版 URL 解码函数
|
||||
void url_decode(const char *src, char *dest, size_t max_len) {
|
||||
size_t i = 0;
|
||||
while (*src && i < max_len - 1) {
|
||||
if (*src == '%') {
|
||||
if (isxdigit((unsigned char)src[1]) && isxdigit((unsigned char)src[2])) {
|
||||
int high = hex_char_to_int(src[1]);
|
||||
int low = hex_char_to_int(src[2]);
|
||||
if (high >= 0 && low >= 0) {
|
||||
dest[i++] = (char)((high << 4) | low);
|
||||
src += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 非法编码,跳过 %
|
||||
src++;
|
||||
} else if (*src == '+') {
|
||||
dest[i++] = ' ';
|
||||
src++;
|
||||
} else {
|
||||
dest[i++] = *src++;
|
||||
}
|
||||
}
|
||||
dest[i] = '\0';
|
||||
}
|
||||
|
||||
static int HttpSetWifiConfig(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 97;
|
||||
char *buf = malloc(buf_size);
|
||||
int mode = -1;
|
||||
char *wifi_ssid = malloc(32);
|
||||
char *wifi_key = malloc(32);
|
||||
char *buf = malloc(256);
|
||||
char *ssid_enc = malloc(128);
|
||||
char *key_enc = malloc(128);
|
||||
char *wifi_ssid = malloc(128);
|
||||
char *wifi_key = malloc(128);
|
||||
int mode = -1;
|
||||
|
||||
err = httpd_get_data(req, buf, buf_size);
|
||||
|
||||
|
||||
err = httpd_get_data(req, buf, 256);
|
||||
require_noerr(err, exit);
|
||||
|
||||
sscanf(buf, "%d %s %s", &mode, wifi_ssid, wifi_key);
|
||||
// 假设 httpd_get_data(req, buf, 256);
|
||||
// tc1_log("wifi config %s",buf);
|
||||
sscanf(buf, "%d %s %s", &mode, ssid_enc, key_enc);
|
||||
// tc1_log("wifi config %s %s",ssid_enc,key_enc);
|
||||
url_decode(ssid_enc, wifi_ssid,128);
|
||||
url_decode(key_enc, wifi_key,128);
|
||||
// tc1_log("wifi config decode %s %s",wifi_ssid,wifi_key);
|
||||
if (mode == 1) {
|
||||
WifiConnect(wifi_ssid, wifi_key);
|
||||
} else {
|
||||
@@ -397,7 +550,10 @@ static int HttpSetMqttConfig(httpd_request_t *req) {
|
||||
|
||||
sscanf(buf, "%s %d %s %s", MQTT_SERVER, &MQTT_SERVER_PORT, MQTT_SERVER_USR, MQTT_SERVER_PWD);
|
||||
mico_system_context_update(sys_config);
|
||||
|
||||
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||
err = UserMqttInit();
|
||||
require_noerr(err, exit);
|
||||
}
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
exit:
|
||||
@@ -457,13 +613,12 @@ static int HttpGetTasks(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetShortClickEvents(httpd_request_t *req) {
|
||||
static int HttpGetButtonEvents(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
char *clicks = GetShortClickConfig();
|
||||
char *clicks = GetButtonClickConfig();
|
||||
send_http(clicks, strlen(clicks), exit, &err);
|
||||
|
||||
exit:
|
||||
if (clicks) free(clicks);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -471,8 +626,8 @@ static int HttpAddTask(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
//1577369623 4 0
|
||||
char buf[16] = {0};
|
||||
err = httpd_get_data(req, buf, 16);
|
||||
char buf[20] = {0};
|
||||
err = httpd_get_data(req, buf, 20);
|
||||
require_noerr(err, exit);
|
||||
|
||||
pTimedTask task = NewTask();
|
||||
@@ -481,21 +636,19 @@ static int HttpAddTask(httpd_request_t *req) {
|
||||
send_http(mess, strlen(mess), exit, &err);
|
||||
return err;
|
||||
}
|
||||
int re = sscanf(buf, "%ld %d %d %d", &task->prs_time, &task->socket_idx, &task->on,
|
||||
int re = sscanf(buf, "%ld %d %d %d", &task->prs_time, &task->operation, &task->on,
|
||||
&task->weekday);http_log("AddTask buf[%s] re[%d] (%ld %d %d %d)",
|
||||
buf, re, task->prs_time, task->socket_idx, task->on,
|
||||
buf, re, task->prs_time, task->operation, task->on,
|
||||
task->weekday);
|
||||
task->socket_idx--;
|
||||
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|
||||
|| task->socket_idx < 0 || task->socket_idx > 5
|
||||
|| (task->on != 0 && task->on != 1)) { http_log("AddTask Error!");
|
||||
|| task->operation < 0 || task->operation > 11) { http_log("AddTask Error!");
|
||||
re = 0;
|
||||
}
|
||||
|
||||
char *mess = (re == 4 && AddTask(task)) ? "OK" : "NO";
|
||||
|
||||
send_http(mess, strlen(mess), exit, &err);
|
||||
if (mess) free(mess);
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
@@ -515,7 +668,6 @@ static int HttpDelTask(httpd_request_t *req) {
|
||||
|
||||
send_http(mess, strlen(mess), exit, &err);
|
||||
exit:
|
||||
if (time_str) free(time_str);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -606,7 +758,6 @@ static int OtaStart(httpd_request_t *req) {
|
||||
|
||||
const struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
||||
{"/demo", HTTPD_HDR_DEFORT, 0, HttpGetDemoPage, NULL, NULL, NULL},
|
||||
{"/assets", HTTPD_HDR_ADD_SERVER |
|
||||
HTTPD_HDR_ADD_CONN_CLOSE, APP_HTTP_FLAGS_NO_EXACT_MATCH, HttpGetAssets, NULL, NULL, NULL},
|
||||
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
||||
@@ -625,7 +776,8 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{"/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},
|
||||
{"/shortClickEvent", HTTPD_HDR_DEFORT, 0, HttpGetShortClickEvents, HttpSetShortClickEvent, NULL, NULL},
|
||||
{"/buttonEvents", HTTPD_HDR_DEFORT, 0, HttpGetButtonEvents, HttpSetButtonEvent, NULL, NULL},
|
||||
{"/ota/fileUpload", HTTPD_HDR_DEFORT, 0, NULL, HttpSetOTAFile, NULL, NULL},
|
||||
};
|
||||
|
||||
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
||||
|
||||
@@ -68,12 +68,12 @@
|
||||
'socketNames':'%s',\
|
||||
'child_lock_enabled':%d,\
|
||||
'deviceName':'%s',\
|
||||
'shortClicks':'%s'\
|
||||
'btnClicks':%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,'deviceName':'%s','shortClicks':'%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,'deviceName':'%s','btnClicks':%s}"
|
||||
|
||||
int AppHttpdStart(void);
|
||||
extern int AppHttpdStart(void);
|
||||
|
||||
int AppHttpdStop();
|
||||
extern int AppHttpdStop();
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
<link rel="stylesheet" href="assets/css_pack.css">
|
||||
<style>
|
||||
.mdl-menu {
|
||||
z-index: 9999 !important;
|
||||
max-height: 300px !important;
|
||||
overflow-y: auto !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -30,7 +31,7 @@
|
||||
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
|
||||
<header class="demo-header mdl-layout__header">
|
||||
<div class="mdl-layout__header-row">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-device-name">
|
||||
<button class="mdl-button mdl-button--icon edit-device-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -39,22 +40,22 @@
|
||||
</button>
|
||||
<span class="mdl-layout-title">TC1智能插座</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<!-- <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"-->
|
||||
<!-- id="hdrbtn">-->
|
||||
<!-- <i class="material-icons">-->
|
||||
<!-- <svg>-->
|
||||
<!-- <use xlink:href="#icon-translate"/>-->
|
||||
<!-- </svg>-->
|
||||
<!-- </i>-->
|
||||
<!-- </button>-->
|
||||
<!-- <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"-->
|
||||
<!-- for="hdrbtn">-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>-->
|
||||
<!-- </ul>-->
|
||||
<!-- <button class="mdl-button mdl-button--icon"-->
|
||||
<!-- id="hdrbtn">-->
|
||||
<!-- <i class="material-icons">-->
|
||||
<!-- <svg>-->
|
||||
<!-- <use xlink:href="#icon-translate"/>-->
|
||||
<!-- </svg>-->
|
||||
<!-- </i>-->
|
||||
<!-- </button>-->
|
||||
<!-- <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"-->
|
||||
<!-- for="hdrbtn">-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>-->
|
||||
<!-- </ul>-->
|
||||
<button onclick="reboot()"
|
||||
class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
|
||||
class="mdl-button mdl-button--icon"
|
||||
id="rebootbtn">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
@@ -91,6 +92,14 @@
|
||||
<span class="lang" langKey="TimedTask">定时任务</span>
|
||||
</a>
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(4);">
|
||||
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
||||
<svg>
|
||||
<use xlink:href="#icon-click"/>
|
||||
</svg>
|
||||
</i>
|
||||
<span class="lang" langKey="TimedTask">按键自定义</span>
|
||||
</a>
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(5);">
|
||||
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
||||
<svg>
|
||||
<use xlink:href="#icon-info"/>
|
||||
@@ -98,15 +107,15 @@
|
||||
</i>
|
||||
<span class="lang" langKey="SystemStatus">系统状态</span>
|
||||
</a>
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(5);">
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(6);">
|
||||
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
||||
<svg>
|
||||
<use xlink:href="#icon-cloud_download"/>
|
||||
</svg>
|
||||
</i>
|
||||
<span class="lang" langKey="OTA">在线升级</span>
|
||||
<span class="lang" langKey="OTA">固件升级</span>
|
||||
</a>
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(6);">
|
||||
<a class="mdl-navigation__link" href="javascript:ShowPage(7);">
|
||||
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
||||
<svg>
|
||||
<use xlink:href="#icon-notes"/>
|
||||
@@ -121,8 +130,9 @@
|
||||
|
||||
|
||||
|
||||
<div class="page page1 mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="overflow: unset;">
|
||||
<div class="page page1 mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing">
|
||||
<div class="demo-options mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
|
||||
<div class="mdl-card__supporting-text">
|
||||
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">插座控制</h2>
|
||||
@@ -166,7 +176,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -185,7 +195,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -204,7 +214,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -223,7 +233,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -242,7 +252,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -261,7 +271,7 @@
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
||||
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
@@ -279,44 +289,34 @@
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="page page1 mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="overflow: unset;">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">功率图</h2>
|
||||
</div>
|
||||
|
||||
<div id="ct-chart-par"
|
||||
class="page page1 mdl-card__supporting-text mdl-shadow--2dp mdl-cell mdl-cell--6-col"
|
||||
style="height:315px;overflow-x:scroll;overflow-y:hidden;">
|
||||
<table class="pw">
|
||||
<tr>
|
||||
<td>当前功率: <span id="p" class="success">0</span> W</td>
|
||||
<td>今日电量: <span id="w_t" class="error">0</span> kW·h</td>
|
||||
<td>昨日电量: <span id="w_y" class="error">0</span> kW·h</td>
|
||||
<td>总电量: <span id="w" class="error">0</span> kW·h</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="ct-chart" class="ct-chart ct-perfect-fourth"
|
||||
style="height:280px;margin-top:40px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page page1 mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="overflow: unset;">
|
||||
<div class="page page1 mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing">
|
||||
<div class="demo-options mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
|
||||
<div class="mdl-card__supporting-text">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">按键自定义</h2>
|
||||
<h2 class="mdl-card__title-text">功率图</h2>
|
||||
</div>
|
||||
<table id="short_click_events_tb" class="mdl-data-table mdl-js-data-table">
|
||||
<tr>
|
||||
<th>按键类型</th>
|
||||
<th>执行操作</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div id="ct-chart-par"
|
||||
class="page page1 mdl-card__supporting-text mdl-shadow--2dp"
|
||||
style="height:315px;overflow-x:scroll;overflow-y:hidden;">
|
||||
<table class="pw">
|
||||
<tr>
|
||||
<td>当前功率: <span id="p" class="success">0</span> W</td>
|
||||
<td>今日电量: <span id="w_t" class="error">0</span> kW·h</td>
|
||||
<td>昨日电量: <span id="w_y" class="error">0</span> kW·h</td>
|
||||
<td>总电量: <span id="w" class="error">0</span> kW·h</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="ct-chart" class="ct-chart ct-perfect-fourth"
|
||||
style="height:280px;margin-top:40px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page page2 mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="overflow: unset;">
|
||||
@@ -368,10 +368,10 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a id="wifi_submit"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" id="wifi_submit"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
提交
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -401,10 +401,10 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a id="mqtt_submit"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" id="mqtt_submit"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
提交
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -422,10 +422,10 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a id="mqtt_freq_submit"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" id="mqtt_freq_submit"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
提交
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -438,20 +438,6 @@
|
||||
<th>循环</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>02-15 07:11</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td><a>删除</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2020-02-15<br>07:11:08</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td>6</td>
|
||||
<td><a>删除</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -495,17 +481,9 @@
|
||||
<use xlink:href="#icon-keyboard_arrow_down"/>
|
||||
</svg>
|
||||
</i>
|
||||
<label for="task_skt_idx" class="mdl-textfield__label">插座</label>
|
||||
<label for="task_skt_idx" class="mdl-textfield__label">操作</label>
|
||||
<ul for="task_skt_idx"
|
||||
class="mdl-menu mdl-menu--bottom-left mdl-js-menu">
|
||||
<li class="mdl-menu__item" data-val="1" data-selected='true'>
|
||||
插座-1
|
||||
</li>
|
||||
<li class="mdl-menu__item" data-val="2">插座-2</li>
|
||||
<li class="mdl-menu__item" data-val="3">插座-3</li>
|
||||
<li class="mdl-menu__item" data-val="4">插座-4</li>
|
||||
<li class="mdl-menu__item" data-val="5">插座-5</li>
|
||||
<li class="mdl-menu__item" data-val="6">插座-6</li>
|
||||
class="mdl-menu mdl-menu--bottom-left mdl-js-menu" id="operations_list">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mdl-textfield mdl-js-textfield">
|
||||
@@ -527,35 +505,114 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a href="javascript:AddTimedTask();"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" onclick="AddTimedTask();"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
提交
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="page page4 mdl-cell mdl-cell--12-col demo-card-event mdl-card mdl-shadow--2dp">
|
||||
<div class="page page4 over-unset mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="z-index: unset;">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">按键自定义</h2>
|
||||
</div>
|
||||
<table id="short_click_events_tb" class="mdl-data-table mdl-js-data-table">
|
||||
<tr>
|
||||
<th>按键类型</th>
|
||||
<th>执行操作</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="page page4 over-unset mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||
style="z-index: unset;">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">添加按键操作</h2>
|
||||
</div>
|
||||
<div class="over-unset mdl-card__supporting-text">
|
||||
<form action="#">
|
||||
<div class="mdl-textfield mdl-js-textfield getmdl-select">
|
||||
<input type="text" value=""
|
||||
class="mdl-textfield__input" readonly>
|
||||
<input type="hidden" value="0" name="button_type" id="button_type">
|
||||
<i class="mdl-icon-toggle__label material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-keyboard_arrow_down"/>
|
||||
</svg>
|
||||
</i>
|
||||
<label for="button_type" class="mdl-textfield__label">按钮触发方式</label>
|
||||
<ul for="button_type"
|
||||
class="mdl-menu mdl-menu--bottom-left mdl-js-menu">
|
||||
<li class="mdl-menu__item" data-val="0" data-selected='true'>
|
||||
单/多击
|
||||
</li>
|
||||
<li class="mdl-menu__item" data-val="1">长按</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mdl-textfield mdl-js-textfield getmdl-select">
|
||||
<input type="text" value=""
|
||||
class="mdl-textfield__input" readonly>
|
||||
<input type="hidden" value="1" name="click_times_press_time" id="click_times_press_time">
|
||||
<i class="mdl-icon-toggle__label material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-keyboard_arrow_down"/>
|
||||
</svg>
|
||||
</i>
|
||||
<label for="click_times_press_time" class="mdl-textfield__label" id="click_times_press_time_label">连击次数</label>
|
||||
<ul for="click_times_press_time"
|
||||
class="mdl-menu mdl-menu--bottom-left mdl-js-menu" id="click_times_press_time_selector" style="">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mdl-textfield mdl-js-textfield getmdl-select">
|
||||
<input type="text" value=""
|
||||
class="mdl-textfield__input" readonly>
|
||||
<input type="hidden" value="-1" name="action_type" id="action_type">
|
||||
<i class="mdl-icon-toggle__label material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-keyboard_arrow_down"/>
|
||||
</svg>
|
||||
</i>
|
||||
<label for="action_type" class="mdl-textfield__label">执行的操作</label>
|
||||
<ul for="action_type"
|
||||
class="mdl-menu mdl-menu--bottom-left mdl-js-menu" id="btn_action_selector">
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<button type="button" onclick="addButtonEvent();"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
添加
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="page page5 mdl-cell mdl-cell--12-col demo-card-event mdl-card mdl-shadow--2dp">
|
||||
<table class="mdl-data-table mdl-js-data-table">
|
||||
<tr>
|
||||
<th>版本</th>
|
||||
<th id="info_version">v1.0.33</th>
|
||||
<th id="info_version"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP</td>
|
||||
<td id="info_ip">192.168.33.222</td>
|
||||
<td id="info_ip"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>子网掩码</td>
|
||||
<td id="info_mask">255.255.255.0</td>
|
||||
<td id="info_mask"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>网关</td>
|
||||
<td id="info_gateway">192.168.33.1</td>
|
||||
<td id="info_gateway"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>启动时间</td>
|
||||
<td id="uptime">10:13:43</td>
|
||||
<td id="uptime"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="mdl-card__actions mdl-card--border" style="display: flex; align-items: center; flex-wrap: wrap;">
|
||||
@@ -567,11 +624,11 @@
|
||||
</svg>
|
||||
</i>
|
||||
<!-- <span>2020-02-22</span> -->
|
||||
<a class="mdl-button" id="st-date">2020-02-22</a>
|
||||
<a class="mdl-button" id="st-date"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page page5 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||
<div class="page page6 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">在线升级</h2>
|
||||
</div>
|
||||
@@ -584,15 +641,34 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a href="javascript:OtaStart();"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" onclick="OtaStart();" id="submit-ota-link"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
提交
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
<div id="ota_status" class="mdl-progress mdl-js-progress"></div>
|
||||
</div>
|
||||
|
||||
<div class="page page6 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">本地升级</h2>
|
||||
</div>
|
||||
<div class="mdl-card__supporting-text">
|
||||
<form id="otaForm" action="/ota/fileUpload" method="post" enctype="multipart/form-data">
|
||||
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||
<input class="mdl-textfield__input" type="file" id="ota_file" name="ota_file">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<button type="button" onclick="OtaFileUpload();" class="mdl-button mdl-button--colored " id="submit-ota-file">
|
||||
上传 OTA 文件
|
||||
</button>
|
||||
</div>
|
||||
<div id="upload_status" class="mdl-progress mdl-js-progress"></div>
|
||||
</div>
|
||||
|
||||
<div class="page page7 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||
<div class="mdl-card__title mdl-card--expand">
|
||||
<h2 class="mdl-card__title-text">系统日志</h2>
|
||||
</div>
|
||||
@@ -600,10 +676,10 @@
|
||||
<pre id="sys_log"></pre>
|
||||
</div>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<a href="javascript:GetSysLog();"
|
||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
||||
<button type="button" onclick="GetSysLog();"
|
||||
class="mdl-button mdl-button--colored ">
|
||||
刷新
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -631,6 +707,10 @@
|
||||
<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-click">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M13 5C15.21 5 17 6.79 17 9C17 10.5 16.2 11.77 15 12.46V11.24C15.61 10.69 16 9.89 16 9C16 7.34 14.66 6 13 6S10 7.34 10 9C10 9.89 10.39 10.69 11 11.24V12.46C9.8 11.77 9 10.5 9 9C9 6.79 10.79 5 13 5M20 20.5C19.97 21.32 19.32 21.97 18.5 22H13C12.62 22 12.26 21.85 12 21.57L8 17.37L8.74 16.6C8.93 16.39 9.2 16.28 9.5 16.28H9.7L12 18V9C12 8.45 12.45 8 13 8S14 8.45 14 9V13.47L15.21 13.6L19.15 15.79C19.68 16.03 20 16.56 20 17.14V20.5M20 2H4C2.9 2 2 2.9 2 4V12C2 13.11 2.9 14 4 14H8V12L4 12L4 4H20L20 12H18V14H20V13.96L20.04 14C21.13 14 22 13.09 22 12V4C22 2.9 21.11 2 20 2Z" />
|
||||
</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"/>
|
||||
@@ -687,32 +767,6 @@
|
||||
<path d="M0,0h24v24H0V0z" fill="none"/>
|
||||
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"/>
|
||||
</g>
|
||||
<g id="img-user">
|
||||
<g id="#45d0e3ff">
|
||||
<path fill="#45d0e3" opacity="1.00"
|
||||
d=" M 53.37 0.00 L 58.72 0.00 C 75.08 0.90 90.91 9.14 100.69 22.33 C 107.50 31.24 111.31 42.21 112.00 53.37 L 112.00 58.70 C 111.04 78.61 98.79 97.47 80.82 106.17 C 79.54 103.27 78.19 100.38 77.13 97.38 C 75.96 93.10 74.50 88.08 76.95 83.97 C 78.90 80.30 84.37 81.15 86.26 77.47 C 87.78 74.72 88.75 71.72 89.88 68.80 C 86.87 67.57 83.95 65.94 82.84 62.67 C 85.41 62.55 87.97 62.56 90.54 62.54 C 90.73 60.46 90.80 58.37 90.97 56.28 C 92.50 56.26 94.04 56.25 95.57 56.24 C 94.14 51.38 93.20 46.39 92.61 41.36 C 91.85 37.14 91.80 32.46 89.06 28.93 C 85.66 24.42 80.36 21.79 75.00 20.42 C 66.49 18.22 57.44 19.54 49.32 22.59 C 48.22 21.70 47.13 20.79 46.00 19.93 C 45.67 19.83 45.02 19.63 44.70 19.53 C 38.54 17.36 31.82 18.95 26.65 22.71 C 21.75 25.72 19.50 31.39 18.56 36.82 C 16.07 51.25 18.52 66.10 15.49 80.46 C 14.80 83.83 13.17 86.89 11.40 89.80 C 4.55 80.87 0.71 69.87 0.00 58.67 L 0.00 53.27 C 0.72 42.15 4.52 31.22 11.31 22.34 C 21.10 9.12 36.98 0.86 53.37 0.00 Z"/>
|
||||
<path fill="#45d0e3" opacity="1.00"
|
||||
d=" M 46.81 58.85 C 48.67 60.66 50.63 62.36 52.52 64.14 C 53.51 65.97 54.72 67.81 54.84 69.95 C 55.32 75.99 54.64 82.26 51.85 87.72 C 47.89 95.43 41.52 101.46 36.56 108.49 C 29.02 105.67 22.14 101.21 16.39 95.59 C 21.92 95.26 27.23 93.08 31.33 89.33 C 40.12 81.50 43.93 69.90 46.81 58.85 Z"/>
|
||||
</g>
|
||||
<g id="#3e3e3eff">
|
||||
<path fill="#3e3e3e" opacity="1.00"
|
||||
d=" M 26.65 22.71 C 31.82 18.95 38.54 17.36 44.70 19.53 C 41.86 22.16 39.20 24.96 36.55 27.77 C 37.72 29.05 38.91 30.31 40.10 31.58 C 42.67 28.12 45.54 24.77 49.32 22.59 C 57.44 19.54 66.49 18.22 75.00 20.42 C 80.36 21.79 85.66 24.42 89.06 28.93 C 91.80 32.46 91.85 37.14 92.61 41.36 C 82.53 41.64 72.25 40.50 62.86 36.65 C 62.81 40.15 63.08 43.92 61.22 47.05 C 60.19 49.27 58.12 50.64 56.32 52.18 C 54.94 50.22 54.14 47.28 51.44 46.79 C 48.33 45.98 45.15 49.54 46.48 52.54 C 48.16 56.57 50.50 60.28 52.52 64.14 C 50.63 62.36 48.67 60.66 46.81 58.85 C 43.93 69.90 40.12 81.50 31.33 89.33 C 27.23 93.08 21.92 95.26 16.39 95.59 C 14.64 93.73 12.95 91.82 11.40 89.80 C 13.17 86.89 14.80 83.83 15.49 80.46 C 18.52 66.10 16.07 51.25 18.56 36.82 C 19.50 31.39 21.75 25.72 26.65 22.71 Z"/>
|
||||
<path fill="#3e3e3e" opacity="1.00"
|
||||
d=" M 83.41 50.49 C 84.92 48.75 86.28 50.47 85.90 52.21 C 84.56 52.87 82.99 52.19 83.41 50.49 Z"/>
|
||||
</g>
|
||||
<g id="#049d56ff">
|
||||
<path fill="#049d56" opacity="1.00"
|
||||
d=" M 44.70 19.53 C 45.02 19.63 45.67 19.83 46.00 19.93 C 47.13 20.79 48.22 21.70 49.32 22.59 C 45.54 24.77 42.67 28.12 40.10 31.58 C 38.91 30.31 37.72 29.05 36.55 27.77 C 39.20 24.96 41.86 22.16 44.70 19.53 Z"/>
|
||||
</g>
|
||||
<g id="#ffe1afff">
|
||||
<path fill="#ffe1af" opacity="1.00"
|
||||
d=" M 62.86 36.65 C 72.25 40.50 82.53 41.64 92.61 41.36 C 93.20 46.39 94.14 51.38 95.57 56.24 C 94.04 56.25 92.50 56.26 90.97 56.28 C 90.80 58.37 90.73 60.46 90.54 62.54 C 87.97 62.56 85.41 62.55 82.84 62.67 C 83.95 65.94 86.87 67.57 89.88 68.80 C 88.75 71.72 87.78 74.72 86.26 77.47 C 84.37 81.15 78.90 80.30 76.95 83.97 C 74.50 88.08 75.96 93.10 77.13 97.38 C 67.78 97.97 58.22 94.74 51.85 87.72 C 54.64 82.26 55.32 75.99 54.84 69.95 C 54.72 67.81 53.51 65.97 52.52 64.14 C 50.50 60.28 48.16 56.57 46.48 52.54 C 45.15 49.54 48.33 45.98 51.44 46.79 C 54.14 47.28 54.94 50.22 56.32 52.18 C 58.12 50.64 60.19 49.27 61.22 47.05 C 63.08 43.92 62.81 40.15 62.86 36.65 M 83.41 50.49 C 82.99 52.19 84.56 52.87 85.90 52.21 C 86.28 50.47 84.92 48.75 83.41 50.49 Z"/>
|
||||
</g>
|
||||
<g id="#fe5606ff">
|
||||
<path fill="#fe5606" opacity="1.00"
|
||||
d=" M 36.56 108.49 C 41.52 101.46 47.89 95.43 51.85 87.72 C 58.22 94.74 67.78 97.97 77.13 97.38 C 78.19 100.38 79.54 103.27 80.82 106.17 C 73.65 109.79 65.69 111.59 57.70 112.00 L 54.26 112.00 C 48.24 111.64 42.22 110.63 36.56 108.49 Z"/>
|
||||
</g>
|
||||
</g>
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
@@ -728,7 +782,7 @@
|
||||
Config: {en: "Config", cn: "设置"},
|
||||
TimedTask: {en: "Timed Task", cn: "定时任务"},
|
||||
SystemStatus: {en: "System Status", cn: "系统状态"},
|
||||
OTA: {en: "OTA", cn: "在线升级"},
|
||||
OTA: {en: "OTA", cn: "固件升级"},
|
||||
SystemLog: {en: "System Log", cn: "系统日志"},
|
||||
About: {en: "About", cn: "关于"},
|
||||
//主页
|
||||
@@ -748,6 +802,8 @@
|
||||
$(this).html(val);
|
||||
});
|
||||
}
|
||||
var BTN_OPERATIONS=["切换总开关"];
|
||||
var names_arr = [];
|
||||
//弹框-start
|
||||
var snackbarContainer = document.querySelector('#demo-toast-example');
|
||||
function ShowToast(mess) {
|
||||
@@ -860,7 +916,7 @@
|
||||
HttpGet("/status", function (re) {
|
||||
var status = JSON.parse(re);
|
||||
var status_arr = status.sockets.split(",");
|
||||
var names_arr = status.socketNames.split(",");
|
||||
names_arr = status.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
$(".mdl-layout-title").text(status.deviceName);
|
||||
document.title=status.deviceName;
|
||||
@@ -898,53 +954,97 @@
|
||||
$("#info_gateway").html(status.gateway);
|
||||
$("#uptime").html(status.up_time);
|
||||
|
||||
|
||||
var actions=status.shortClicks.split(",");
|
||||
//按键操作功能定义
|
||||
var BTN_OPERATIONS=["切换总开关"];
|
||||
for (var i = 0; i < names_arr.length; i++) {
|
||||
for (var i = 0; i < names_arr.length; i++) {
|
||||
BTN_OPERATIONS.push(`切换${names_arr[i]}`);
|
||||
}
|
||||
BTN_OPERATIONS.push("切换电源指示灯启用");
|
||||
BTN_OPERATIONS.push("重启系统");
|
||||
BTN_OPERATIONS.push("重新配网");
|
||||
BTN_OPERATIONS.push("重置系统");
|
||||
BTN_OPERATIONS.push("切换童锁");
|
||||
BTN_OPERATIONS.push("重启网页");
|
||||
|
||||
$('#btn_action_selector').append(
|
||||
$('<li>')
|
||||
.addClass('mdl-menu__item')
|
||||
.attr('data-val', -1)
|
||||
.text("未设置")
|
||||
);
|
||||
for (let i = 0; i < BTN_OPERATIONS.length; i++) {
|
||||
$('#operations_list').append(
|
||||
$('<li>')
|
||||
.addClass('mdl-menu__item')
|
||||
.attr('data-val', `${i}`)
|
||||
.attr('data-selected', `false`)
|
||||
.text(BTN_OPERATIONS[i].replaceAll('切换','设置'))
|
||||
);
|
||||
$('#btn_action_selector').append(
|
||||
$('<li>')
|
||||
.addClass('mdl-menu__item')
|
||||
.attr('data-val', i)
|
||||
.text(BTN_OPERATIONS[i])
|
||||
);
|
||||
}
|
||||
getmdlSelect.init(".getmdl-select");
|
||||
|
||||
refreshButtonEvents(status.btnClicks);
|
||||
GetTimedTask();
|
||||
});
|
||||
|
||||
|
||||
function refreshButtonEvents(actions){
|
||||
var tb_html = `
|
||||
<thead>
|
||||
<tr>
|
||||
<th>按键类型</th>
|
||||
<th>执行操作</th>
|
||||
<th>执行动作</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
|
||||
var cnt=0;
|
||||
for (var i = 0; i < actions.length; i++) {
|
||||
var rowId = `select-${i}`;
|
||||
var index = parseInt(actions[i]);
|
||||
var valueText = (isNaN(index) || index < 0 || index >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[index];
|
||||
var times = Object.keys(actions[i])[0];
|
||||
var operations = Object.values(actions[i])[0];
|
||||
if(operations[0]!=-1){
|
||||
cnt++;
|
||||
var valueText = (isNaN(operations[0]) || operations[0] < 0 || operations[0] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[0]];
|
||||
tb_html += `
|
||||
<tr>
|
||||
<td>${times > 1 ? '连续' : ''}短按${times}次</td>
|
||||
<td>${valueText}</td>
|
||||
<td><a href='javascript:deleteButtonEvent(${times},0);'>删除</a></td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
if(operations[1]!=-1){
|
||||
cnt++;
|
||||
var valueText = (isNaN(operations[1]) || operations[1] < 0 || operations[1] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[1]];
|
||||
|
||||
tb_html += `
|
||||
<tr>
|
||||
<td>${i > 0 ? '连续' : ''}短按${i + 1}次</td>
|
||||
<td>
|
||||
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select getmdl-select__fix-height">
|
||||
<input class="mdl-textfield__input" type="text" id="${rowId}-input" readonly value="${valueText}">
|
||||
<input type="hidden" id="${rowId}-value" value="${index}">
|
||||
<ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu" for="${rowId}-input">
|
||||
<li class="mdl-menu__item" data-val="-1" onclick="selectOperation('${rowId}', -1,'${BTN_OPERATIONS[0]}')">未设置</li>
|
||||
${BTN_OPERATIONS.map((op, idx) =>
|
||||
`<li class="mdl-menu__item" data-val="${idx}" onclick="selectOperation('${rowId}', ${idx},'${BTN_OPERATIONS[idx]}')">${op}</li>`
|
||||
).join('')}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td>长按${times}秒</td>
|
||||
<td>${valueText}</td>
|
||||
<td><a href='javascript:deleteButtonEvent(${times},1);'>删除</a></td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
|
||||
}
|
||||
if (cnt == 0) {
|
||||
tb_html += "<tr><td colspan='5'>没有自定义按键动作</td></tr>";
|
||||
}
|
||||
tb_html+="\
|
||||
</tbody>";
|
||||
document.getElementById("short_click_events_tb").innerHTML = tb_html;
|
||||
componentHandler.upgradeDom();
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
$(".mdl-switch__input").on("click", function() {
|
||||
if("list-switch-all" == this.id||"list-switch-child-lock"== this.id){
|
||||
if("list-switch-all" == this.id||"list-switch-child-lock"== this.id||"task_on"== this.id){
|
||||
return;
|
||||
}
|
||||
var sockets_st = "";
|
||||
@@ -1122,15 +1222,15 @@ componentHandler.upgradeDom();
|
||||
var mode = $("#custom_station").prop("checked") ? 1 : 0;
|
||||
var ssid = $("#custom_ssid").val();
|
||||
var passwd = $("#custom_password").val();
|
||||
if (ContainQM(ssid) || ContainQM(passwd)) {
|
||||
alert(qm_mess);
|
||||
return;
|
||||
}
|
||||
//if (ContainQM(ssid) || ContainQM(passwd)) {
|
||||
// alert(qm_mess);
|
||||
// return;
|
||||
//}
|
||||
if (passwd.length < 8) {
|
||||
alert(le_mess);
|
||||
return;
|
||||
}
|
||||
var params = mode + " " + ssid + " " + passwd;
|
||||
var params = mode + " " + encodeURIComponent(ssid) + " " + encodeURIComponent(passwd);
|
||||
HttpPost("/wifi/config", function (re) {
|
||||
ShowToast(re);
|
||||
}, params);
|
||||
@@ -1146,6 +1246,7 @@ componentHandler.upgradeDom();
|
||||
var w = document.getElementById("w");
|
||||
var w_t = document.getElementById("w_t");
|
||||
var w_y = document.getElementById("w_y");
|
||||
var powerTimerId;
|
||||
|
||||
function GetPowerRecord() {
|
||||
HttpPost("/power", function (re) {
|
||||
@@ -1195,7 +1296,7 @@ componentHandler.upgradeDom();
|
||||
switch_lables[2].MaterialSwitch.off();
|
||||
}
|
||||
var status_arr = power.sockets.split(",");
|
||||
var names_arr = power.socketNames.split(",");
|
||||
names_arr = power.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
$(".mdl-layout-title").text(power.deviceName);
|
||||
document.title=power.deviceName;
|
||||
@@ -1211,7 +1312,7 @@ componentHandler.upgradeDom();
|
||||
switch_lables[i+3].MaterialSwitch.off();
|
||||
}
|
||||
}
|
||||
window.setTimeout(GetPowerRecord, 3000);
|
||||
powerTimerId= window.setTimeout(GetPowerRecord, 3000);
|
||||
}, power_idx.toString());
|
||||
}
|
||||
$(document).ready(function(){
|
||||
@@ -1230,13 +1331,14 @@ componentHandler.upgradeDom();
|
||||
function GetTimedTask() {
|
||||
HttpGet("/task", function (re) {
|
||||
var tb_html = "\
|
||||
<tr>\
|
||||
<thead><tr>\
|
||||
<th>时间</th>\
|
||||
<th>插座</th>\
|
||||
<th>开关</th>\
|
||||
<th>循环</th>\
|
||||
<th>操作</th>\
|
||||
</tr>";
|
||||
</tr></thead>\
|
||||
<tbody>";
|
||||
console.log(re);
|
||||
var tasks = JSON.parse(re);
|
||||
if (tasks.length == 0) {
|
||||
@@ -1246,16 +1348,39 @@ componentHandler.upgradeDom();
|
||||
tb_html += "\
|
||||
<tr>\
|
||||
<td>" + tasks[i].prs_time + "</td>\
|
||||
<td>" + tasks[i].socket_idx + "</td>\
|
||||
<td>" + tasks[i].on + "</td>\
|
||||
<td>" + tasks[i].weekday + "</td>\
|
||||
<td><a href='javascript:DelTimedTask(" + tasks[i].timestamp + ");'>Delete</a></td>\
|
||||
<td>" + BTN_OPERATIONS[tasks[i].operation].replaceAll('切换','设置') + "</td>\
|
||||
<td>" + ((tasks[i].operation==11||tasks[i].operation<8)?(tasks[i].on == 1?"开":"关"):"-") + "</td>\
|
||||
<td>" + getLoopText(tasks[i].weekday) + "</td>\
|
||||
<td><a href='javascript:DelTimedTask(" + tasks[i].timestamp + ");'>删除</a></td>\
|
||||
</tr>";
|
||||
}
|
||||
tb_html+="\
|
||||
</tbody>";
|
||||
document.getElementById("timed_task_tb").innerHTML = tb_html;
|
||||
});
|
||||
}
|
||||
GetTimedTask();
|
||||
function getLoopText(i){
|
||||
switch(i){
|
||||
case 0:
|
||||
return '不循环';
|
||||
case 1:
|
||||
return '每周一';
|
||||
case 2:
|
||||
return '每周二';
|
||||
case 3:
|
||||
return '每周三';
|
||||
case 4:
|
||||
return '每周四';
|
||||
case 5:
|
||||
return '每周五';
|
||||
case 6:
|
||||
return '每周六';
|
||||
case 7:
|
||||
return '每周日';
|
||||
case 8:
|
||||
return '每天';
|
||||
}
|
||||
}
|
||||
|
||||
var task_date = document.getElementById("task_date");
|
||||
var task_time = document.getElementById("task_time");
|
||||
@@ -1275,10 +1400,7 @@ componentHandler.upgradeDom();
|
||||
//prs_time = prs_time + parseInt(sec);
|
||||
on = on ? "1" : "0";
|
||||
var cmd = prs_time + " " + idx + " " + on + " " + wkd;
|
||||
if (cmd.length != 16) {
|
||||
alert("CMD ERROR!");
|
||||
return
|
||||
}
|
||||
|
||||
HttpPost("/task", function (re) {
|
||||
if (re != "OK") {
|
||||
alert(re);
|
||||
@@ -1287,6 +1409,61 @@ componentHandler.upgradeDom();
|
||||
GetTimedTask();
|
||||
}, cmd);
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$('ul[for="button_type"] .mdl-menu__item').on('click',function(){
|
||||
$('#button_type').trigger('change');
|
||||
});
|
||||
});
|
||||
$('#button_type').on('change', function() {
|
||||
var value = $(this).val();
|
||||
$('#click_times_press_time_label').text(value == '0'?'连击次数':'长按秒数');
|
||||
});
|
||||
$(function() {
|
||||
for (let i = 1; i <= 30; i++) {
|
||||
$('#click_times_press_time_selector').append(
|
||||
$('<li>')
|
||||
.addClass('mdl-menu__item')
|
||||
.attr('data-val', i)
|
||||
.text(i)
|
||||
);
|
||||
}
|
||||
getmdlSelect.init(".getmdl-select");
|
||||
});
|
||||
|
||||
function getButtonEvents(){
|
||||
HttpGet("/buttonEvents", function (re) {
|
||||
|
||||
refreshButtonEvents(JSON.parse(re));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function addButtonEvent() {
|
||||
|
||||
var longPress = document.getElementById("button_type").value;
|
||||
var event = document.getElementById("action_type").value;
|
||||
var times_or_seconds = document.getElementById("click_times_press_time").value;
|
||||
|
||||
if(!event||!times_or_seconds){
|
||||
ShowToast("请完成选项");
|
||||
return;
|
||||
}
|
||||
HttpPost("/buttonEvents", function (re) {
|
||||
if (re == "OK") {
|
||||
ShowToast("已添加按键事件");
|
||||
getButtonEvents();
|
||||
}
|
||||
}, `${times_or_seconds} ${event} ${longPress}`);
|
||||
}
|
||||
function deleteButtonEvent(times_or_seconds ,longPress){
|
||||
HttpPost("/buttonEvents", function (re) {
|
||||
if (re == "OK") {
|
||||
ShowToast("已删除按键事件");
|
||||
getButtonEvents();
|
||||
}
|
||||
}, `${times_or_seconds} -1 ${longPress}`);
|
||||
}
|
||||
function selectOperation(rowId, index, operationText) {
|
||||
var witch = parseInt(rowId.split('-')[1]);
|
||||
if (index === -1) {
|
||||
@@ -1314,11 +1491,51 @@ HttpPost("/shortClickEvent", function (re) {
|
||||
var ota_url = document.getElementById("ota_url").value;
|
||||
var protocol = window.location.protocol;
|
||||
var baseUrl = protocol+"//"+window.location.host;
|
||||
|
||||
document.getElementById("submit-ota-link").disabled = true;
|
||||
HttpPost("/ota", function (re) {
|
||||
OtaStatus();
|
||||
}, ota_url);
|
||||
}
|
||||
var upload_status = document.querySelector('#upload_status');
|
||||
upload_status.addEventListener('mdl-componentupgraded', function() {
|
||||
this.MaterialProgress.setProgress(0);
|
||||
});
|
||||
function OtaFileUpload() {
|
||||
//alert("假的假的是假的,忽略");
|
||||
//return;
|
||||
var fileInput = document.getElementById("ota_file");
|
||||
if (fileInput.files.length === 0) {
|
||||
ShowToast("请选择要上传的 OTA 文件");
|
||||
return;
|
||||
}
|
||||
clearTimeout(powerTimerId);
|
||||
console.log(fileInput.files[0].size); // 应显示 647168 左右
|
||||
document.getElementById("submit-ota-file").disabled = true;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/ota/fileUpload");
|
||||
|
||||
xhr.upload.onprogress = function (e) {
|
||||
if (e.lengthComputable) {
|
||||
let percent = (e.loaded / e.total * 100).toFixed(1);
|
||||
upload_status.MaterialProgress.setProgress(percent);
|
||||
console.log(`上传进度:${percent}%`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function () {
|
||||
alert("上传完成:" + xhr.responseText);
|
||||
document.getElementById("submit-ota-file").disabled = false;
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
alert("上传失败");
|
||||
document.getElementById("submit-ota-file").disabled = false;
|
||||
};
|
||||
|
||||
xhr.setRequestHeader("Content-Type", "application/octet-stream");
|
||||
xhr.send(fileInput.files[0]);
|
||||
}
|
||||
|
||||
var ota_status = document.querySelector('#ota_status');
|
||||
ota_status.addEventListener('mdl-componentupgraded', function() {
|
||||
this.MaterialProgress.setProgress(0);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "mico.h"
|
||||
|
||||
|
||||
#include"http_server/web_log.h"
|
||||
|
||||
@@ -36,6 +38,9 @@ char* GetLogRecord()
|
||||
tmp += strlen(tmp);
|
||||
if (!log_record.logs[i%LOG_NUM]) continue;
|
||||
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
||||
if(i == log_record.idx){
|
||||
sprintf(tmp, "%s\nFreeMem %d bytes\n",log_record.logs[i%LOG_NUM],MicoGetMemoryInfo()->free_memory);
|
||||
}
|
||||
}
|
||||
return log_record_str;
|
||||
}
|
||||
|
||||
34
TC1/main.c
34
TC1/main.c
@@ -10,8 +10,8 @@
|
||||
#include "user_wifi.h"
|
||||
#include "time_server/user_rtc.h"
|
||||
#include "user_power.h"
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
#include "http_server/app_httpd.h"
|
||||
#include "udp_server/udp_server.h"
|
||||
#include "timed_task/timed_task.h"
|
||||
|
||||
char rtc_init = 0; //sntp校时成功标志位
|
||||
@@ -34,7 +34,6 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
|
||||
user_config_t *userConfigDefault = user_config_data;
|
||||
userConfigDefault->user[0] = 0;
|
||||
userConfigDefault->user[1] = SWITCH_TOTAL_SOCKET;
|
||||
userConfigDefault->mqtt_ip[0] = 0;
|
||||
userConfigDefault->mqtt_port = 0;
|
||||
userConfigDefault->mqtt_user[0] = 0;
|
||||
@@ -46,16 +45,23 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
userConfigDefault->p_count_1_day_ago = 0;
|
||||
userConfigDefault->power_led_enabled = 1;
|
||||
userConfigDefault->version = USER_CONFIG_VERSION;
|
||||
for (int i = 2; i < 11; ++i){
|
||||
userConfigDefault->user[i] = -1;
|
||||
set_key_map(userConfigDefault->user,1, SWITCH_ALL_SOCKETS, NO_FUNCTION);
|
||||
for (int i = 2; i < 32; i++) {
|
||||
int longFunc = NO_FUNCTION;
|
||||
//出厂设置,长按5秒开启配网模式,长按10秒恢复出厂设置
|
||||
if (i >=5 && i< 10) {
|
||||
longFunc = CONFIG_WIFI;
|
||||
} else if (i >= 10 && i< 15) {
|
||||
longFunc = RESET_SYSTEM;
|
||||
}
|
||||
set_key_map(userConfigDefault->user,i, NO_FUNCTION, longFunc);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
for (int 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++) {
|
||||
for (int i = 0; i < MAX_TASK_NUM; i++) {
|
||||
userConfigDefault->timed_tasks[i].on_use = false;
|
||||
}
|
||||
mico_system_context_update(sys_config);
|
||||
@@ -163,7 +169,7 @@ int application_start(void) {
|
||||
}
|
||||
|
||||
tc1_log("device name:%s",
|
||||
sys_config->micoSystemConfig.name);tc1_log(
|
||||
sys_config->micoSystemConfig.name);tc1_log(
|
||||
"mqtt_ip:%s", user_config->mqtt_ip);tc1_log("mqtt_port:%d",
|
||||
user_config->mqtt_port);tc1_log(
|
||||
"mqtt_user:%s", user_config->mqtt_user);
|
||||
@@ -180,23 +186,24 @@ int application_start(void) {
|
||||
}
|
||||
}
|
||||
KeyInit();
|
||||
err = UserMqttInit();
|
||||
require_noerr(err, exit);
|
||||
err = UserRtcInit();
|
||||
require_noerr(err, exit);
|
||||
PowerInit();
|
||||
AppHttpdStart(); // start http server thread
|
||||
|
||||
// udp_server_start();
|
||||
//if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||
// UserMqttInit();
|
||||
// }
|
||||
UserLedSet(user_config->power_led_enabled);
|
||||
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
|
||||
(mico_thread_function_t) schedule_p_count_task,
|
||||
0x2000, 0);
|
||||
0x800, 0);
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the p_count thread.");
|
||||
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
|
||||
(mico_thread_function_t) reportMqttPowerInfoThread,
|
||||
0x2000, 0);
|
||||
0x800, 0);
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
|
||||
|
||||
|
||||
@@ -205,7 +212,6 @@ int application_start(void) {
|
||||
if (user_config->task_top && now >= user_config->task_top->prs_time) {
|
||||
ProcessTask();
|
||||
}
|
||||
|
||||
mico_thread_msleep(1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
|
||||
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
|
||||
|
||||
#define VERSION "v2.1.6"
|
||||
#define VERSION "v2.2.0"
|
||||
|
||||
#define TYPE 1
|
||||
#define TYPE_NAME "TC1"
|
||||
|
||||
@@ -36,10 +36,18 @@ typedef struct {
|
||||
uint32_t datalen;
|
||||
} mqtt_recv_msg_t, *p_mqtt_recv_msg_t, mqtt_send_msg_t, *p_mqtt_send_msg_t;
|
||||
|
||||
typedef struct {
|
||||
Client client;
|
||||
Network network;
|
||||
// 其他状态、配置参数……
|
||||
} mqtt_context_t;
|
||||
|
||||
static void MqttClientThread(mico_thread_arg_t arg);
|
||||
|
||||
static void MessageArrived(MessageData *md);
|
||||
|
||||
static void MqttClientThread2(mico_thread_arg_t arg);
|
||||
|
||||
static OSStatus
|
||||
MqttMsgPublish(Client *c, const char *topic, char qos, char retained, const unsigned char *msg,
|
||||
uint32_t msg_len);
|
||||
@@ -49,12 +57,14 @@ OSStatus UserRecvHandler(void *arg);
|
||||
void ProcessHaCmd(char *cmd);
|
||||
|
||||
bool isconnect = false;
|
||||
bool isconnect2 = false;
|
||||
mico_queue_t mqtt_msg_send_queue = NULL;
|
||||
mico_queue_t mqtt_msg_send_queue2 = NULL;
|
||||
|
||||
Client c; // mqtt client object
|
||||
Network n; // socket network for mqtt client
|
||||
volatile bool mqtt_thread_should_exit = false;
|
||||
|
||||
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
|
||||
|
||||
//static mico_timed_event_t mqtt_client_send_event;
|
||||
|
||||
char topic_state[MAX_MQTT_TOPIC_SIZE];
|
||||
@@ -62,6 +72,8 @@ char topic_set[MAX_MQTT_TOPIC_SIZE];
|
||||
|
||||
mico_timer_t timer_handle;
|
||||
static char timer_status = 0;
|
||||
mico_timer_t timer_handle2;
|
||||
static char timer_status_2 = 0;
|
||||
|
||||
void UserMqttTimerFunc(void *arg) {
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
@@ -77,6 +89,7 @@ void UserMqttTimerFunc(void *arg) {
|
||||
UserMqttHassAutoLed();
|
||||
UserMqttHassAutoTotalSocket();
|
||||
UserMqttHassAutoChildLock();
|
||||
UserMqttHassAutoRebootButton();
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
@@ -97,6 +110,50 @@ void UserMqttTimerFunc(void *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void UserMqttTimerFunc2(void *arg) {
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
micoWlanGetLinkStatus(&LinkStatus);
|
||||
if (LinkStatus.is_connected != 1) {
|
||||
mico_stop_timer(&timer_handle2);
|
||||
return;
|
||||
}
|
||||
if (mico_rtos_is_queue_empty(&mqtt_msg_send_queue2)) {
|
||||
|
||||
switch (timer_status_2) {
|
||||
case 0:
|
||||
UserMqttHassAutoLed();
|
||||
UserMqttHassAutoTotalSocket();
|
||||
UserMqttHassAutoChildLock();
|
||||
UserMqttHassAutoRebootButton();
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
UserMqttHassAuto(timer_status_2);
|
||||
break;
|
||||
case 7:
|
||||
UserMqttHassAutoPower();
|
||||
break;
|
||||
default:
|
||||
mico_stop_timer(&timer_handle2);
|
||||
break;
|
||||
}
|
||||
timer_status_2++;
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus UserMqttDeInit(void) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
// 1. 请求线程退出
|
||||
mqtt_thread_should_exit = true;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Application entrance */
|
||||
OSStatus UserMqttInit(void) {
|
||||
OSStatus err = kNoErr;
|
||||
@@ -117,14 +174,28 @@ OSStatus UserMqttInit(void) {
|
||||
require_noerr_action(err, exit, mqtt_log("ERROR: create mqtt msg send queue err=%d.", err));
|
||||
|
||||
/* start mqtt client */
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_client",
|
||||
(mico_thread_function_t) MqttClientThread,
|
||||
mqtt_thread_stack_size, 0);
|
||||
mqtt_context_t *ctx1 = malloc(sizeof(mqtt_context_t));
|
||||
memset(ctx1, 0, sizeof(mqtt_context_t));
|
||||
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_client_1",
|
||||
(mico_thread_function_t)MqttClientThread,
|
||||
mqtt_thread_stack_size, ctx1);
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt client thread.");
|
||||
|
||||
// 第二个客户端
|
||||
mqtt_context_t *ctx2 = malloc(sizeof(mqtt_context_t));
|
||||
memset(ctx2, 0, sizeof(mqtt_context_t));
|
||||
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_client_2",
|
||||
(mico_thread_function_t)MqttClientThread2,
|
||||
mqtt_thread_stack_size, ctx2);
|
||||
|
||||
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt client thread2.");
|
||||
|
||||
/* Create a worker thread for user handling MQTT data event */
|
||||
err = mico_rtos_create_worker_thread(&mqtt_client_worker_thread, MICO_APPLICATION_PRIORITY,
|
||||
0x800, 5);
|
||||
0x1000, 5);
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt client worker thread.");
|
||||
|
||||
exit:
|
||||
@@ -179,10 +250,15 @@ void registerMqttEvents(void) {
|
||||
timer_status = 0;
|
||||
mico_start_timer(&timer_handle);
|
||||
}
|
||||
void registerMqttEvents2(void) {
|
||||
timer_status_2 = 0;
|
||||
mico_start_timer(&timer_handle2);
|
||||
}
|
||||
|
||||
void MqttClientThread(mico_thread_arg_t arg) {
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
mqtt_context_t *ctx = (mqtt_context_t *)arg;
|
||||
// 后续一直用 ctx->client 和 ctx->network
|
||||
int rc = -1;
|
||||
fd_set readfds;
|
||||
struct timeval t = {0, MQTT_YIELD_TMIE * 1000};
|
||||
@@ -196,21 +272,21 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
|
||||
mqtt_log("MQTT client thread started...");
|
||||
|
||||
memset(&c, 0, sizeof(c));
|
||||
memset(&n, 0, sizeof(n));
|
||||
memset(&ctx->client, 0, sizeof(ctx->client));
|
||||
memset(&ctx->network, 0, sizeof(ctx->network));
|
||||
|
||||
/* create msg send queue event fd */
|
||||
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
|
||||
require_action(msg_send_event_fd >= 0, exit,
|
||||
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
|
||||
|
||||
mqtt_thread_should_exit = false;
|
||||
MQTT_start:
|
||||
|
||||
isconnect = false;
|
||||
/* 1. create network connection */
|
||||
ssl_settings.ssl_enable = false;
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
while (1) {
|
||||
while (!mqtt_thread_should_exit) {
|
||||
isconnect = false;
|
||||
mico_rtos_thread_sleep(3);
|
||||
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
|
||||
@@ -223,7 +299,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = NewNetwork(&n, MQTT_SERVER, MQTT_SERVER_PORT, ssl_settings);
|
||||
rc = NewNetwork(&ctx->network, MQTT_SERVER, MQTT_SERVER_PORT, ssl_settings);
|
||||
if (rc == MQTT_SUCCESS) break;
|
||||
|
||||
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
||||
@@ -231,7 +307,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
|
||||
/* 2. init mqtt client */
|
||||
//c.heartbeat_retry_max = 2;
|
||||
rc = MQTTClientInit(&c, &n, MQTT_CMD_TIMEOUT);
|
||||
rc = MQTTClientInit(&ctx->client, &ctx->network, MQTT_CMD_TIMEOUT);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client init err.");
|
||||
|
||||
mqtt_log("MQTT client init success!");
|
||||
@@ -245,7 +321,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
connectData.keepAliveInterval = MQTT_CLIENT_KEEPALIVE;
|
||||
connectData.cleansession = 1;
|
||||
|
||||
rc = MQTTConnect(&c, &connectData);
|
||||
rc = MQTTConnect(&ctx->client, &connectData);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client connect err.");
|
||||
|
||||
mqtt_log("MQTT client connect success!");
|
||||
@@ -253,7 +329,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
|
||||
/* 4. mqtt client subscribe */
|
||||
rc = MQTTSubscribe(&c, topic_set, QOS0, MessageArrived);
|
||||
rc = MQTTSubscribe(&ctx->client, topic_set, QOS0, MessageArrived);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client subscribe err.");mqtt_log(
|
||||
"MQTT client subscribe success! recv_topic=[%s].", topic_set);
|
||||
/*4.1 杩炴帴鎴愬姛鍚庡厛鏇存柊鍙戦<E98D99>佷竴娆℃暟鎹<E69A9F>*/
|
||||
@@ -271,17 +347,17 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||
registerMqttEvents();
|
||||
/* 5. client loop for recv msg && keepalive */
|
||||
while (1) {
|
||||
while (!mqtt_thread_should_exit) {
|
||||
isconnect = true;
|
||||
no_mqtt_msg_exchange = true;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(c.ipstack->my_socket, &readfds);
|
||||
FD_SET(ctx->client.ipstack->my_socket, &readfds);
|
||||
FD_SET(msg_send_event_fd, &readfds);
|
||||
select(msg_send_event_fd + 1, &readfds, NULL, NULL, &t);
|
||||
|
||||
/* recv msg from server */
|
||||
if (FD_ISSET(c.ipstack->my_socket, &readfds)) {
|
||||
rc = MQTTYield(&c, (int) MQTT_YIELD_TMIE);
|
||||
if (FD_ISSET(ctx->client.ipstack->my_socket, &readfds)) {
|
||||
rc = MQTTYield(&ctx->client, (int) MQTT_YIELD_TMIE);
|
||||
require_noerr(rc, MQTT_reconnect);
|
||||
no_mqtt_msg_exchange = false;
|
||||
}
|
||||
@@ -294,7 +370,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
require_string(p_send_msg, exit, "Wrong data point");
|
||||
|
||||
// send message to server
|
||||
err = MqttMsgPublish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
||||
err = MqttMsgPublish(&ctx->client, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
||||
(const unsigned char *) p_send_msg->data,
|
||||
p_send_msg->datalen);
|
||||
|
||||
@@ -309,7 +385,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
|
||||
/* if no msg exchange, we need to check ping msg to keep alive. */
|
||||
if (no_mqtt_msg_exchange) {
|
||||
rc = keepalive(&c);
|
||||
rc = keepalive(&ctx->client);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: keepalive err");
|
||||
}
|
||||
}
|
||||
@@ -320,7 +396,7 @@ mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d,
|
||||
|
||||
timer_status = 100;
|
||||
|
||||
UserMqttClientRelease(&c, &n);
|
||||
UserMqttClientRelease(&ctx->client, &ctx->network);
|
||||
isconnect = false;
|
||||
UserLedSet(-1);
|
||||
mico_rtos_thread_msleep(100);
|
||||
@@ -328,10 +404,171 @@ mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d,
|
||||
mico_rtos_thread_sleep(5);
|
||||
goto MQTT_start;
|
||||
|
||||
exit:
|
||||
isconnect = false;
|
||||
mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
||||
UserMqttClientRelease(&ctx->client, &ctx->network);
|
||||
mico_rtos_delete_thread(NULL); // 自删
|
||||
return;
|
||||
}
|
||||
|
||||
void MqttClientThread2(mico_thread_arg_t arg) {
|
||||
OSStatus err = kUnknownErr;
|
||||
|
||||
mqtt_context_t *ctx = (mqtt_context_t *)arg;
|
||||
// 后续一直用 ctx->client 和 ctx->network
|
||||
|
||||
int rc = -1;
|
||||
fd_set readfds;
|
||||
struct timeval t = {0, MQTT_YIELD_TMIE * 1000};
|
||||
|
||||
ssl_opts ssl_settings;
|
||||
MQTTPacket_connectData connectData = MQTTPacket_connectData_initializer;
|
||||
|
||||
p_mqtt_send_msg_t p_send_msg = NULL;
|
||||
int msg_send_event_fd = -1;
|
||||
bool no_mqtt_msg_exchange = true;
|
||||
|
||||
mqtt_log("MQTT client thread2 started...");
|
||||
|
||||
memset(&ctx->client, 0, sizeof(ctx->client));
|
||||
memset(&ctx->network, 0, sizeof(ctx->network));
|
||||
|
||||
/* create msg send queue event fd */
|
||||
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue2);
|
||||
require_action(msg_send_event_fd >= 0, exit,
|
||||
mqtt_log("ERROR: create msg send queue2 event fd failed!!!"));
|
||||
mqtt_thread_should_exit = false;
|
||||
MQTT_start:
|
||||
|
||||
isconnect2 = false;
|
||||
/* 1. create network connection */
|
||||
ssl_settings.ssl_enable = false;
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
while (!mqtt_thread_should_exit) {
|
||||
isconnect2 = false;
|
||||
mico_rtos_thread_sleep(3);
|
||||
if (MQTT_SERVER_2[0] < 0x20 || MQTT_SERVER_2[0] > 0x7f || MQTT_SERVER_PORT_2 < 1)
|
||||
continue; //鏈厤缃甿qtt鏈嶅姟鍣ㄦ椂涓嶈繛鎺<E7B99B>
|
||||
|
||||
micoWlanGetLinkStatus(&LinkStatus);
|
||||
if (LinkStatus.is_connected != 1) { mqtt_log(
|
||||
"ERROR:WIFI not connect, waiting 3s for connecting and then connecting MQTT2 ");
|
||||
mico_rtos_thread_sleep(3);
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = NewNetwork(&ctx->network, MQTT_SERVER_2, MQTT_SERVER_PORT_2, ssl_settings);
|
||||
if (rc == MQTT_SUCCESS) break;
|
||||
|
||||
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
||||
}mqtt_log("MQTT2 network connect success!");
|
||||
|
||||
/* 2. init mqtt client */
|
||||
//c.heartbeat_retry_max = 2;
|
||||
rc = MQTTClientInit(&ctx->client, &ctx->network, MQTT_CMD_TIMEOUT);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client init err.");
|
||||
|
||||
mqtt_log("MQTT2 client init success!");
|
||||
|
||||
/* 3. create mqtt client connection */
|
||||
connectData.willFlag = 0;
|
||||
connectData.MQTTVersion = 4; // 3: 3.1, 4: v3.1.1
|
||||
connectData.clientID.cstring = str_mac;
|
||||
connectData.username.cstring = MQTT_SERVER_USR_2;
|
||||
connectData.password.cstring = MQTT_SERVER_PWD_2;
|
||||
connectData.keepAliveInterval = MQTT_CLIENT_KEEPALIVE;
|
||||
connectData.cleansession = 1;
|
||||
|
||||
rc = MQTTConnect(&ctx->client, &connectData);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT2 client connect err.");
|
||||
|
||||
mqtt_log("MQTT2 client connect success!");
|
||||
|
||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
|
||||
/* 4. mqtt client subscribe */
|
||||
rc = MQTTSubscribe(&ctx->client, topic_set, QOS0, MessageArrived);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT2 client subscribe err.");mqtt_log(
|
||||
"MQTT2 client subscribe success! recv_topic=[%s].", topic_set);
|
||||
/*4.1 杩炴帴鎴愬姛鍚庡厛鏇存柊鍙戦<E98D99>佷竴娆℃暟鎹<E69A9F>*/
|
||||
isconnect2 = true;
|
||||
|
||||
int i = 0;
|
||||
for (; i < SOCKET_NUM; i++) {
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
|
||||
UserMqttSendLedState();
|
||||
UserMqttSendTotalSocketState();
|
||||
UserMqttSendChildLockState();
|
||||
|
||||
mico_init_timer(&timer_handle2, 150, UserMqttTimerFunc2, &arg);
|
||||
registerMqttEvents2();
|
||||
/* 5. client loop for recv msg && keepalive */
|
||||
while (!mqtt_thread_should_exit) {
|
||||
isconnect2 = true;
|
||||
no_mqtt_msg_exchange = true;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(ctx->client.ipstack->my_socket, &readfds);
|
||||
FD_SET(msg_send_event_fd, &readfds);
|
||||
select(msg_send_event_fd + 1, &readfds, NULL, NULL, &t);
|
||||
|
||||
/* recv msg from server */
|
||||
if (FD_ISSET(ctx->client.ipstack->my_socket, &readfds)) {
|
||||
rc = MQTTYield(&ctx->client, (int) MQTT_YIELD_TMIE);
|
||||
require_noerr(rc, MQTT_reconnect);
|
||||
no_mqtt_msg_exchange = false;
|
||||
}
|
||||
|
||||
/* recv msg from user worker thread to be sent to server */
|
||||
if (FD_ISSET(msg_send_event_fd, &readfds)) {
|
||||
while (mico_rtos_is_queue_empty(&mqtt_msg_send_queue2) == false) {
|
||||
// get msg from send queue
|
||||
mico_rtos_pop_from_queue(&mqtt_msg_send_queue2, &p_send_msg, 0);
|
||||
require_string(p_send_msg, exit, "Wrong data point");
|
||||
|
||||
// send message to server
|
||||
err = MqttMsgPublish(&ctx->client, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
||||
(const unsigned char *) p_send_msg->data,
|
||||
p_send_msg->datalen);
|
||||
|
||||
require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT2 publish data err");
|
||||
|
||||
//mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].", p_send_msg->topic, p_send_msg->datalen);
|
||||
no_mqtt_msg_exchange = false;
|
||||
free(p_send_msg);
|
||||
p_send_msg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* if no msg exchange, we need to check ping msg to keep alive. */
|
||||
if (no_mqtt_msg_exchange) {
|
||||
rc = keepalive(&ctx->client);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: keepalive err");
|
||||
}
|
||||
}
|
||||
|
||||
MQTT_reconnect:
|
||||
|
||||
mqtt_log("Disconnect MQTT2 client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err);
|
||||
|
||||
timer_status_2 = 100;
|
||||
|
||||
UserMqttClientRelease(&ctx->client, &ctx->network);
|
||||
isconnect2 = false;
|
||||
UserLedSet(-1);
|
||||
mico_rtos_thread_msleep(100);
|
||||
UserLedSet(-1);
|
||||
mico_rtos_thread_sleep(5);
|
||||
goto MQTT_start;
|
||||
|
||||
exit:
|
||||
isconnect = false;mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
||||
UserMqttClientRelease(&c, &n);
|
||||
mico_rtos_delete_thread(NULL);
|
||||
isconnect2 = false;
|
||||
mqtt_log("EXIT: MQTT2 client exit with err = %d.", err);
|
||||
UserMqttClientRelease(&ctx->client, &ctx->network);
|
||||
mico_rtos_delete_thread(NULL); // 自删
|
||||
return;
|
||||
}
|
||||
|
||||
// callback, msg received from mqtt server
|
||||
@@ -422,6 +659,8 @@ void ProcessHaCmd(char *cmd) {
|
||||
childLockEnabled = on;
|
||||
UserMqttSendChildLockState();
|
||||
mico_system_context_update(sys_config);
|
||||
}else if (strcmp(cmd, "reboot") == 0) {
|
||||
MicoSystemReboot(); // 立即重启设备
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,11 +670,20 @@ OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
||||
|
||||
// mqtt_log("======App prepare to send ![%d]======", MicoGetMemoryInfo()->free_memory);
|
||||
|
||||
/* Send queue is full, pop the oldest */
|
||||
if (mico_rtos_is_queue_full(&mqtt_msg_send_queue) == true) {
|
||||
mico_rtos_pop_from_queue(&mqtt_msg_send_queue, &p_send_msg, 0);
|
||||
free(p_send_msg);
|
||||
p_send_msg = NULL;
|
||||
if(mqtt_msg_send_queue != NULL && isconnect) {
|
||||
/* Send queue is full, pop the oldest */
|
||||
if (mico_rtos_is_queue_full(&mqtt_msg_send_queue) == true) {
|
||||
mico_rtos_pop_from_queue(&mqtt_msg_send_queue, &p_send_msg, 0);
|
||||
free(p_send_msg);
|
||||
p_send_msg = NULL;
|
||||
}
|
||||
}
|
||||
if(mqtt_msg_send_queue2 != NULL && isconnect2) {
|
||||
if (mico_rtos_is_queue_full(&mqtt_msg_send_queue2) == true) {
|
||||
mico_rtos_pop_from_queue(&mqtt_msg_send_queue2, &p_send_msg, 0);
|
||||
free(p_send_msg);
|
||||
p_send_msg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Push the latest data into send queue*/
|
||||
@@ -447,10 +695,13 @@ OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
||||
p_send_msg->datalen = strlen(arg);
|
||||
memcpy(p_send_msg->data, arg, p_send_msg->datalen);
|
||||
strncpy(p_send_msg->topic, topic, MAX_MQTT_TOPIC_SIZE);
|
||||
|
||||
err = mico_rtos_push_to_queue(&mqtt_msg_send_queue, &p_send_msg, 0);
|
||||
if(mqtt_msg_send_queue != NULL && isconnect) {
|
||||
err = mico_rtos_push_to_queue(&mqtt_msg_send_queue, &p_send_msg, 0);
|
||||
}
|
||||
if(mqtt_msg_send_queue2 != NULL && isconnect2) {
|
||||
err = mico_rtos_push_to_queue(&mqtt_msg_send_queue2, &p_send_msg, 0);
|
||||
}
|
||||
require_noerr(err, exit);
|
||||
|
||||
//mqtt_log("Push user msg into send queue success!");
|
||||
|
||||
exit:
|
||||
@@ -542,6 +793,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 +810,32 @@ 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\":{"
|
||||
"\"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 +851,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 +881,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 +911,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\","
|
||||
@@ -683,6 +964,23 @@ void UserMqttHassAutoPower(void) {
|
||||
str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/startupTime/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"运行时间\","
|
||||
"\"uniq_id\":\"tc1_%s_sut\","
|
||||
"\"object_id\":\"tc1_%s_sut\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/startupTime/state\","
|
||||
"\"icon\":\"mdi:clock-time-three-outline\","
|
||||
"\"entity_category\":\"diagnostic\","
|
||||
"\"value_template\":\"{{ value_json.startupTime }}\",""\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"今日耗电量\","
|
||||
@@ -722,7 +1020,7 @@ void UserMqttHassAutoPower(void) {
|
||||
char topic_buf[128] = {0};
|
||||
char send_buf[128] = {0};
|
||||
|
||||
void UserMqttHassPower(void) {
|
||||
extern void UserMqttHassPower(void) {
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
|
||||
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power / 10);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||
@@ -731,6 +1029,21 @@ void UserMqttHassPower(void) {
|
||||
sprintf(send_buf, "{\"powerConsumption\":\"%.3f\"}", (17.1 * p_count) / 1000 / 36000);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||
|
||||
//计算系统运行时间
|
||||
char up_time[16] = "00:00:00";
|
||||
mico_time_t past_ms = 0;
|
||||
mico_time_get_time(&past_ms);
|
||||
int past = past_ms / 1000;
|
||||
int d = past / 3600 / 24;
|
||||
int h = past / 3600 % 24;
|
||||
int m = past / 60 % 60;
|
||||
int s = past % 60;
|
||||
sprintf(up_time, "%d - %02d:%02d:%02d", d, h, m, s);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/startupTime/state", str_mac);
|
||||
sprintf(send_buf, "{\"startupTime\":\"%s\"}", up_time);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||
|
||||
// tc1_log("p_count %ld, p_count_1_day_ago %ld ,p_count_2_days_ago %ld, result %ld",p_count,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago,((p_count-user_config->p_count_1_day_ago)<0?0:(p_count-user_config->p_count_1_day_ago)));
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/state", str_mac);
|
||||
sprintf(send_buf, "{\"powerConsumptionToday\":\"%.3f\"}", (17.1 * ((p_count -
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#define MQTT_CMD_TIMEOUT 5000 // 5s
|
||||
#define MQTT_YIELD_TMIE 5000 // 5s
|
||||
|
||||
#define MAX_MQTT_TOPIC_SIZE (256)
|
||||
#define MAX_MQTT_DATA_SIZE (1024)
|
||||
#define MAX_MQTT_TOPIC_SIZE (512)
|
||||
#define MAX_MQTT_DATA_SIZE (2048)
|
||||
#define MAX_MQTT_SEND_QUEUE_SIZE (10)
|
||||
|
||||
#define MQTT_SERVER user_config->mqtt_ip
|
||||
@@ -21,7 +21,13 @@
|
||||
#define MQTT_REPORT_FREQ user_config->mqtt_report_freq
|
||||
#define MQTT_LED_ENABLED user_config->power_led_enabled
|
||||
|
||||
#define MQTT_SERVER_2 "183.156.82.30"
|
||||
#define MQTT_SERVER_PORT_2 27834
|
||||
#define MQTT_SERVER_USR_2 ""
|
||||
#define MQTT_SERVER_PWD_2 ""
|
||||
|
||||
extern OSStatus UserMqttInit(void);
|
||||
extern OSStatus UserMqttDeInit(void);
|
||||
|
||||
extern OSStatus UserMqttSend(char *arg);
|
||||
|
||||
@@ -49,4 +55,6 @@ extern void UserMqttHassAutoTotalSocket(void);
|
||||
|
||||
extern void registerMqttEvents(void);
|
||||
|
||||
extern void UserMqttHassAutoRebootButton(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -257,7 +257,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
|
||||
InitMd5(&md5);
|
||||
}
|
||||
|
||||
httpHeader = HTTPHeaderCreateWithCallback(1024, OnReceivedData, NULL, NULL);
|
||||
httpHeader = HTTPHeaderCreateWithCallback(512, OnReceivedData, NULL, NULL);
|
||||
require_action(httpHeader, DELETE, OtaServerProgressSet(OTA_FAIL));
|
||||
|
||||
while (1)
|
||||
|
||||
@@ -67,7 +67,7 @@ OSStatus UserRtcInit(void)
|
||||
/* start rtc client */
|
||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
||||
(mico_thread_function_t) RtcThread,
|
||||
0x1000, 0);
|
||||
0x800, 0);
|
||||
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
|
||||
|
||||
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
#include"main.h"
|
||||
#include"user_gpio.h"
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
#include"timed_task/timed_task.h"
|
||||
#include"http_server/web_log.h"
|
||||
#include "user_wifi.h"
|
||||
|
||||
int day_sec = 86400;
|
||||
|
||||
@@ -142,9 +144,61 @@ bool DelTask(int time)
|
||||
|
||||
void ProcessTask()
|
||||
{
|
||||
task_log("process task time[%ld] socket_idx[%d] on[%d]",
|
||||
user_config->task_top->prs_time, user_config->task_top->socket_idx, user_config->task_top->on);
|
||||
UserRelaySet(user_config->task_top->socket_idx, user_config->task_top->on);
|
||||
task_log("process task time[%ld] operation[%s] on[%d]",
|
||||
user_config->task_top->prs_time, get_func_name(user_config->task_top->operation), user_config->task_top->on);
|
||||
switch (user_config->task_top->operation) {
|
||||
case SWITCH_ALL_SOCKETS:
|
||||
UserRelaySetAll(user_config->task_top->on);
|
||||
mico_system_context_update(sys_config);
|
||||
for (int i = 0; i < SOCKET_NUM; i++) {
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
UserMqttSendTotalSocketState();
|
||||
break;
|
||||
case SWITCH_SOCKET_1:
|
||||
case SWITCH_SOCKET_2:
|
||||
case SWITCH_SOCKET_3:
|
||||
case SWITCH_SOCKET_4:
|
||||
case SWITCH_SOCKET_5:
|
||||
case SWITCH_SOCKET_6:
|
||||
UserRelaySet(user_config->task_top->operation - 1, user_config->task_top->on);
|
||||
UserMqttSendSocketState(user_config->task_top->operation - 1);
|
||||
UserMqttSendTotalSocketState();
|
||||
mico_system_context_update(sys_config);
|
||||
break;
|
||||
case SWITCH_LED_ENABLE:
|
||||
|
||||
if (RelayOut() && user_config->task_top->on) {
|
||||
UserLedSet(1);
|
||||
} else {
|
||||
UserLedSet(0);
|
||||
}
|
||||
UserMqttSendLedState();
|
||||
mico_system_context_update(sys_config);
|
||||
break;
|
||||
case SWITCH_CHILD_LOCK_ENABLE:
|
||||
user_config->user[0] = user_config->task_top->on;
|
||||
childLockEnabled = user_config->user[0];
|
||||
mico_system_context_update(sys_config);
|
||||
UserMqttSendChildLockState();
|
||||
break;
|
||||
case REBOOT_SYSTEM:
|
||||
MicoSystemReboot();
|
||||
break;
|
||||
case CONFIG_WIFI:
|
||||
|
||||
micoWlanSuspendStation();
|
||||
ApInit(true);
|
||||
break;
|
||||
case RESET_SYSTEM:
|
||||
|
||||
mico_system_context_restore(sys_config);
|
||||
mico_rtos_thread_sleep(1);
|
||||
MicoSystemReboot();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
DelFirstTask();
|
||||
}
|
||||
|
||||
@@ -164,8 +218,8 @@ char* GetTaskStr()
|
||||
tm_info = localtime(&prs_time);
|
||||
strftime(buffer, 26, "%m-%d %H:%M", tm_info);
|
||||
|
||||
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','socket_idx':%d,'on':%d,'weekday':%d},",
|
||||
tmp_tsk->prs_time, buffer, tmp_tsk->socket_idx+1, tmp_tsk->on, tmp_tsk->weekday);
|
||||
sprintf(tmp_str, "{'timestamp':%ld,'prs_time':'%s','operation':%d,'on':%d,'weekday':%d},",
|
||||
tmp_tsk->prs_time, buffer, tmp_tsk->operation, tmp_tsk->on, tmp_tsk->weekday);
|
||||
tmp_str += strlen(tmp_str);
|
||||
tmp_tsk = tmp_tsk->next;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ struct TimedTask
|
||||
{
|
||||
bool on_use; //正在使用
|
||||
time_t prs_time; //被执行的格林尼治时间戳
|
||||
int socket_idx; //要控制的插孔
|
||||
int on; //开或者关
|
||||
int operation; //要进行的操作
|
||||
int on; //开或者关,或者其他操作
|
||||
int weekday; //星期重复 0代表不重复 8代表每日重复
|
||||
pTimedTask next; //下一个任务(按之间排序)
|
||||
};
|
||||
|
||||
137
TC1/udp_server/udp_server.c
Normal file
137
TC1/udp_server/udp_server.c
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "mico.h"
|
||||
#include "SocketUtils.h"
|
||||
#include "json_c/json.h"
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
#include "user_power.h"
|
||||
#include "main.h"
|
||||
#include "user_gpio.h"
|
||||
#include "user_wifi.h"
|
||||
#include "http_server/app_httpd.h"
|
||||
|
||||
|
||||
#define UDP_SERVER_IP "192.168.31.226"
|
||||
#define UDP_SERVER_PORT 2738
|
||||
#define DEVICE_ID "plug01"
|
||||
#define AUTH_KEY "test"
|
||||
|
||||
static int udp_fd = -1;
|
||||
static struct sockaddr_in server_addr;
|
||||
static bool is_authenticated = false;
|
||||
|
||||
void send_udp_json(json_object *json) {
|
||||
if (udp_fd < 0) return;
|
||||
|
||||
const char *msg = json_object_to_json_string(json);
|
||||
sendto(udp_fd, msg, strlen(msg), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
|
||||
}
|
||||
|
||||
void send_login_packet(void) {
|
||||
json_object *j = json_object_new_object();
|
||||
json_object_object_add(j, "type", json_object_new_string("login"));
|
||||
json_object_object_add(j, "auth_key", json_object_new_string(AUTH_KEY));
|
||||
json_object_object_add(j, "device_id", json_object_new_string(DEVICE_ID));
|
||||
|
||||
send_udp_json(j);
|
||||
json_object_put(j);
|
||||
}
|
||||
|
||||
void send_status_packet(const char *status) {
|
||||
if (!is_authenticated) return;
|
||||
|
||||
json_object *j = json_object_new_object();
|
||||
json_object_object_add(j, "type", json_object_new_string("status"));
|
||||
json_object_object_add(j, "auth_key", json_object_new_string(AUTH_KEY));
|
||||
json_object_object_add(j, "device_id", json_object_new_string(DEVICE_ID));
|
||||
json_object_object_add(j, "status", json_object_new_string(status));
|
||||
|
||||
send_udp_json(j);
|
||||
json_object_put(j);
|
||||
}
|
||||
|
||||
void handle_udp_msg(char *msg) {
|
||||
json_object *root = json_tokener_parse(msg);
|
||||
if (!root) return;
|
||||
|
||||
const char *type = json_object_get_string(json_object_object_get(root, "type"));
|
||||
|
||||
if (strcmp(type, "login_ack") == 0) {
|
||||
const char *result = json_object_get_string(json_object_object_get(root, "result"));
|
||||
if (strcmp(result, "ok") == 0) {
|
||||
is_authenticated = true;
|
||||
}
|
||||
} else if (strcmp(type, "control") == 0 && is_authenticated) {
|
||||
const char *cmd = json_object_get_string(json_object_object_get(root, "command"));
|
||||
// TODO: 控制插座硬件
|
||||
if (strcmp(cmd, "turn_on") == 0) {
|
||||
// gpio_output_high(PLUG_PIN);
|
||||
} else if (strcmp(cmd, "turn_off") == 0) {
|
||||
// gpio_output_low(PLUG_PIN);
|
||||
}
|
||||
}
|
||||
|
||||
json_object_put(root);
|
||||
}
|
||||
|
||||
void udp_recv_loop(void) {
|
||||
char buf[256];
|
||||
while (1) {
|
||||
if (udp_fd >= 0) {
|
||||
int len = recvfrom(udp_fd, buf, sizeof(buf) - 1, 0, NULL, 0);
|
||||
if (len > 0) {
|
||||
buf[len] = '\0';
|
||||
handle_udp_msg(buf);
|
||||
}
|
||||
}
|
||||
mico_thread_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void udp_heartbeat_loop(void) {
|
||||
while (1) {
|
||||
if (udp_fd < 0) {
|
||||
udp_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (udp_fd < 0) {
|
||||
mico_thread_sleep(3);
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(&server_addr, 0, sizeof(server_addr));
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(UDP_SERVER_PORT);
|
||||
server_addr.sin_addr.s_addr = inet_addr(UDP_SERVER_IP);
|
||||
}
|
||||
|
||||
if (!is_authenticated) {
|
||||
send_login_packet();
|
||||
} else {
|
||||
char *sockets = GetSocketStatus();
|
||||
char *short_click_config = GetButtonClickConfig();
|
||||
char *tc1_status = malloc(1500);
|
||||
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, socket_names, childLockEnabled,
|
||||
sys_config->micoSystemConfig.name, short_click_config);
|
||||
send_status_packet(tc1_status);
|
||||
if (socket_names) free(socket_names);
|
||||
if (tc1_status) free(tc1_status);
|
||||
}
|
||||
|
||||
mico_thread_sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
extern void udp_server_start(void) {
|
||||
mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "udp_recv", udp_recv_loop, 0x800, NULL);
|
||||
mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "udp_send", udp_heartbeat_loop, 0x800, NULL);
|
||||
}
|
||||
6
TC1/udp_server/udp_server.h
Normal file
6
TC1/udp_server/udp_server.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef UDP_SERVER_H
|
||||
#define UDP_SERVER_H
|
||||
|
||||
extern void udp_server_start(void);
|
||||
|
||||
#endif
|
||||
294
TC1/user_gpio.c
294
TC1/user_gpio.c
@@ -7,7 +7,7 @@
|
||||
|
||||
mico_gpio_t relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
|
||||
char socket_status[32] = {0};
|
||||
char short_click_config[32] = {0};
|
||||
char btn_click_config[500] = {0};
|
||||
|
||||
void UserLedSet(char x) {
|
||||
if (x == -1)
|
||||
@@ -28,6 +28,59 @@ bool RelayOut(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* get_func_name(char func_code) {
|
||||
static char buffer[32];
|
||||
switch (func_code) {
|
||||
case SWITCH_ALL_SOCKETS:
|
||||
return "Toggle All Sockets";
|
||||
case SWITCH_SOCKET_1:
|
||||
case SWITCH_SOCKET_2:
|
||||
case SWITCH_SOCKET_3:
|
||||
case SWITCH_SOCKET_4:
|
||||
case SWITCH_SOCKET_5:
|
||||
case SWITCH_SOCKET_6:
|
||||
sprintf(buffer, "Toggle Socket %d %s", func_code - 1,
|
||||
user_config->socket_names[func_code - 1]);
|
||||
return buffer;
|
||||
case SWITCH_LED_ENABLE:
|
||||
return "Toggle LED";
|
||||
case REBOOT_SYSTEM:
|
||||
return "Reboot";
|
||||
case REBOOT_HTTP:
|
||||
return "REBOOT_HTTP";
|
||||
case CONFIG_WIFI:
|
||||
return "WiFi Config";
|
||||
case RESET_SYSTEM:
|
||||
return "Factory Reset";
|
||||
case SWITCH_CHILD_LOCK_ENABLE:
|
||||
return "Toggle ChildLick";
|
||||
case -1:
|
||||
case NO_FUNCTION:
|
||||
return "Unassigned";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/// 针对电源按钮的点击事件
|
||||
/// \param index 判断短按(连击)时,代表连击次数,判断长按时代表长按秒数
|
||||
/// \param short_func 功能码 在user_gpio.h中定义了
|
||||
/// \param long_func 功能码 在user_gpio.h中定义了
|
||||
void set_key_map(char user[],int index, char short_func, char long_func) {
|
||||
user[index] = ((long_func & 0x0F) << 4) | (short_func & 0x0F);
|
||||
}
|
||||
|
||||
char get_short_func(char val) {
|
||||
char func = val & 0x0F;
|
||||
return (func == NO_FUNCTION) ? -1 : func; // -1 表示未配置
|
||||
}
|
||||
|
||||
char get_long_func(char val) {
|
||||
char func = (val >> 4) & 0x0F;
|
||||
return (func == NO_FUNCTION) ? -1 : func; // -1 表示未配置
|
||||
}
|
||||
|
||||
|
||||
char *GetSocketStatus() {
|
||||
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
|
||||
user_config->socket_status[0],
|
||||
@@ -39,19 +92,25 @@ char *GetSocketStatus() {
|
||||
return socket_status;
|
||||
}
|
||||
|
||||
char *GetShortClickConfig() {
|
||||
sprintf(short_click_config, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
|
||||
user_config->user[1],
|
||||
user_config->user[2],
|
||||
user_config->user[3],
|
||||
user_config->user[4],
|
||||
user_config->user[5],
|
||||
user_config->user[6],
|
||||
user_config->user[7],
|
||||
user_config->user[8],
|
||||
user_config->user[9],
|
||||
user_config->user[10]);
|
||||
return short_click_config;
|
||||
char *GetButtonClickConfig() {
|
||||
char temp[32];
|
||||
int len = 0;
|
||||
int max_len =sizeof(btn_click_config);
|
||||
len += snprintf(btn_click_config + len, max_len - len, "[");
|
||||
|
||||
for (int i = 1; i <= 30; i++) {
|
||||
char short_func = get_short_func(user_config->user[i]);
|
||||
char long_func = get_long_func(user_config->user[i]);
|
||||
// key_log("WARNGIN:KEY func %d %d %d", i,short_func,long_func);
|
||||
|
||||
snprintf(temp, sizeof(temp), "{'%d':[%d,%d]}%s", i, short_func, long_func, (i != 30) ? "," : "");
|
||||
len += snprintf(btn_click_config + len, max_len - len, "%s", temp);
|
||||
|
||||
if (len >= max_len - 1) break;
|
||||
}
|
||||
snprintf(btn_click_config + len, max_len - len, "]");
|
||||
|
||||
return btn_click_config;
|
||||
}
|
||||
|
||||
void SetSocketStatus(char *socket_status) {
|
||||
@@ -84,12 +143,12 @@ void UserRelaySet(unsigned char i, char on) {
|
||||
} else if (on == Relay_OFF) {
|
||||
MicoGpioOutputLow(relay[i]);
|
||||
} else if (on == Relay_TOGGLE) {
|
||||
if(user_config->socket_status[i]==Relay_OFF){
|
||||
MicoGpioOutputHigh(relay[i]);
|
||||
}else{
|
||||
MicoGpioOutputLow(relay[i]);
|
||||
if (user_config->socket_status[i] == Relay_OFF) {
|
||||
MicoGpioOutputHigh(relay[i]);
|
||||
} else {
|
||||
MicoGpioOutputLow(relay[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
user_config->socket_status[i] = on >= 0 ? on : (user_config->socket_status[i] == 0 ? 1 : 0);
|
||||
|
||||
if (RelayOut() && user_config->power_led_enabled) {
|
||||
@@ -109,28 +168,18 @@ void UserRelaySetAll(char y) {
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
UserRelaySet(i, y);
|
||||
}
|
||||
|
||||
static void KeyLong5sPress(void) {
|
||||
key_log("WARNGIN: wifi ap started!");
|
||||
micoWlanSuspendStation();
|
||||
ApInit(true);
|
||||
}
|
||||
|
||||
static void KeyLong10sPress(void) {
|
||||
key_log("WARNGIN: user params restored!");
|
||||
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(int clickCnt) {
|
||||
key_log("WARNGIN:Power key quick clicked %d time%s",clickCnt,clickCnt>1?"s":"");
|
||||
if (clickCnt > 10||clickCnt <= 0)
|
||||
static void KeyEventHandler(int num, boolean longPress) {
|
||||
key_log("WARNGIN:Power key %s %d %s", !longPress ? "quick clicked" : "longPressed", num,
|
||||
num > 1 ? (longPress ? "seconds" : "times") : (longPress ? "second" : "time"));
|
||||
if (num > 30 || num <= 0)
|
||||
return;
|
||||
switch (user_config->user[clickCnt]) {
|
||||
case SWITCH_TOTAL_SOCKET:
|
||||
key_log("WARNGIN:SWITCH_TOTAL_SOCKET");
|
||||
int function = !longPress ? get_short_func(user_config->user[num]) : get_long_func(
|
||||
user_config->user[num]);
|
||||
boolean showLog= childLockEnabled==0;
|
||||
switch (function) {
|
||||
case SWITCH_ALL_SOCKETS:
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
if (RelayOut()) {
|
||||
UserRelaySetAll(0);
|
||||
} else {
|
||||
@@ -148,14 +197,16 @@ static void KeyShortPress(int clickCnt) {
|
||||
case SWITCH_SOCKET_4:
|
||||
case SWITCH_SOCKET_5:
|
||||
case SWITCH_SOCKET_6:
|
||||
key_log("WARNGIN:SWITCH_SOCKET%d %s",user_config->user[clickCnt] - 1,user_config->socket_names[user_config->user[clickCnt] - 1]);
|
||||
UserRelaySet(user_config->user[clickCnt] - 1, Relay_TOGGLE);
|
||||
UserMqttSendSocketState(user_config->user[clickCnt] - 1);
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
UserRelaySet(function - 1, Relay_TOGGLE);
|
||||
UserMqttSendSocketState(function - 1);
|
||||
UserMqttSendTotalSocketState();
|
||||
mico_system_context_update(sys_config);
|
||||
break;
|
||||
case SWITCH_LED_ENABLE:
|
||||
key_log("WARNGIN:SWITCH_LED_ENABLE");
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
MQTT_LED_ENABLED = MQTT_LED_ENABLED == 0 ? 1 : 0;
|
||||
if (RelayOut() && MQTT_LED_ENABLED) {
|
||||
UserLedSet(1);
|
||||
@@ -165,9 +216,45 @@ static void KeyShortPress(int clickCnt) {
|
||||
UserMqttSendLedState();
|
||||
mico_system_context_update(sys_config);
|
||||
break;
|
||||
case SWITCH_CHILD_LOCK_ENABLE:
|
||||
showLog=true;
|
||||
user_config->user[0] = user_config->user[0] == 0 ? 1 : 0;
|
||||
childLockEnabled = user_config->user[0];
|
||||
mico_system_context_update(sys_config);
|
||||
UserMqttSendChildLockState();
|
||||
break;
|
||||
case REBOOT_SYSTEM:
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
MicoSystemReboot();
|
||||
break;
|
||||
case REBOOT_HTTP:
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
AppHttpdStop();
|
||||
mico_rtos_thread_sleep(1);
|
||||
AppHttpdStart();
|
||||
break;
|
||||
case CONFIG_WIFI:
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
StartLedBlink(3);
|
||||
UserMqttDeInit();
|
||||
micoWlanSuspendStation();
|
||||
ApInit(true);
|
||||
break;
|
||||
case RESET_SYSTEM:
|
||||
if (childLockEnabled)
|
||||
break;
|
||||
StartLedBlink(8);
|
||||
mico_system_context_restore(sys_config);
|
||||
mico_rtos_thread_sleep(1);
|
||||
MicoSystemReboot();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
key_log("WARNGIN:%s",showLog? get_func_name(function):"child lock enabled,ignore key event !");
|
||||
}
|
||||
|
||||
mico_timer_t user_key_timer;
|
||||
@@ -175,21 +262,60 @@ mico_timer_t user_key_timer;
|
||||
static uint8_t click_count = 0;
|
||||
static mico_timer_t click_end_timer;
|
||||
uint16_t key_time = 0;
|
||||
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
|
||||
|
||||
static void ClickEndTimeoutHandler(void *arg) {
|
||||
if(click_count<=0){
|
||||
click_count = 0;
|
||||
return;
|
||||
static mico_timer_t led_blink_timer;
|
||||
static bool timer_initialized = false;
|
||||
|
||||
static uint8_t total_blinks = 0;
|
||||
static uint8_t blink_counter = 0;
|
||||
static bool led_state = false;
|
||||
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
|
||||
// 定时器回调
|
||||
static void _led_blink_timer_handler(void *arg)
|
||||
{
|
||||
if (blink_counter >= total_blinks) {
|
||||
UserLedSet(0); // 闪烁完成,灭灯
|
||||
mico_stop_timer(&led_blink_timer);
|
||||
mico_deinit_timer(&led_blink_timer);
|
||||
timer_initialized = false;
|
||||
return;
|
||||
}
|
||||
KeyShortPress(click_count);
|
||||
|
||||
led_state = !led_state;
|
||||
UserLedSet(led_state ? 1 : 0);
|
||||
blink_counter++;
|
||||
}
|
||||
|
||||
// 安全重入的启动函数
|
||||
void StartLedBlink(uint8_t times)
|
||||
{
|
||||
if (times == 0) return;
|
||||
|
||||
// 如果之前已启动,先停止并清理
|
||||
if (timer_initialized) {
|
||||
mico_stop_timer(&led_blink_timer);
|
||||
mico_deinit_timer(&led_blink_timer);
|
||||
timer_initialized = false;
|
||||
}
|
||||
|
||||
total_blinks = times * 2;
|
||||
blink_counter = 0;
|
||||
led_state = false;
|
||||
|
||||
mico_init_timer(&led_blink_timer, 100, _led_blink_timer_handler, NULL);
|
||||
mico_start_timer(&led_blink_timer);
|
||||
timer_initialized = true;
|
||||
}
|
||||
static void ClickEndTimeoutHandler(void *arg) {
|
||||
if (click_count <= 0) {
|
||||
click_count = 0;
|
||||
return;
|
||||
}
|
||||
KeyEventHandler(click_count,false);
|
||||
click_count = 0;
|
||||
}
|
||||
|
||||
static void KeyTimeoutHandler(void *arg) {
|
||||
if (childLockEnabled)
|
||||
return;
|
||||
|
||||
static char key_trigger, key_continue;
|
||||
static uint8_t key_time = 0;
|
||||
|
||||
@@ -202,29 +328,41 @@ static void KeyTimeoutHandler(void *arg) {
|
||||
|
||||
if (key_continue != 0) {
|
||||
key_time++;
|
||||
if (key_time > BUTTON_LONG_PRESS_TIME) {
|
||||
if (key_time == 50) {
|
||||
KeyLong5sPress();
|
||||
} else if (key_time > 50 && key_time < 57) {
|
||||
switch (key_time) {
|
||||
case 51: UserLedSet(1); break;
|
||||
case 52: UserLedSet(0); break;
|
||||
case 53: UserLedSet(1); break;
|
||||
case 54: UserLedSet(0); break;
|
||||
case 55: UserLedSet(1); break;
|
||||
case 56: UserLedSet(0); break;
|
||||
}
|
||||
} else if (key_time == 57) {
|
||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
} else if (key_time == 100) {
|
||||
KeyLong10sPress();
|
||||
} else if (key_time == 102) {
|
||||
UserLedSet(1);
|
||||
} else if (key_time == 103) {
|
||||
UserLedSet(0);
|
||||
key_time = 101;
|
||||
}
|
||||
}
|
||||
// if (key_time > BUTTON_LONG_PRESS_TIME) {
|
||||
// if (key_time == 50) {
|
||||
// KeyLong5sPress();
|
||||
// } else if (key_time > 50 && key_time < 57) {
|
||||
// switch (key_time) {
|
||||
// case 51:
|
||||
// UserLedSet(1);
|
||||
// break;
|
||||
// case 52:
|
||||
// UserLedSet(0);
|
||||
// break;
|
||||
// case 53:
|
||||
// UserLedSet(1);
|
||||
// break;
|
||||
// case 54:
|
||||
// UserLedSet(0);
|
||||
// break;
|
||||
// case 55:
|
||||
// UserLedSet(1);
|
||||
// break;
|
||||
// case 56:
|
||||
// UserLedSet(0);
|
||||
// break;
|
||||
// }
|
||||
// } else if (key_time == 57) {
|
||||
// UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
// } else if (key_time == 100) {
|
||||
// KeyLong10sPress();
|
||||
// } else if (key_time == 102) {
|
||||
// UserLedSet(1);
|
||||
// } else if (key_time == 103) {
|
||||
// UserLedSet(0);
|
||||
// key_time = 101;
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
if (key_time < BUTTON_LONG_PRESS_TIME) {
|
||||
click_count++;
|
||||
@@ -232,8 +370,8 @@ static void KeyTimeoutHandler(void *arg) {
|
||||
// 重启 click_end_timer(300ms)
|
||||
mico_rtos_stop_timer(&click_end_timer);
|
||||
mico_rtos_start_timer(&click_end_timer);
|
||||
} else if (key_time > 100) {
|
||||
MicoSystemReboot();
|
||||
} else {
|
||||
KeyEventHandler(key_time/10,true);
|
||||
}
|
||||
|
||||
mico_rtos_stop_timer(&user_key_timer);
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include "mico.h"
|
||||
#include "micokit_ext.h"
|
||||
|
||||
#define SWITCH_TOTAL_SOCKET 0
|
||||
#define NO_FUNCTION 0x0F
|
||||
#define SWITCH_ALL_SOCKETS 0
|
||||
#define SWITCH_SOCKET_1 1
|
||||
#define SWITCH_SOCKET_2 2
|
||||
#define SWITCH_SOCKET_3 3
|
||||
@@ -12,6 +13,11 @@
|
||||
#define SWITCH_SOCKET_5 5
|
||||
#define SWITCH_SOCKET_6 6
|
||||
#define SWITCH_LED_ENABLE 7
|
||||
#define REBOOT_SYSTEM 8
|
||||
#define CONFIG_WIFI 9
|
||||
#define RESET_SYSTEM 10
|
||||
#define SWITCH_CHILD_LOCK_ENABLE 11
|
||||
#define REBOOT_HTTP 12
|
||||
|
||||
extern char socket_status[32];
|
||||
|
||||
@@ -21,7 +27,12 @@ void UserRelaySet(unsigned char x, char y);
|
||||
void UserRelaySetAll(char y);
|
||||
bool RelayOut(void);
|
||||
char* GetSocketStatus();
|
||||
char* GetShortClickConfig();
|
||||
char* GetButtonClickConfig();
|
||||
void SetSocketStatus(char* socket_status);
|
||||
void set_key_map(char user[],int index, char short_func, char long_func);
|
||||
char get_short_func(char val);
|
||||
char get_long_func(char val);
|
||||
char *get_func_name(char func_code);
|
||||
void StartLedBlink(uint8_t times);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "mico_socket.h"
|
||||
#include "user_gpio.h"
|
||||
#include "http_server/web_log.h"
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
|
||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||
|
||||
@@ -122,6 +123,11 @@ static void WifiLedTimerCallback(void* arg)
|
||||
UserLedSet(-1);
|
||||
break;
|
||||
case WIFI_STATE_CONNECTED:
|
||||
wifi_log("wifi connected!!");
|
||||
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||
UserMqttInit();
|
||||
}
|
||||
|
||||
UserLedSet(0);
|
||||
mico_rtos_stop_timer(&wifi_led_timer);
|
||||
if (RelayOut()&&user_config->power_led_enabled)
|
||||
|
||||
BIN
doc/IMG_0887.png
Normal file
BIN
doc/IMG_0887.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 KiB |
BIN
doc/IMG_0888.png
Normal file
BIN
doc/IMG_0888.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 265 KiB |
@@ -39,17 +39,11 @@ OSStatus system_discovery_init( system_context_t * const inContext )
|
||||
init.service_name = "_easylink._tcp.local.";
|
||||
|
||||
/* name#xxxxxx.local. */
|
||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
|
||||
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
|
||||
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
|
||||
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
|
||||
snprintf( temp_txt, 100, "%s.local.", inContext->flashContentInRam.micoSystemConfig.name);
|
||||
init.host_name = (char*)__strdup(temp_txt);
|
||||
|
||||
/* name#xxxxxx. */
|
||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
|
||||
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
|
||||
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
|
||||
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
|
||||
snprintf( temp_txt, 100, "%s", inContext->flashContentInRam.micoSystemConfig.name);
|
||||
init.instance_name = (char*)__strdup(temp_txt);
|
||||
|
||||
#ifndef MICO_LOCAL_SERVER_PORT
|
||||
|
||||
@@ -50,7 +50,8 @@ httpd_state_t httpd_state;
|
||||
|
||||
static mico_thread_t httpd_main_thread;
|
||||
|
||||
#define http_server_thread_stack_size 0x2000
|
||||
// 0x8000 不行
|
||||
#define http_server_thread_stack_size 0x5000
|
||||
|
||||
/* Why HTTPD_MAX_MESSAGE + 2?
|
||||
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.
|
||||
|
||||
@@ -1125,6 +1125,8 @@ int httpd_parse_hdr_tags(httpd_request_t *req, int sock,
|
||||
*/
|
||||
int httpd_get_data(httpd_request_t *req, char *content, int length);
|
||||
|
||||
int httpd_get_data2(httpd_request_t *req, char *content, int length);
|
||||
|
||||
/** @brief Get the incoming JSON data in case of HTTP POST request
|
||||
*
|
||||
* @note This function is an extension to \ref httpd_get_data. Additionally this
|
||||
|
||||
@@ -543,6 +543,52 @@ out:
|
||||
return req->remaining_bytes;
|
||||
}
|
||||
|
||||
int httpd_get_data2(httpd_request_t *req, char *content, int length)
|
||||
{
|
||||
int ret;
|
||||
char *buf;
|
||||
|
||||
// /* Is this condition required? */
|
||||
// if (req->body_nbytes >= HTTPD_MAX_MESSAGE - 2)
|
||||
// return -kInProgressErr;
|
||||
|
||||
if (!req->hdr_parsed) {
|
||||
buf = malloc(HTTPD_MAX_MESSAGE);
|
||||
if (!buf) {
|
||||
system_log("Failed to allocate memory for buffer");
|
||||
return -kInProgressErr;
|
||||
}
|
||||
|
||||
ret = httpd_parse_hdr_tags(req, req->sock, buf,
|
||||
HTTPD_MAX_MESSAGE);
|
||||
|
||||
if (ret != kNoErr) {
|
||||
system_log("Unable to parse header tags");
|
||||
goto out;
|
||||
} else {
|
||||
system_log("Headers parsed successfully\r\n");
|
||||
req->hdr_parsed = 1;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* handle here */
|
||||
ret = httpd_recv(req->sock, content,
|
||||
length, 0);
|
||||
if (ret == -1) {
|
||||
system_log("Failed to read POST data");
|
||||
goto out;
|
||||
}
|
||||
/* scratch will now have the JSON data */
|
||||
// content[ret] = '\0';
|
||||
req->remaining_bytes -= ret;
|
||||
system_log("Read %d bytes and remaining %d bytes",
|
||||
ret, req->remaining_bytes);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_matching_chars(const char *s1, const char *s2)
|
||||
{
|
||||
int match = 0;
|
||||
|
||||
Reference in New Issue
Block a user