diff --git a/TC1/main.c b/TC1/main.c index 3c97437..055fd71 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -54,7 +54,7 @@ void appRestoreDefault_callback( void * const user_config_data, uint32_t size ) { userConfigDefault->plug[i].task[j].hour = 0; userConfigDefault->plug[i].task[j].minute = 0; - userConfigDefault->plug[i].task[j].repeat = 0x80; + userConfigDefault->plug[i].task[j].repeat = 0x00; userConfigDefault->plug[i].task[j].on = 0; userConfigDefault->plug[i].task[j].action = 1; } diff --git a/TC1/user_function.c b/TC1/user_function.c index f611070..3bf564a 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -83,6 +83,16 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) cJSON *json_send = cJSON_CreateObject( ); cJSON_AddNumberToObject( json_send, "idx", user_config->plug[i].idx ); cJSON_AddNumberToObject( json_send, "nvalue", user_config->plug[i].on ); + cJSON_AddStringToObject( json_send, "mac", strMac ); + + char strTemp1[] = "plug_X"; + strTemp1[5] = i + '0'; + cJSON *json_send_plug_on = cJSON_CreateObject( ); + cJSON_AddNumberToObject( json_send_plug_on, "on", p_nvalue->valueint ); + + cJSON_AddItemToObject( json_send, strTemp1, json_send_plug_on ); + + char *json_str = cJSON_Print( json_send ); user_send( udp_flag, json_str ); //发送数据 free( json_str ); @@ -111,7 +121,7 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata ) { uint32_t now_time = UpTicks( ); os_log( "system_get_time:%d,%d = %09d\r\n", last_time, now_time, (now_time - last_time) ); - if ( now_time - last_time < 1000 && p_idx ) + if ( now_time - last_time < 1000 && p_idx ) { return_flag = false; } else diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c index 3d85f34..90124e5 100644 --- a/TC1/user_gpio.c +++ b/TC1/user_gpio.c @@ -98,21 +98,20 @@ static void key_short_press( void ) user_relay_set_all( 1 ); } - if ( user_config->idx >= 0 ) + uint8_t * buf = NULL; //[64] = { 0 }; + buf = malloc( 64 ); + if ( buf != NULL ) { - uint8_t * buf = NULL; //[64] = { 0 }; - buf = malloc( 64 ); - if ( buf != NULL ) - { - + if ( user_config->idx >= 0 ) sprintf( buf, "{\"idx\" : %d,\"mac\" : \"%s\",\"nvalue\" : %d}", user_config->idx, strMac, relay_out( ) ); - os_log("send %s", buf); - if ( !user_mqtt_isconnect( ) ) //发送数据 - user_udp_send( buf ); - else - user_mqtt_send( buf ); - free( buf ); - } + else + sprintf( buf, "{\"mac\" : \"%s\",\"nvalue\" : %d}", strMac, relay_out( ) ); + os_log("send %s", buf); + if ( !user_mqtt_isconnect( ) ) //发送数据 + user_udp_send( buf ); + else + user_mqtt_send( buf ); + free( buf ); } } @@ -156,7 +155,7 @@ static void key_timeout_handler( void* arg ) else if ( key_time == 103 ) { user_led_set( 0 ); - key_time=101; + key_time = 101; } } @@ -168,7 +167,7 @@ static void key_timeout_handler( void* arg ) key_time = 0; os_log("button short pressed:%d",key_time); key_short_press( ); - } else if(key_time > 100) + } else if ( key_time > 100 ) { MicoSystemReboot( ); } diff --git a/TC1/user_mqtt_client.c b/TC1/user_mqtt_client.c index 2d97f86..90e5f62 100644 --- a/TC1/user_mqtt_client.c +++ b/TC1/user_mqtt_client.c @@ -328,7 +328,7 @@ void mqtt_client_thread( mico_thread_arg_t arg ) require_noerr_string( err, MQTT_reconnect, "ERROR: MQTT publish data err" ); - mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld][%s].\r\n", p_send_msg->topic, p_send_msg->datalen, p_send_msg->data); + mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].\r\n", p_send_msg->topic, p_send_msg->datalen); no_mqtt_msg_exchange = false; free( p_send_msg ); p_send_msg = NULL; diff --git a/TC1/user_rtc.c b/TC1/user_rtc.c index 2ddb6bd..c83849e 100644 --- a/TC1/user_rtc.c +++ b/TC1/user_rtc.c @@ -161,11 +161,11 @@ void rtc_thread( mico_thread_arg_t arg ) if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值 rtc_time.sec == 0 && rtc_time.min == user_config->plug[i].task[j].minute && rtc_time.hr == user_config->plug[i].task[j].hour - && ((repeat == 0x80) || repeat & (1 << (rtc_time.weekday - 1))) + && ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1))) ) { user_relay_set( i, user_config->plug[i].task[j].action ); - if ( repeat == 0x80 ) + if ( repeat == 0x00 ) { user_config->plug[i].task[j].on = 0; update_user_config_flag = 1; diff --git a/TC1/user_udp.c b/TC1/user_udp.c index 10b2728..8158433 100644 --- a/TC1/user_udp.c +++ b/TC1/user_udp.c @@ -89,7 +89,7 @@ void udp_thread( void *arg ) strcpy( ip_address, inet_ntoa( addr.sin_addr ) ); if(len<1024) buf[len]=0; - os_log( "udp recv from %s:%d, len:%d :%s", ip_address,addr.sin_port, len ,buf); + os_log( "udp recv from %s:%d, len:%d ", ip_address,addr.sin_port, len ); user_function_cmd_received(1,buf); // sendto( udp_fd, buf, len, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in) ); } @@ -107,7 +107,7 @@ void udp_thread( void *arg ) err = udp_msg_send( udp_fd, p_send_msg->data, p_send_msg->datalen ); // require_noerr_string( err, MQTT_reconnect, "ERROR: udp publish data err" ); - os_log( "udp send data success! msg=[%ld][%s].\r\n", p_send_msg->datalen, p_send_msg->data ); + os_log( "udp send data success! msg=[%ld].\r\n", p_send_msg->datalen); free( p_send_msg ); p_send_msg = NULL; }