mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 13:08:13 +08:00
fix:修复当smtp失败时无法发送功率数据的问题
This commit is contained in:
27
TC1/main.c
27
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++;
|
||||
//<2F><><EFBFBD><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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!");
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
cJSON *p_total_time = cJSON_GetObjectItem( pJsonRoot, "total_time" );
|
||||
if ( p_total_time )
|
||||
{
|
||||
cJSON_AddNumberToObject( json_send, "total_time", total_time );
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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);
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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 );
|
||||
}
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸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 );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>plug<75><67>setting<6E><67>Ŀ----------------------------------------------
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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 );
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user