fix:hass自动发现功率id异常的问题

This commit is contained in:
Zip
2019-04-16 08:53:58 +08:00
parent d8b424f653
commit f71271b267
4 changed files with 72 additions and 69 deletions

View File

@@ -103,6 +103,8 @@ static uint8_t status = 0;
void user_mqtt_timer_func( void *arg )
{
uint8_t *buf1 = NULL;
if ( mico_rtos_is_queue_empty( &mqtt_msg_send_queue ) == true )
{
status++;
switch ( status )
{
@@ -166,6 +168,7 @@ void user_mqtt_timer_func( void *arg )
// mico_deinit_timer( &timer_handle );
break;
}
}
}
/* Application entrance */
@@ -398,7 +401,7 @@ void mqtt_client_thread( mico_thread_arg_t arg )
mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err );
if (&timer_handle !=NULL && mico_rtos_is_timer_running( &timer_handle ) )
if ( &timer_handle != NULL && mico_rtos_is_timer_running( &timer_handle ) )
{
mico_stop_timer( &timer_handle );
// mico_deinit_timer( &timer_handle );
@@ -622,7 +625,7 @@ void user_mqtt_hass_auto_power_name( void )
send_buf[16] = 0xe7;
send_buf[17] = 0x8e;
send_buf[18] = 0x87;
user_mqtt_send_topic( topic_buf, send_buf, 1 );
user_mqtt_send_topic( topic_buf, send_buf, 0 );
}
if ( send_buf )
free( send_buf );

View File

@@ -115,6 +115,7 @@ void rtc_thread( mico_thread_arg_t arg )
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;
@@ -139,13 +140,12 @@ void rtc_thread( mico_thread_arg_t arg )
mico_time_get_utc_time( &utc_time );
utc_time += 28800;
if(utc_time_last!=utc_time)
if ( utc_time_last != utc_time )
{
utc_time_last==utc_time;
utc_time_last == utc_time;
total_time++;
}
struct tm * currentTime = localtime( (const time_t *) &utc_time );
rtc_time.sec = currentTime->tm_sec;
rtc_time.min = currentTime->tm_min;
@@ -255,19 +255,19 @@ void rtc_thread( mico_thread_arg_t arg )
}
//<2F><><EFBFBD>͹<EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ( power_last != power )
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 ); //
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 );
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();
user_mqtt_hass_power( );
}
mico_rtos_thread_msleep( 900 );