From 412342efe8228430fb893f36536435281fa17af4 Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Sun, 16 Feb 2020 19:04:10 +0800 Subject: [PATCH] mqtt real_time_power --- TC1/main.c | 8 ++++---- TC1/main.h | 2 +- TC1/mqtt_server/user_function.c | 4 ++-- TC1/mqtt_server/user_mqtt_client.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/TC1/main.c b/TC1/main.c index d8777be..6bc3b8d 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -15,7 +15,7 @@ char rtc_init = 0; //sntp校时成功标志位 uint32_t total_time = 0; char str_mac[16] = { 0 }; -uint32_t power = 0; +uint32_t real_time_power = 0; system_config_t* sys_config; user_config_t* user_config; @@ -146,11 +146,11 @@ int application_start(void) while (1) { //发送功率数据 - uint32_t power2 = 171 * (p_count - last_p_count) / 10; + real_time_power = 171 * (p_count - last_p_count) / 10; last_p_count = p_count; - //SetPowerRecord(&power_record, power2); + //SetPowerRecord(&power_record, real_time_power); sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%u.%u\",\"total_time\":%u}", - str_mac, (unsigned int)(power2 / 10), (unsigned int)(power2 % 10), (unsigned int)total_time); + str_mac, (unsigned int)(real_time_power/10), (unsigned int)(real_time_power%10), (unsigned int)total_time); UserSend(0, power_buf); UserMqttHassPower(); diff --git a/TC1/main.h b/TC1/main.h index 69a8b3d..248a214 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -54,7 +54,7 @@ typedef struct extern char rtc_init; extern uint32_t total_time; extern char str_mac[16]; -extern uint32_t power; +extern uint32_t real_time_power; extern system_config_t* sys_config; extern user_config_t* user_config; extern char socket_status[32]; diff --git a/TC1/mqtt_server/user_function.c b/TC1/mqtt_server/user_function.c index 65ed087..64a4cab 100644 --- a/TC1/mqtt_server/user_function.c +++ b/TC1/mqtt_server/user_function.c @@ -99,11 +99,11 @@ void UserFunctionCmdReceived(int udp_flag, char* pusrdata) char *temp_buf = malloc(16); if (temp_buf != NULL) { - sprintf(temp_buf, "%d.%d", (int)(power/10), (int)(power%10)); + sprintf(temp_buf, "%d.%d", (int)(real_time_power/10), (int)(real_time_power%10)); cJSON_AddStringToObject(json_send, "power", temp_buf); free(temp_buf); } - os_log("power:%d", (int)power); + os_log("power:%d", (int)real_time_power); } //解析主机setting----------------------------------------------------------------- cJSON *p_setting = cJSON_GetObjectItem(pJsonRoot, "setting"); diff --git a/TC1/mqtt_server/user_mqtt_client.c b/TC1/mqtt_server/user_mqtt_client.c index 55a0aab..807f23a 100644 --- a/TC1/mqtt_server/user_mqtt_client.c +++ b/TC1/mqtt_server/user_mqtt_client.c @@ -621,7 +621,7 @@ void UserMqttHassPower(void) if (send_buf != NULL && topic_buf != NULL) { sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac); - sprintf(send_buf, "{\"power\":\"%d.%d\"}", (int)(power/10), (int)(power%10)); + sprintf(send_buf, "{\"power\":\"%d.%d\"}", (int)(real_time_power/10), (int)(real_time_power%10)); UserMqttSendTopic(topic_buf, send_buf, 0); } if (send_buf) free(send_buf);