/**************************************************************** FunctionName : GAgent_CloudTick. Description : GAgent Send cloud heartbeat to cloud when mqttstatus is MQTT_STATUS_RUNNING Add by Alex.lin --2015-03-10 ****************************************************************/ void GAgent_CloudTick( pgcontext pgc ) { uint32 cTime=0,dTime=0; if( pgc->rtinfo.waninfo.mqttstatus != MQTT_STATUS_RUNNING ) return; cTime = GAgent_GetDevTime_MS(); dTime = abs(cTime - pgc->rtinfo.waninfo.send2MqttLastTime ); if( dTime < CLOUD_HEARTBEAT ) return ; if(pgc->rtinfo.waninfo.cloudPingTime > 2 ) { ERRORCODE pgc->rtinfo.waninfo.cloudPingTime=0; GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_STATUS,1 ); } else { MQTT_HeartbeatTime(); pgc->rtinfo.waninfo.cloudPingTime++; GAgent_Printf(GAGENT_INFO,"GAgent MQTT Ping ..."); } pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS(); }
/**************************************************************** FunctionName : GAgent_CloudTick. Description : GAgent Send cloud heartbeat to cloud when mqttstatus is MQTT_STATUS_RUNNING Add by Alex.lin --2015-03-10 ****************************************************************/ void GAgent_CloudTick( pgcontext pgc,uint32 dTime_s ) { if( pgc->rtinfo.waninfo.mqttstatus != MQTT_STATUS_RUNNING ) { GAgent_Printf(GAGENT_INFO, "MQTT is not running\r\n"); return; } pgc->rtinfo.waninfo.send2MqttLastTime +=dTime_s; if( pgc->rtinfo.waninfo.send2MqttLastTime >= CLOUD_HEARTBEAT ) { GAgent_Printf(GAGENT_DEBUG, "send2MqttLastTime >= CLOUD_HEARTBEAT\r\n"); pgc->rtinfo.waninfo.send2MqttLastTime = 0; if(0) // pgc->rtinfo.waninfo.cloudPingTime > 2 ) { ERRORCODE pgc->rtinfo.waninfo.cloudPingTime=0; pgc->rtinfo.waninfo.wanclient_num = 0; pgc->rtinfo.waninfo.ReConnectMqttTime = 0; GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); } else { MQTT_HeartbeatTime(); pgc->rtinfo.waninfo.cloudPingTime++; GAgent_Printf( GAGENT_CRITICAL,"GAgent Cloud Ping ..." ); } } else GAgent_Printf(GAGENT_DEBUG, "send2MqttLastTime:%d CLOUD_HEARTBEAT:%d\r\n", pgc->rtinfo.waninfo.send2MqttLastTime, CLOUD_HEARTBEAT); }