支持平台远程参数修改,上报数据规则修改
authorkyz <kongyuzhong@google.com>
Mon, 27 May 2024 04:12:10 +0000 (12:12 +0800)
committerkyz <kongyuzhong@google.com>
Mon, 27 May 2024 07:57:17 +0000 (15:57 +0800)
1.支持平台远程修改节气因子和气路选择,
2.修改参数后调用lfs读写参数,栈空间不够,tcp线程和at解析器两个task的栈扩展到2K
3.定时上报数据, 改为判断数据有变化上报,无变化不上报。
4.增加气体类型字段上报

LWIP/Target/lwipopts.h
doc/智能焊接设备上位机参数配置说明.md
user/at_parser.c
user/ht1622.c
user/user_app.c
user/user_eth.c
user/user_lfs.c
user/user_report.c
user/user_valve_ctrl.c
user/user_wifi.c

index a9468ca143e515a6fb8be8d59273753bed7b1341..a9bdcdb57aa37c978242c1cb804e188525ada6b3 100644 (file)
@@ -75,7 +75,7 @@
 /*----- Value in opt.h for LWIP_NETIF_LINK_CALLBACK: 0 -----*/
 #define LWIP_NETIF_LINK_CALLBACK 1
 /*----- Value in opt.h for TCPIP_THREAD_STACKSIZE: 0 -----*/
-#define TCPIP_THREAD_STACKSIZE 1024
+#define TCPIP_THREAD_STACKSIZE (1024*2)
 /*----- Value in opt.h for TCPIP_THREAD_PRIO: 1 -----*/
 #define TCPIP_THREAD_PRIO 24
 /*----- Value in opt.h for TCPIP_MBOX_SIZE: 0 -----*/
index 6e02ec6fc16e2dccfa246022b8a500a4bc2cceae..8eb26a93215cc493313e8322aad84e01ec06293b 100644 (file)
@@ -1,5 +1,5 @@
 # 智能焊接设备上位机参数配置说明
-V20240523
+V20240527
 
 按目前 固件v2.15  和工具v0.6 定义,参数配置功能说明
 
@@ -57,16 +57,22 @@ SMC流量计累计流量为软件实现,不需要使用修正系数,不受
 
 如选择自动探测,会增加一定的初始化时间
 
-选择自动探测:设备上电先通过485读取奥松流量计,失败则尝试通过485读取矽翔流量计,再失败则
+* 选择自动探测:设备上电先通过485读取奥松流量计,失败则尝试通过485读取矽翔流量计,再失败则
 按照SMC流量计读取ADC值, 三个都失败则报告流量计故障。
 
-选择指定流量计:则按对应接口读取指定流量计,失败则报告流量计故障。
+* 选择指定流量计:则按对应接口读取指定流量计,失败则报告流量计故障。
 
 该参数修改后,需要设备重新上电后生效。
 ### 7.2 气体
-三种气体选择,该参数目前仅对MF4008有效, 根据选择气体种类, 开机后会同步到流量计内部修正系数
+气体类型选择,可以设置值有默认气体、氩气、二氧化碳、混合气
+* 平台上报气体类型使用该参数
+如果选择氩气、二氧化碳或混合气,上报平台直接使用该参数的值上报平台
+如果选择默认气体,则按照修正系数值来确定气体类型值上报平台
 
+* 流量计MF4008,需要使用该参数
 如果开机后流量计指定了矽翔 MF4008, 或者自动探测到MF4008, 先从流量计内部读取气体修正值,和这个设置值比较,如果不一样,就将新的修正值通过RS485接口更新到流量计内部。
+
+* 其他流量计不使用该参数
 ### 8. 报警阈值
 设置低流量报警
 0 关闭
index fe6f3a9e0499c5b543de7e4c853ea67b4e8be87f..77dca7a8a7e9b6dac550f6958594bef85472d513 100644 (file)
@@ -210,7 +210,7 @@ static void at_worker_uart_send_mutex_deinit()
 
 static const osThreadAttr_t atworker_attributes = {
   .name = "atWork",
-  .stack_size = 1024,
+  .stack_size = 1024*2,
   .priority = (osPriority_t) osPriorityNormal,
 };
 int at_parser_init(void)
