From 243b1caf63f3d91b9638ec7a6588e66b56dd2deb Mon Sep 17 00:00:00 2001 From: kyz Date: Fri, 7 Jun 2024 15:51:53 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=BF=83=E8=B7=B3=E5=8C=85?= =?utf8?q?=E4=B8=8A=E6=8A=A5=E5=B9=B3=E5=8F=B030=E7=A7=92=E4=B8=80?= =?utf8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- user/user_report.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/user/user_report.c b/user/user_report.c index 6ce62bd..bef75e8 100644 --- a/user/user_report.c +++ b/user/user_report.c @@ -53,6 +53,9 @@ static const char *fmt = "{\n\ }"; #endif + +static const char* keepalive_fmt ="{ \"action\":\"heartbeat\", \"mac\":\"%s\" }"; + typedef struct{ uint32_t cid; char* mac; @@ -163,13 +166,28 @@ static void mac_str_init( void ) static const char * weld_method_str[3] = {"TIG", "MIG", "MAG" }; + + char * devinfo_report_str( void ) { static char tx_buf[500]; - static rpt_info_t to_rpt; + static rpt_info_t to_rpt; + static uint32_t last_rpt_tick = 0; + uint32_t now = xTaskGetTickCount(); + + if( last_rpt_tick == 0 ) + last_rpt_tick = now; if( get_new_rpt_info( &to_rpt ) < 0 ){ - return NULL; + if( now - last_rpt_tick < 30*1000 ){ + //数据没有变化,不上报 + return NULL; + }else{ + //30秒上报一个心跳包 + sprintf( (char*)tx_buf, keepalive_fmt, g_mac_str ); + last_rpt_tick = now; + return tx_buf; + } } memcpy( &g_rpt_sent, &to_rpt, sizeof( g_rpt_sent ) ); @@ -192,7 +210,7 @@ char * devinfo_report_str( void ) g_rpt_sent.freq, g_rpt_sent.gas ); - + last_rpt_tick = now; return tx_buf; } -- 2.34.1