mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18: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;
|
int i;
|
||||||
os_log( "Start %s",VERSION );
|
os_log( "Start %s",VERSION );
|
||||||
|
|
||||||
|
uint8_t main_num=0;
|
||||||
|
uint32_t power_last = 0xffffffff;
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
// for ( i = 0; i < Relay_NUM; i++ )
|
// for ( i = 0; i < Relay_NUM; i++ )
|
||||||
@@ -163,13 +165,24 @@ int application_start( void )
|
|||||||
// app_httpd_start();
|
// app_httpd_start();
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
// mico_thread_msleep(500);
|
main_num++;
|
||||||
// MicoGpioOutputTrigger(MICO_GPIO_5);
|
//<2F><><EFBFBD><EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
// mico_gpio_output_toggle( MICO_SYS_LED );
|
if ( power_last != power || main_num>4 )
|
||||||
// mico_rtos_delay_milliseconds(1000);
|
{
|
||||||
// uint32_t a=mico_nanosecond_clock_value();
|
power_last = power;
|
||||||
// os_log("nano=%lu",a/1000);
|
main_num =0;
|
||||||
// mico_rtos_delay_milliseconds(1000);
|
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:
|
exit:
|
||||||
os_log("application_start ERROR!");
|
os_log("application_start ERROR!");
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ void user_function_set_last_time( )
|
|||||||
last_time = UpTicks( );
|
last_time = UpTicks( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool json_plug_analysis( int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON * pJsonSend );
|
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 )
|
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);
|
os_log("version:%s",VERSION);
|
||||||
cJSON_AddStringToObject( json_send, "version", 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-----------------------------------------------------------------
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>setting-----------------------------------------------------------------
|
||||||
cJSON *p_setting = cJSON_GetObjectItem( pJsonRoot, "setting" );
|
cJSON *p_setting = cJSON_GetObjectItem( pJsonRoot, "setting" );
|
||||||
if ( p_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 );
|
sprintf( user_config->mqtt_password, p_mqtt_password->valuestring );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸ota
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸ota
|
||||||
if ( p_ota ) cJSON_AddStringToObject( json_setting_send, "ota", p_ota->valuestring );
|
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 );
|
cJSON_AddStringToObject( json_send, "name", sys_config->micoSystemConfig.name );
|
||||||
|
|
||||||
|
|
||||||
if ( return_flag == true )
|
if ( return_flag == true )
|
||||||
{
|
{
|
||||||
char *json_str = cJSON_Print( json_send );
|
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 );
|
user_relay_set( x, p_plug_on->valueint );
|
||||||
return_flag = true;
|
return_flag = true;
|
||||||
}
|
}
|
||||||
user_mqtt_send_plug_state(x);
|
user_mqtt_send_plug_state( x );
|
||||||
}
|
}
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD>plug<75><67>setting<6E><67>Ŀ----------------------------------------------
|
//<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;
|
return_flag = true;
|
||||||
sprintf( user_config->plug[x].name, p_plug_setting_name->valuestring );
|
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 );
|
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;
|
OSStatus err = kUnknownErr;
|
||||||
LinkStatusTypeDef LinkStatus;
|
LinkStatusTypeDef LinkStatus;
|
||||||
mico_rtc_time_t rtc_time;
|
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;
|
||||||
mico_utc_time_t utc_time_last;
|
mico_utc_time_t utc_time_last;
|
||||||
@@ -127,6 +126,7 @@ void rtc_thread( mico_thread_arg_t arg )
|
|||||||
err = user_sntp_get_time( );
|
err = user_sntp_get_time( );
|
||||||
if ( err == kNoErr )
|
if ( err == kNoErr )
|
||||||
{
|
{
|
||||||
|
os_log("sntp success!");
|
||||||
rtc_init = 1;
|
rtc_init = 1;
|
||||||
break;
|
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 );
|
mico_rtos_thread_msleep( 900 );
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user