index 7a63e55c032294bf1d22c0a15a4f6a7bef6080e2..61b49051ff6ba3baecd5bc0577db916c72ceb0aa 100644 (file)
@@ -276,8 +276,8 @@ int32_t lcd_init_h3( void )
        volatile uint32_t test_ram_wr = 0x12345678;
        volatile uint32_t test_ram_rd = 0;
        
-         ht1622_ram_write( 0, &test_ram_wr, sizeof( test_ram_wr) );
-         ht1622_ram_read( 0, &test_ram_rd, sizeof( test_ram_rd ) );
+         ht1622_ram_write( 0, (uint8_t*)&test_ram_wr, sizeof( test_ram_wr) );
+         ht1622_ram_read( 0, (uint8_t*)&test_ram_rd, sizeof( test_ram_rd ) );
        
          if( test_ram_wr == test_ram_rd ){
                        printf( "ht122 lcd test ok, %02X\n", test_ram_wr);
@@ -726,7 +726,7 @@ void lcd_disp_all( void )
     disp_icon( icon_not_save_gas, DISP_OFF);
 
     disp_icon( icon_wifi, g_dev.wifi_connected?DISP_ON:DISP_OFF );
-    disp_icon( icon_link, (g_dev.wifi_connected==2||g_dev.eth_connected)?DISP_ON:DISP_OFF );
+    disp_icon( icon_link, (g_dev.wifi_connected==2||g_dev.eth_connected==2)?DISP_ON:DISP_OFF );
 
     if( g_disp.fault_code ){
         if( time_after( xTaskGetTickCount(), g_disp.fault_disp_time+1000 ) ){
index 085c427fcc9dfa0a1701ff31d68c5e3189e81fac..9251345695791d5e1c56a9e6bf5708fdb1b1bd5f 100644 (file)
@@ -347,12 +347,9 @@ void beep_init( void )
 
 void user_beep_task( void* unused )
 {
-    int i;
-       
                beep_init();
                beep_on( 50 );
 
-    //TODO: 实际使用有源, 待修改代码
     while(1){
 
         //气压和流量报警优先,     以上报警音,优先级, 气压报警  >  高流量报警 > 低流量报警 
index c47a61c58f247c921ea4fffa223ca0606e3d5d59..d33fdaa364fa6a4888f45c99a6e761197dc43f79 100644 (file)
@@ -37,6 +37,7 @@ static tcp_cli_t  g_iot_client;
 static tcp_cli_t  g_ota_client;
 
 extern char * devinfo_report_str( void );
+extern void iot_rpt_init( void );
 
 int32_t eth_devinfo_report( tcp_cli_t *client )
 {
@@ -49,6 +50,10 @@ int32_t eth_devinfo_report( tcp_cli_t *client )
     }
 
     rpt_data = devinfo_report_str();
+               if( !rpt_data ){
+                       //数据不变,不上报
+                       return 0;
+               }
 
     if( strlen( rpt_data) > tcp_sndbuf(g_iot_client.pcb) ){
         debug_printf( "tx len[%d] > sendbuf[%d]\n", strlen(rpt_data), tcp_sndbuf(g_iot_client.pcb) );
@@ -140,6 +145,11 @@ static err_t tcp_eth_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
     debug_printf( "tcp sent %d Bytes\n", len );
     return ERR_OK;
 }
+
+extern void iot_resp_req( uint8_t *resp, uint32_t sz );
+extern uint32_t resp_data_get( uint8_t **pdata, uint32_t *sz );
+extern void resp_data_clean( void );
+
 static int32_t iot_act_resp = 0;
 static err_t tcp_eth_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
 { 
@@ -174,7 +184,11 @@ static err_t tcp_eth_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t
                        int32_t act = iot_cmd_parse( 1, (char *)p->payload );
                        if( act == 1 || act == 2 ){
                                iot_act_resp = 1;
-            }
+                       }else if( act == 4){
+                                         //需要原包返回到平台
+                                         iot_resp_req( p->payload, p->tot_len );
+                                         iot_act_resp = 4;
+      }
                }else if( client == &g_ota_client ){
             //TODO:
             extern int32_t ota_handle_http_resp_data( uint8_t *rx_data, uint32_t rx_sz );
@@ -321,6 +335,8 @@ void user_eth_task( void* unused )
         }
 
         g_dev.eth_connected = 2;
+                               iot_rpt_init();
+
         //5.定时上报
         last_ticks = xTaskGetTickCount();
         rpt_secs = g_dev.cfg.iot_rpt_period;
@@ -343,6 +359,16 @@ void user_eth_task( void* unused )
                 if( tcp_write( g_iot_client.pcb, s, strlen(s), 1 ) == ERR_OK ){
                     tcp_output( g_iot_client.pcb );
                 }
+                iot_act_resp = 0;
+                                               }else if( iot_act_resp == 4 ){
+                                                         uint8_t *tx_buf;
+                                                       uint32_t tx_sz;
+                                                         if( resp_data_get( &tx_buf,&tx_sz) > 0 ){
+                                                                       if( tcp_write( g_iot_client.pcb, tx_buf, tx_sz, 1 ) == ERR_OK ){
+                                                                               tcp_output( g_iot_client.pcb );
+                                                                       }
+                                                                       resp_data_clean();
+                                                               }
                 iot_act_resp = 0;
             }
 
index e24b5dbdb29c47559495c60c582b7dfc0f706069..c004ded0d8e7216a328b6b5d649c37bad5aa2186 100644 (file)
@@ -183,4 +183,4 @@ int32_t lfs_store_offline_time( uint32_t secs )
             ret = 0;
     }
     return ret;
-}
\ No newline at end of file
+}
index 69efc71ebb71a65bc6057ec5dddc2064aeec2bd1..0459cc8e8646245a6bf66b2d7e4461c8d60908c6 100644 (file)
@@ -1,8 +1,18 @@
 #include "user.h"
 #include "cJSON.h"
 
