diff --git a/TC1/main.c b/TC1/main.c index 8ebb1c9..1aff275 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -75,6 +75,8 @@ int application_start( void ) int i; os_log( "Start %s",VERSION ); + uint8_t main_num=0; + uint32_t power_last = 0xffffffff; OSStatus err = kNoErr; // for ( i = 0; i < Relay_NUM; i++ ) @@ -163,13 +165,24 @@ int application_start( void ) // app_httpd_start(); while ( 1 ) { -// mico_thread_msleep(500); -// MicoGpioOutputTrigger(MICO_GPIO_5); -// mico_gpio_output_toggle( MICO_SYS_LED ); -// mico_rtos_delay_milliseconds(1000); -// uint32_t a=mico_nanosecond_clock_value(); -// os_log("nano=%lu",a/1000); -// mico_rtos_delay_milliseconds(1000); + main_num++; + //发送功率数据 + if ( power_last != power || main_num>4 ) + { + power_last = power; + main_num =0; + uint8_t *power_buf = NULL; + power_buf = malloc( 128 ); + if ( power_buf != NULL ) + { + sprintf( power_buf, "{\"mac\":\"%s\",\"power\":\"%d.%d\",\"total_time\":%d}", strMac, power / 10, power % 10, total_time ); + user_send( 0, power_buf ); + free( power_buf ); + } + user_mqtt_hass_power( ); + } + mico_thread_msleep(1000); + } exit: os_log("application_start ERROR!"); diff --git a/TC1/user_function.c b/TC1/user_function.c index 08153b2..9046806 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -16,10 +16,8 @@ void user_function_set_last_time( ) last_time = UpTicks( ); } - - bool json_plug_analysis( int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON * pJsonSend ); -bool json_plug_task_analysis(unsigned char x, unsigned char y, cJSON * pJsonRoot, cJSON * pJsonSend ); +bool json_plug_task_analysis( unsigned char x, unsigned char y, cJSON * pJsonRoot, cJSON * pJsonSend ); void user_send( int udp_flag, char *s ) { @@ -84,6 +82,25 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) os_log("version:%s",VERSION); cJSON_AddStringToObject( json_send, "version", VERSION ); } + //解析运行时间 + cJSON *p_total_time = cJSON_GetObjectItem( pJsonRoot, "total_time" ); + if ( p_total_time ) + { + cJSON_AddNumberToObject( json_send, "total_time", total_time ); + } + //解析功率 + cJSON *p_power = cJSON_GetObjectItem( pJsonRoot, "power" ); + if ( p_power ) + { + uint8_t *temp_buf = malloc( 16 ); + if ( temp_buf != NULL ) + { + sprintf( temp_buf, "%d.%d", power / 10, power % 10 ); + cJSON_AddStringToObject( json_send, "power", temp_buf ); + free( temp_buf ); + } + os_log("power:%d",power); + } //解析主机setting----------------------------------------------------------------- cJSON *p_setting = cJSON_GetObjectItem( pJsonRoot, "setting" ); if ( p_setting ) @@ -137,7 +154,6 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) sprintf( user_config->mqtt_password, p_mqtt_password->valuestring ); } - //开发返回数据 //返回设备ota if ( p_ota ) cJSON_AddStringToObject( json_setting_send, "ota", p_ota->valuestring ); @@ -165,7 +181,6 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) cJSON_AddStringToObject( json_send, "name", sys_config->micoSystemConfig.name ); - if ( return_flag == true ) { char *json_str = cJSON_Print( json_send ); @@ -216,7 +231,7 @@ bool json_plug_analysis( int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON user_relay_set( x, p_plug_on->valueint ); return_flag = true; } - user_mqtt_send_plug_state(x); + user_mqtt_send_plug_state( x ); } //解析plug中setting项目---------------------------------------------- @@ -232,7 +247,7 @@ bool json_plug_analysis( int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON { return_flag = true; sprintf( user_config->plug[x].name, p_plug_setting_name->valuestring ); - user_mqtt_hass_auto(x); + user_mqtt_hass_auto( x ); } cJSON_AddStringToObject( json_plug_setting_send, "name", user_config->plug[x].name ); } diff --git a/TC1/user_rtc.c b/TC1/user_rtc.c index e911579..c5d8f51 100644 --- a/TC1/user_rtc.c +++ b/TC1/user_rtc.c @@ -114,8 +114,7 @@ void rtc_thread( mico_thread_arg_t arg ) OSStatus err = kUnknownErr; LinkStatusTypeDef LinkStatus; mico_rtc_time_t rtc_time; - uint32_t power_last = 0xffffffff; - uint32_t total_time_last = 0xffffffff; + mico_utc_time_t utc_time; mico_utc_time_t utc_time_last; @@ -127,6 +126,7 @@ void rtc_thread( mico_thread_arg_t arg ) err = user_sntp_get_time( ); if ( err == kNoErr ) { + os_log("sntp success!"); rtc_init = 1; break; } @@ -254,21 +254,7 @@ void rtc_thread( mico_thread_arg_t arg ) } } - //发送功率数据 - if ( power_last != power || total_time - total_time_last > 4 ) - { - power_last = power; - total_time_last = total_time; - uint8_t *power_buf = NULL; - power_buf = malloc( 128 ); - if ( power_buf != NULL ) - { - sprintf( power_buf, "{\"mac\":\"%s\",\"power\":\"%d.%d\",\"total_time\":%d}", strMac, power / 10, power % 10, total_time ); - user_send( 0, power_buf ); - free( power_buf ); - } - user_mqtt_hass_power( ); - } + mico_rtos_thread_msleep( 900 ); } diff --git a/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin b/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin index d134aeb..4e30daf 100644 Binary files a/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin and b/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin differ diff --git a/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin b/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin index 1853fc9..7075c9c 100644 Binary files a/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin and b/build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin differ