From 2fd16b4239bbf22e6ec54a273830cfc72b0afd3c Mon Sep 17 00:00:00 2001 From: Zip <76966589@qq.com> Date: Thu, 14 Mar 2019 17:27:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E6=8C=89=E4=B8=8B=E5=8F=91=E9=80=81=E9=80=BB=E8=BE=91=20?= =?UTF-8?q?=E5=B7=B2=E7=9F=A5issue:=E6=8C=89=E9=94=AE=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=A4=8D=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/user_gpio.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c index c6b493f..8607c3a 100644 --- a/TC1/user_gpio.c +++ b/TC1/user_gpio.c @@ -3,6 +3,7 @@ #include "main.h" #include "user_gpio.h" #include "user_mqtt_client.h" +#include "user_udp.h" #include "cJSON/cJSON.h" mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 }; @@ -70,29 +71,35 @@ static void key_long_press( void ) static void key_short_press( void ) { char i; - - cJSON *json_send = cJSON_CreateObject( ); - - cJSON_AddStringToObject( json_send, "mac", strMac ); - if ( user_config->idx >= 0 ) cJSON_AddNumberToObject( json_send, "idx", user_config->idx ); + OSStatus err; if ( relay_out( ) ) { user_relay_set_all( 0 ); - cJSON_AddNumberToObject( json_send, "nvalue", 1 ); } else { user_relay_set_all( 1 ); - cJSON_AddNumberToObject( json_send, "nvalue", 0 ); } - char *json_str = cJSON_Print( json_send ); - if ( !user_mqtt_isconnect() )//发送数据 - user_udp_send( json_str ); - else - user_mqtt_send( json_str ); - free( (void *) json_str ); + uint8_t *buf = NULL; + if ( user_config->idx >= 0 ) + { + + buf = malloc( 1024 ); + require_action( buf, exit, err = kNoMemoryErr ); + + sprintf( buf, "{\"idx\" : %d,\"mac\" : \"%s\",\"nvalue\" : %d}", user_config->idx,strMac, relay_out() ); + if ( !user_mqtt_isconnect( ) ) //发送数据 + user_udp_send( buf ); + else + user_mqtt_send( buf ); + } + exit: + if ( err != kNoErr ) + os_log("key_short_press Send data with err: %d", err); + if ( buf != NULL ) free( buf ); + } void key_init( void )