+extern void ui_cfg_remote_update( void );
+
+__attribute__((section(".DTCM"),zero_init)) static uint8_t tcp_resp_buf[ 512 ];
+static uint16_t tcp_resp_n;
+
+
 static char mac_str_buf[20]; //"00:00:00:00:00:00";
+static char g_sw_ver[20];
 static char *g_mac_str;
+
+
+
 #if 0
 static const char *fmt = "{\n\
  \"cmd\":\"rt\",\n\
@@ -20,28 +30,104 @@ static const char *fmt = "{\n\
 
 #else
 static const char *fmt = "{\n\
- \"cmd\":\"rt\",\n\
- \"cid\":%d,\n\
- \"mac\":\"%s\",\n\
- \"val\":{\n\
-  \"c\":\"%0.1f\",\n\
-  \"s\":\"%d\",\n\
-  \"g\":\"%0.1f\"\n\
- },\n\
- \"weldTech\":\"%s\",\n\
- \"solarTermFactor\":\"%d\",\n\
- \"gasPressure\":\"%d\",\n\
- \"totalFlow\":\"%d\",\n\
- \"onlineStatus\":\"%d\",\n\
- \"softVersion\":\"V%d.%d\",\n\
- \"lock\":\"%d\",\n\
- \"deviceNo\":\"%s\",\n\
- \"gasPathType\":%d,\n\
- \"airRatio\":%d,\n\
- \"syncFrequency\":%d\n\
- }";
+\"cmd\":\"rt\",\n\
+\"cid\":%d,\n\
+\"mac\":\"%s\",\n\
+\"val\":{\n\
+ \"c\":\"%0.1f\",\n\
+ \"s\":\"%d\",\n\
+ \"g\":\"%0.1f\"\n\
+},\n\
+\"weldTech\":\"%s\",\n\
+\"solarTermFactor\":\"%d\",\n\
+\"gasPressure\":\"%d\",\n\
+\"totalFlow\":\"%d\",\n\
+\"onlineStatus\":\"%d\",\n\
+\"softVersion\":\"%s\",\n\
+\"lock\":\"%d\",\n\
+\"deviceNo\":\"%s\",\n\
+\"gasPathType\":%d,\n\
+\"airRatio\":%d,\n\
+\"syncFrequency\":%d,\n\
+\"gasType\":%d\n\
+}";
 
 #endif
+typedef struct{
+       uint32_t cid;
+       char* mac;
+       uint32_t curr_x10;
+       uint32_t weld_st;
+       uint32_t flow_x10;
+       uint32_t weld_tech;
+       uint32_t factor;
+       uint32_t pressure;
+       uint32_t total_flow;
+       uint32_t online_st;
+       char* ver;
+       uint32_t lock;
+       char* deviceNo;
+       uint32_t path;
+       uint32_t prev;
+       uint32_t freq;
+       uint32_t gas; //1,2,3
+}rpt_info_t;
+
+static rpt_info_t g_rpt_sent;
+
+
+extern float welding_curr_disp_value( float curr );
+static void mac_str_init( void );
+
+void iot_rpt_init( void )
+{
+       g_rpt_sent.online_st = 0;//改成0, 后面一定会上报一帧数据 
+}
+
+int32_t get_new_rpt_info( rpt_info_t *rpt )
+{
+       //return 0:正常上报,  -1:不上报
+       if(!rpt)
+               return -1;
+       
+  if( !g_mac_str ){
+        mac_str_init();
+  }
+
+       rpt->cid = g_rpt_sent.cid;
+       rpt->mac = g_mac_str;
+       rpt->curr_x10 = (uint32_t)(welding_curr_disp_value( g_dev.welding_current )*10);
+       rpt->weld_st = g_dev.welding_start;
+       rpt->flow_x10 = (uint32_t)(g_dev.flowmeter.flow_speed*10);
+       rpt->weld_tech = g_dev.cfg.welding_method;
+       rpt->factor = g_dev.cfg.save_gas_factor,
+       rpt->pressure = (uint32_t)g_dev.pressure;
+       rpt->total_flow = (uint32_t)g_dev.flowmeter.flow_total;
+       rpt->online_st = 1;
+       rpt->ver = g_sw_ver;
+       rpt->lock = g_dev.cfg.remote_locked==1?0:1;
+       rpt->deviceNo = g_dev.serial_number;
+       rpt->path = g_dev.cfg.bypass?0:1, //平台定义节气为1, 旁路为0
+       rpt->prev = g_dev.cfg.valve_open_default;
+       rpt->freq = g_dev.cfg.iot_rpt_period;
+       
+       if( g_dev.cfg2.gas > GAS_DEFAULT && g_dev.cfg2.gas <=  GAS_MAX ){
+               rpt->gas  = g_dev.cfg2.gas;
+       }else{
+               if( g_dev.cfg.cal.flow_coeff_x1000 == 570 )
+                       rpt->gas = 2;
+               else if( g_dev.cfg.cal.flow_coeff_x1000 == 910 )
+                       rpt->gas = 3;
+               else
+                       rpt->gas = 1;
+       }
+
+       if( memcmp( rpt, &g_rpt_sent, sizeof( g_rpt_sent ) ) ){
+               rpt->cid++;
+               return 0;
+       }
+       return -1;      
+}
 
 void offline_time_update( uint32_t add_secs )
        { 
@@ -72,41 +158,39 @@ static void mac_str_init( void )
     device_get_mac(mac);
     sprintf( mac_str_buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
     g_mac_str = mac_str_buf;
+               sprintf( g_sw_ver, "V%d.%d", APP_VER_MAJOR, APP_VER_MINOR );    
 }
 
 static const char * weld_method_str[3] = {"TIG", "MIG", "MAG" };
 
-extern float welding_curr_disp_value( float curr );
 char * devinfo_report_str( void )
 {
-    static uint32_t cid = 0;
     static char tx_buf[500];
-    float c,g;
-    uint32_t s;
+         static rpt_info_t to_rpt;
 
-    if( !g_mac_str ){
-        mac_str_init();
-    }
+         if( get_new_rpt_info( &to_rpt ) < 0 ){
+                       return NULL;
+               }
+               memcpy( &g_rpt_sent, &to_rpt, sizeof( g_rpt_sent ) );
 
-    //c = g_dev.welding_current;
-    g = g_dev.flowmeter.flow_speed;
-    s = g_dev.welding_start;
-
-    //+10A 到 -10A 上报0,与屏上显示一致
-               c = welding_curr_disp_value( g_dev.welding_current );
-
-    sprintf( (char*)tx_buf, fmt, cid++, g_mac_str, c, s, g,
-        weld_method_str[g_dev.cfg.welding_method],
-        g_dev.cfg.save_gas_factor,
-        (int)g_dev.pressure,
-        (int)g_dev.flowmeter.flow_total,
-        1,
-        APP_VER_MAJOR, APP_VER_MINOR,
-        g_dev.cfg.remote_locked==1?0:1,
-                               g_dev.serial_number,
-                               g_dev.cfg.bypass?0:1, //平台定义节气为1, 旁路为0
-                               g_dev.cfg.valve_open_default,
-                               g_dev.cfg.iot_rpt_period
+    sprintf( (char*)tx_buf, fmt, 
+                         g_rpt_sent.cid,
+                         g_rpt_sent.mac,
+                   g_rpt_sent.curr_x10/10.0f,
+                         g_rpt_sent.weld_st,
+                         g_rpt_sent.flow_x10/10.0f,
+        weld_method_str[g_rpt_sent.weld_tech],
+                         g_rpt_sent.factor,
+                         g_rpt_sent.pressure,
+                         g_rpt_sent.total_flow,
+                         g_rpt_sent.online_st,
+                         g_rpt_sent.ver,
+                         g_rpt_sent.lock,
+                         g_rpt_sent.deviceNo,
+                         g_rpt_sent.path,
+                         g_rpt_sent.prev,
+                         g_rpt_sent.freq,
+                         g_rpt_sent.gas
                                );
 
     return tx_buf;
@@ -135,8 +219,39 @@ char * lock_resp_str( void )
     return tx_buf;
 }
 
+#if 0
+//节气因子,远程修改
+{
+    "action":"updateSolarTermFactor",
+    "timeStamp":1716445485381,
+    "data":{
+          "mac":"123",
+       "solarTermFactor":"10"
+    }
+}
+//气路选择,远程修改
+{
+    "action":"updateGasPathType",
+    "timeStamp":1716445485381,
+    "data":{
+          "mac":"123",
+          // 1 节气  0不节气
+       "gasPathType":1
+    }
+}
+//设备回应,原包返回
+#endif
+
 int32_t iot_cmd_parse( uint32_t link, char *cmd )
 {
+       cJSON * data;
+       cJSON * ver;
+       cJSON * url;
+       cJSON * mac;
+       cJSON * gasPathType;
+       cJSON * solarTermFactor;
+       
+       
                        int32_t act = 0;
                        cJSON*root = cJSON_Parse( (char*)cmd );
                        if( root ){
@@ -149,6 +264,38 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd )
                                                g_dev.cfg.remote_locked = 1;
                                                dev_cfg_store( &g_dev.cfg );
                                                act = 1;
+                                       }else if( strcmp( action->valuestring, "updateSolarTermFactor" )== 0 ){
+                                                       data = cJSON_GetObjectItem( root, "data" );
+                                                       debug_printf( "-----ota----- " );
+                                                       if(data){
+                                                               mac = cJSON_GetObjectItem( data, "mac" );
+                                                               solarTermFactor = cJSON_GetObjectItem( data, "solarTermFactor" );
+                                                               if( mac && solarTermFactor && strcasecmp( mac->valuestring, g_mac_str ) == 0 ){
+                                                                         int32_t factor = atoi( solarTermFactor->valuestring );
+                                                                         if( factor >=2 && factor <=30 ){
+                                                                                         g_dev.cfg.save_gas_factor = factor;
+                                                                                               dev_cfg_store( &g_dev.cfg );
+                                                                                               ui_cfg_remote_update();
+                                                                                         act = 4; //原包回发。
+                                                                               }
+                                                               }
+                                                       }
+                                       }else if( strcmp( action->valuestring, "updateGasPathType" )== 0 ){
+                                                       data = cJSON_GetObjectItem( root, "data" );
+                                                       debug_printf( "-----ota----- " );
+                                                       if(data){
+                                                               mac = cJSON_GetObjectItem( data, "mac" );
+                                                               gasPathType = cJSON_GetObjectItem( data, "gasPathType" );
+                                                               if( mac && gasPathType && strcasecmp( mac->valuestring, g_mac_str ) == 0 ){
+                                                                               if( gasPathType->valueint == 1 || gasPathType->valueint == 0 ){ // 1 节气  0不节气
+                                                                                         g_dev.cfg.bypass = (g_dev.has_bypass &&  gasPathType->valueint == 0)?1:0;
+                                                                                               dev_cfg_store( &g_dev.cfg );
+                                                                                         ui_cfg_remote_update();
+                                                                                         act = 4; //原包回发。
+                                                                               }
+                                                               }
+                                                       }
+                                               
                                        }else if( strcmp( action->valuestring, "unlockDevice" )== 0 ){
                                                debug_printf( "unlockdevice %d->0\n", g_dev.cfg.remote_locked );
                                                g_dev.cfg.remote_locked = 0;
@@ -156,9 +303,7 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd )
                                                act = 2;
                                        }else if( strcmp( action->valuestring, "update" )== 0 ){
                                                //ota;
-                                               cJSON * data;
-                                               cJSON * ver;
-                                               cJSON * url;
+
                                                data = cJSON_GetObjectItem( root, "data" );
                                                debug_printf( "-----ota----- " );
                                                if(data){
@@ -193,3 +338,23 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd )
                        }
                        return act;
 }
+
+void iot_resp_req( uint8_t *resp, uint32_t sz )
+{
+       if( sz > sizeof( tcp_resp_buf) )
+               sz = sizeof(tcp_resp_buf);
+       memcpy( tcp_resp_buf, resp, sz );
+       tcp_resp_n = sz;
+}
+
+uint32_t resp_data_get( uint8_t **pdata, uint32_t *sz )
+{
+       *pdata = tcp_resp_buf;
+       *sz = tcp_resp_n;
+       return tcp_resp_n;
+}
+void resp_data_clean( void )
+{
+       tcp_resp_n = 0;
+}
+
index 1e532529368a35aa040041d8a39d6ae11c1718fb..87511149c64641acd9f3f05e58f70f9f0afb8e3d 100644 (file)
@@ -681,4 +681,3 @@ void pressure_alarm_check( void )
         g_dev.alarm.pressure_high = 0;
     }
 }
