mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-15 14:23:18 +08:00
Merge branch 'oopuuu:master' into master
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -2,7 +2,4 @@
|
||||
~*
|
||||
build
|
||||
zTC1.*
|
||||
*.bin
|
||||
*.rar
|
||||
|
||||
TC1/http_server/web/assets/*
|
||||
*.rar
|
||||
@@ -52,6 +52,7 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
||||
|
||||
- [x] HomeAssistant中增加总耗电量传感器,今日耗电量传感器,昨日耗电量传感器,数据来自于插座历史统计
|
||||
- [x] 可以设置mqtt数据上报频率,默认2秒
|
||||
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
|
||||
|
||||
# 编译固件
|
||||
|
||||
|
||||
@@ -427,6 +427,7 @@ static int LedSetEnabled(httpd_request_t *req) {
|
||||
} else {
|
||||
UserLedSet(0);
|
||||
}
|
||||
UserMqttSendLedState();
|
||||
mico_system_context_update(sys_config);
|
||||
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
@@ -795,7 +795,7 @@
|
||||
HttpPost("/socket", function (re) {
|
||||
}, sockets_st);
|
||||
HttpPost("/led", function (re) {
|
||||
}, checkboxs[0].checked ? 1 : 0);
|
||||
}, checkboxs[0].checked ? "1" : "0");
|
||||
});
|
||||
//Socket-end
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
34
TC1/main.c
34
TC1/main.c
@@ -16,6 +16,7 @@
|
||||
char rtc_init = 0; //sntp校时成功标志位
|
||||
uint32_t total_time = 0;
|
||||
char str_mac[16] = {0};
|
||||
time_t last_check_time = 0;
|
||||
|
||||
system_config_t *sys_config;
|
||||
user_config_t *user_config;
|
||||
@@ -58,16 +59,31 @@ void recordDailyPCount() {
|
||||
time_t now;
|
||||
time(&now);
|
||||
struct tm *current_time = localtime(&now);
|
||||
if (current_time->tm_hour != 0 || current_time->tm_min != 0) {
|
||||
return;
|
||||
// 判断上次检查的时间与当前时间的日期是否不同
|
||||
if (last_check_time != 0) {
|
||||
struct tm *last_check_time_tm = localtime(&last_check_time);
|
||||
|
||||
// 如果日期发生变化(即跨天了),则进行记录
|
||||
if (current_time->tm_year != last_check_time_tm->tm_year ||
|
||||
current_time->tm_mon != last_check_time_tm->tm_mon ||
|
||||
current_time->tm_mday != last_check_time_tm->tm_mday) {
|
||||
// 记录数据
|
||||
if (user_config->p_count_1_day_ago != 0) {
|
||||
user_config->p_count_2_days_ago = user_config->p_count_1_day_ago;
|
||||
}
|
||||
user_config->p_count_1_day_ago = p_count;
|
||||
|
||||
// 更新系统配置
|
||||
mico_system_context_update(sys_config);
|
||||
|
||||
tc1_log("WARNGIN: p_count record! p_count_1_day_ago:%d p_count_2_days_ago:%d",
|
||||
user_config->p_count_1_day_ago, user_config->p_count_2_days_ago);
|
||||
}
|
||||
}
|
||||
if (user_config->p_count_1_day_ago != 0) {
|
||||
user_config->p_count_2_days_ago = user_config->p_count_1_day_ago;
|
||||
}
|
||||
user_config->p_count_1_day_ago = p_count;
|
||||
mico_system_context_update(sys_config);tc1_log(
|
||||
"WARNGIN: p_count record! p_count_1_day_ago:%d p_count_2_days_ago:%d",
|
||||
user_config->p_count_1_day_ago, user_config->p_count_2_days_ago);
|
||||
|
||||
// 更新上次检查时间
|
||||
last_check_time = now;
|
||||
|
||||
}
|
||||
|
||||
void schedule_p_count_task(mico_thread_arg_t arg) {
|
||||
|
||||
@@ -69,9 +69,12 @@ void UserMqttTimerFunc(void *arg)
|
||||
}
|
||||
if (mico_rtos_is_queue_empty(&mqtt_msg_send_queue))
|
||||
{
|
||||
timer_status++;
|
||||
|
||||
switch (timer_status)
|
||||
{
|
||||
case 0:
|
||||
UserMqttHassAutoLed();
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
@@ -87,6 +90,7 @@ void UserMqttTimerFunc(void *arg)
|
||||
mico_stop_timer(&timer_handle);
|
||||
break;
|
||||
}
|
||||
timer_status++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +249,8 @@ void MqttClientThread(mico_thread_arg_t arg)
|
||||
|
||||
mqtt_log("MQTT client connect success!");
|
||||
|
||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
|
||||
/* 4. mqtt client subscribe */
|
||||
rc = MQTTSubscribe(&c, topic_set, QOS0, MessageArrived);
|
||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client subscribe err.");
|
||||
@@ -258,6 +264,8 @@ void MqttClientThread(mico_thread_arg_t arg)
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
|
||||
UserMqttSendLedState();
|
||||
|
||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||
mico_start_timer(&timer_handle);
|
||||
/* 5. client loop for recv msg && keepalive */
|
||||
@@ -391,6 +399,19 @@ void ProcessHaCmd(char* cmd)
|
||||
UserRelaySet(i, on);
|
||||
UserMqttSendSocketState(i);
|
||||
mico_system_context_update(sys_config);
|
||||
}else if(strcmp(cmd, "set led") == ' '){
|
||||
int on;
|
||||
sscanf(cmd, "set led %s %d", mac, &on);
|
||||
if (strcmp(mac, str_mac)) return;
|
||||
mqtt_log("set led on[%d]", on);
|
||||
user_config->power_led_enabled = on;
|
||||
if (RelayOut() && user_config->power_led_enabled) {
|
||||
UserLedSet(1);
|
||||
} else {
|
||||
UserLedSet(0);
|
||||
}
|
||||
UserMqttSendLedState();
|
||||
mico_system_context_update(sys_config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,6 +474,23 @@ OSStatus UserMqttSendSocketState(char socket_id)
|
||||
return oss_status;
|
||||
}
|
||||
|
||||
OSStatus UserMqttSendLedState(void)
|
||||
{
|
||||
char *send_buf = malloc(64);
|
||||
char *topic_buf = malloc(64);
|
||||
OSStatus oss_status = kUnknownErr;
|
||||
if (send_buf != NULL && topic_buf != NULL)
|
||||
{
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/led/state", str_mac);
|
||||
sprintf(send_buf, "set led %s %d", str_mac, (int)user_config->power_led_enabled);
|
||||
oss_status = UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf) free(send_buf);
|
||||
if (topic_buf) free(topic_buf);
|
||||
|
||||
return oss_status;
|
||||
}
|
||||
|
||||
//hass mqtt鑷姩鍙戠幇鏁版嵁寮<E5B581>鍏冲彂閫<E5BD82>
|
||||
void UserMqttHassAuto(char socket_id)
|
||||
{
|
||||
@@ -479,6 +517,33 @@ void UserMqttHassAuto(char socket_id)
|
||||
if (topic_buf)
|
||||
free(topic_buf);
|
||||
}
|
||||
|
||||
void UserMqttHassAutoLed(void)
|
||||
{
|
||||
char *send_buf = NULL;
|
||||
char *topic_buf = NULL;
|
||||
send_buf = (char *) malloc(300);
|
||||
topic_buf = (char *) malloc(64);
|
||||
if (send_buf != NULL && topic_buf != NULL)
|
||||
{
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
|
||||
sprintf(send_buf, "set led %s %d", str_mac, (int)user_config->power_led_enabled);
|
||||
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"TC1_%s_Led\","
|
||||
"\"uniq_id\":\"%s_led\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/led/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
"\"pl_on\":\"set led %s 1\","
|
||||
"\"pl_off\":\"set led %s 0\"}",
|
||||
str_mac+8, str_mac, str_mac, str_mac,str_mac);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
free(send_buf);
|
||||
if (topic_buf)
|
||||
free(topic_buf);
|
||||
}
|
||||
//hass mqtt鑷姩鍙戠幇鏁版嵁鍔熺巼鍙戦<E98D99><E688A6>
|
||||
void UserMqttHassAutoPower(void)
|
||||
{
|
||||
|
||||
@@ -29,10 +29,14 @@ extern bool UserMqttIsConnect(void);
|
||||
|
||||
extern OSStatus UserMqttSendSocketState(char socket_id);
|
||||
|
||||
extern OSStatus UserMqttSendLedState(void);
|
||||
|
||||
extern void UserMqttHassAuto(char socket_id);
|
||||
|
||||
extern void UserMqttHassPower(void);
|
||||
|
||||
extern void UserMqttHassAutoPower(void);
|
||||
|
||||
extern void UserMqttHassAutoLed(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -124,7 +124,7 @@ static void WifiLedTimerCallback(void* arg)
|
||||
case WIFI_STATE_CONNECTED:
|
||||
UserLedSet(0);
|
||||
mico_rtos_stop_timer(&wifi_led_timer);
|
||||
if (RelayOut())
|
||||
if (RelayOut()&&user_config->power_led_enabled)
|
||||
UserLedSet(1);
|
||||
else
|
||||
UserLedSet(0);
|
||||
|
||||
11
build.sh
11
build.sh
@@ -1,8 +1,11 @@
|
||||
cd ./TC1/http_server
|
||||
|
||||
python ./test.py > web_data.c
|
||||
|
||||
cd ../..
|
||||
|
||||
mico make clean
|
||||
|
||||
mico make TC1@MK3031@moc
|
||||
mico make TC1@MK3031@moc total
|
||||
|
||||
mico make TC1@MK3031@moc download run
|
||||
|
||||
mico make TC1@MK3031@moc total download run
|
||||
cp ./build/TC1\@MK3031\@moc/binary/TC1\@MK3031\@moc.ota.bin ./build/TC1\@MK3031\@moc/binary/ota.bin
|
||||
|
||||
BIN
mico-os/MiCO/core/rf_driver/MARVELL_sd8801_P34.bin
Normal file
BIN
mico-os/MiCO/core/rf_driver/MARVELL_sd8801_P34.bin
Normal file
Binary file not shown.
BIN
mico-os/MiCO/core/rf_driver/MARVELL_sd8801_P70.bin
Normal file
BIN
mico-os/MiCO/core/rf_driver/MARVELL_sd8801_P70.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MW3xx/merge/boot2.bin
Normal file
BIN
mico-os/platform/MCU/MW3xx/merge/boot2.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MW3xx/merge/mw30x_uapsta_14.76.36.p84.bin
Normal file
BIN
mico-os/platform/MCU/MW3xx/merge/mw30x_uapsta_14.76.36.p84.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MW3xx/merge/uart_wifi_bridge.bin
Normal file
BIN
mico-os/platform/MCU/MW3xx/merge/uart_wifi_bridge.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/Bootloader_3088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/Bootloader_3088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/Bootloader_5088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/Bootloader_5088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/ate_3088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/ate_3088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/ate_5088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/ate_5088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/iperf_3088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/iperf_3088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1101/ATE/iperf_5088.bin
Normal file
BIN
mico-os/platform/MCU/MX1101/ATE/iperf_5088.bin
Normal file
Binary file not shown.
BIN
mico-os/platform/MCU/MX1290/merge/ate.bin
Normal file
BIN
mico-os/platform/MCU/MX1290/merge/ate.bin
Normal file
Binary file not shown.
0
mico-os/resources/ate_firmware/3165/ate.bin
Normal file
0
mico-os/resources/ate_firmware/3165/ate.bin
Normal file
BIN
mico-os/resources/ate_firmware/3166/ate.bin
Normal file
BIN
mico-os/resources/ate_firmware/3166/ate.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/bt_patch/43438/43438A0.bin
Normal file
BIN
mico-os/resources/bt_patch/43438/43438A0.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/bt_patch/43438/43438A1.bin
Normal file
BIN
mico-os/resources/bt_patch/43438/43438A1.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3031/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3031/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3031B/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3031B/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3031_ipv6/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3031_ipv6/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3031ent/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3031ent/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3080B/boot.bin
Normal file
BIN
mico-os/resources/moc_kernel/3080B/boot.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3080B/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3080B/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3080C/boot.bin
Normal file
BIN
mico-os/resources/moc_kernel/3080C/boot.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/3080C/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/3080C/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/5031/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/5031/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/5080/boot.bin
Normal file
BIN
mico-os/resources/moc_kernel/5080/boot.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/moc_kernel/5080/kernel.bin
Normal file
BIN
mico-os/resources/moc_kernel/5080/kernel.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.10.bin
Normal file
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.10.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.12.bin
Normal file
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.12.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.15.bin
Normal file
BIN
mico-os/resources/wifi_firmware/43362/43362A2-5.90.230.15.bin
Normal file
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/43431/43341B0.bin
Normal file
BIN
mico-os/resources/wifi_firmware/43431/43341B0.bin
Normal file
Binary file not shown.
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/43438/43438A1-7.45.45.17.bin
Normal file
BIN
mico-os/resources/wifi_firmware/43438/43438A1-7.45.45.17.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mico-os/resources/wifi_firmware/w8801/w8801B0-14.76.36.p70.bin
Normal file
BIN
mico-os/resources/wifi_firmware/w8801/w8801B0-14.76.36.p70.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user