diff --git a/TC1/main.h b/TC1/main.h index 82d3992..7be0590 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -4,7 +4,7 @@ #include "mico.h" #include "MiCOKit_EXT.h" -#define VERSION "v0.10" +#define VERSION "v0.10.1" #define TYPE 1 #define TYPE_NAME "zTC1" diff --git a/TC1/user_function.c b/TC1/user_function.c index 9046806..b969fa0 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -75,6 +75,14 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) cJSON *json_send = cJSON_CreateObject( ); cJSON_AddStringToObject( json_send, "mac", strMac ); + //解析重启命令 +// cJSON *p_cmd = cJSON_GetObjectItem( pJsonRoot, "name" ); + if(p_cmd && cJSON_IsString( p_cmd ) && strcmp( p_cmd->valuestring, "restart" ) == 0) + { + os_log("cmd:restart"); + mico_system_power_perform( mico_system_context_get( ), eState_Software_Reset ); + } + //解析版本 cJSON *p_version = cJSON_GetObjectItem( pJsonRoot, "version" ); if ( p_version ) @@ -247,7 +255,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_name( x ); } cJSON_AddStringToObject( json_plug_setting_send, "name", user_config->plug[x].name ); } diff --git a/TC1/user_mqtt_client.c b/TC1/user_mqtt_client.c index 4d26083..96f98bf 100644 --- a/TC1/user_mqtt_client.c +++ b/TC1/user_mqtt_client.c @@ -99,14 +99,22 @@ char topic_state[MAX_MQTT_TOPIC_SIZE]; char topic_set[MAX_MQTT_TOPIC_SIZE]; mico_timer_t timer_handle; -static uint8_t status = 0; +static uint8_t timer_status = 0; void user_mqtt_timer_func( void *arg ) { uint8_t *buf1 = NULL; + + LinkStatusTypeDef LinkStatus; + micoWlanGetLinkStatus( &LinkStatus ); + if ( LinkStatus.is_connected != 1 ) + { + mico_stop_timer( &timer_handle ); + return; + } if ( mico_rtos_is_queue_empty( &mqtt_msg_send_queue ) == true ) { - status++; - switch ( status ) + timer_status++; + switch ( timer_status ) { case 1: user_mqtt_hass_auto_power( ); @@ -401,11 +409,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 ) ) - { - mico_stop_timer( &timer_handle ); -// mico_deinit_timer( &timer_handle ); - } + timer_status=100; mqtt_client_release( &c, &n ); isconnect = false; @@ -428,11 +432,7 @@ static void messageArrived( MessageData* md ) OSStatus err = kUnknownErr; p_mqtt_recv_msg_t p_recv_msg = NULL; MQTTMessage* message = md->message; - /* - app_log("MQTT messageArrived callback: topiclen=[%d][%s],\t payloadlen=[%d][%s]",md->topicName->lenstring.len, - md->topicName->lenstring.data,(int)message->payloadlen,(char*)message->payload); - */ -// mqtt_log("======MQTT received callback ![%d]======", MicoGetMemoryInfo()->free_memory ); + p_recv_msg = (p_mqtt_recv_msg_t) calloc( 1, sizeof(mqtt_recv_msg_t) ); require_action( p_recv_msg, exit, err = kNoMemoryErr ); diff --git a/TC1/user_power.c b/TC1/user_power.c index b0158f3..8a4c50c 100644 --- a/TC1/user_power.c +++ b/TC1/user_power.c @@ -24,7 +24,7 @@ static void power_timer_handler( void* arg ) { timer = (clock_count - clock_count_last); - os_log("power_irq_handler:%09u %u %u",timer,timer_irq_count,timer_count); +// os_log("power_irq_handler:%09u %u %u",timer,timer_irq_count,timer_count); if ( timer_count > 3 ) { timer /= 1000; diff --git a/TC1/user_wifi.c b/TC1/user_wifi.c index 07c839f..4811c28 100644 --- a/TC1/user_wifi.c +++ b/TC1/user_wifi.c @@ -34,7 +34,7 @@ void wifi_start_easylink( ) micoWlanStartEasyLink( 20000 ); user_led_set( 1 ); } -uint32_t ip = 0xd248912c; + //easylink 完成回调 void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg ) { 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 265a967..3000aa3 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 8944502..067c0ce 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