- 
\ No newline at end of file
index 7484297eb8e6b5e73fe88bb38a4f385347d5d948..4394cffb6c3afb6434f44fd24ecb2699a7781d2e 100644 (file)
@@ -16,6 +16,7 @@
 extern int32_t ota_handle_http_resp_data( uint8_t *rx_data, uint32_t rx_sz );
 extern int32_t wifi_ota_start( char * url, char *ver );
 extern char * devinfo_report_str( void );
+extern void iot_rpt_init( void );
 
 extern UART_HandleTypeDef huart5;
 
@@ -40,6 +41,9 @@ static uint16_t tcp_rx_n;
 __attribute__((section(".DTCM"),zero_init)) static uint8_t ota_rx_buf[2048];
 static uint16_t ota_rx_n;
 
+
+
+
 int32_t wifi_tcp_tx( uint8_t link, uint8_t *data, uint32_t sz );
 
 void wifi_uart_rx_start( void )
@@ -238,11 +242,19 @@ int32_t wifi_devinfo_report( void )
     char * rpt_data;
 
     rpt_data = devinfo_report_str();
+               if( !rpt_data ){
+                       //数据不变,不上报
+                       return 0;
+               }
     wifi_tcp_tx( CONN_ID_IOT, (uint8_t *)rpt_data, strlen((char *)rpt_data) );
 
     return 0;
 }
 
+extern void iot_resp_req( uint8_t *resp, uint32_t sz );
+extern uint32_t resp_data_get( uint8_t **pdata, uint32_t *sz );
+extern void resp_data_clean( void );
+
 static int32_t iot_act_resp = 0;
 static void tcp_rx_data_handle(void *arg, char *rspinfo, int rsplen)
 {
@@ -304,6 +316,11 @@ static void tcp_rx_data_handle(void *arg, char *rspinfo, int rsplen)
                                                //char * s = lock_resp_str();
                                                //wifi_tcp_tx(0, (uint8_t*)s, strlen(s) );
                                                iot_act_resp = 1;
+                               }else if( act == 4){
+                                         //需要原包返回到平台
+                                       
+                                         iot_resp_req( tcp_rx_buf, tcp_rx_n );
+                                         iot_act_resp = 4;
                                }
                        }
                        tcp_rx_n = 0;
@@ -387,6 +404,12 @@ int32_t wifi_tcp_tx( uint8_t conn_id, uint8_t *data, uint32_t sz )
     return ret;
 }
 
+static void wifi_tcp_closed_cb(void *arg, char *rspinfo, int rsplen)
+{
+       if( g_dev.wifi_connected == 2 )
+               g_dev.wifi_connected = 1 ;
+}
+
 void user_wifi_task( void* unused )
 {
     char *ssid;
@@ -409,7 +432,7 @@ void user_wifi_task( void* unused )
     }
 
     at_register_callback("+IPD", NULL, NULL, 0, tcp_rx_data_handle, NULL);
-//  at_register_callback( "link is not valid", NULL, NULL, 0, link_down, NULL );
+    at_register_callback( "0,CLOSED", NULL, NULL, 0, wifi_tcp_closed_cb, NULL );
     while( 1 ){
 
         ssid = g_dev.cfg.net.wifi_ssid;
@@ -432,6 +455,9 @@ void user_wifi_task( void* unused )
             //tcp connect
             if( tcp_server_connect( CONN_ID_IOT, g_dev.cfg.net.tcp_server, g_dev.cfg.net.tcp_port ) == 0 ){
                 g_dev.wifi_connected = 2;
+                                                         if( g_dev.eth_connected != 2 ){
+                                                                       iot_rpt_init(); //tcp连接上,开始上报一帧数据, 以免设备信息不变一直不上报。
+                                                               }
             }else{
                 osDelay( 1000 );
                 continue;
@@ -450,6 +476,14 @@ void user_wifi_task( void* unused )
                                                        char * s = lock_resp_str();
                                                        wifi_tcp_tx( CONN_ID_IOT, (uint8_t*)s, strlen(s) );
                                                        iot_act_resp = 0;
+                                               }else if( iot_act_resp == 4 ){
+                                                         uint8_t *tx_buf;
+                                                       uint32_t tx_sz;
+                                                         if( resp_data_get( &tx_buf,&tx_sz) > 0 ){
+                                                                       wifi_tcp_tx( CONN_ID_IOT, tx_buf, tx_sz );
+                                                                       resp_data_clean();
+                                                               }
+                iot_act_resp = 0;
                                                }
             if( g_dev.eth_connected == 2 ){
                 //如果有线已经连接,wifi不上传数据