Hi,
I am using CC3220 device for the IOT. Recently I founded an issue in my device. Issue is related to the PING to the gateway.
Explanation.
My device is pinging to the gateway to check the internet capability. Once device connected with the router, device start to check the internet is available or not via ping method.
Issue.
My ping response was generated but number of received packet was zero. @sl_NetAppPing API does not return any error code after the call.
Please have a look code.
bool volatile pingResponseDone = false; #define PING_INTERVAL (2000) /* In msecs */ #define PING_TIMEOUT (3000) /* In msecs */ #define PING_PKT_SIZE (150) /* In bytes */ #define NO_OF_ATTEMPTS (5) void SimpleLinkPingReport(SlNetAppPingReport_t *pPingReport) { uint32_t successRate = 0; successRate = ((pPingReport->PacketsReceived * 100) / pPingReport->PacketsSent); WMLogInfo(GEN_LOG,"Ping done. Success rate: %d%% \r\n", successRate); WMLogInfo(GEN_LOG, "number of packet send %ld and received %ld", pPingReport->PacketsSent, pPingReport->PacketsReceived); if(successRate > 40) { MSD_deviceConfigAndPacket.deviceInternetFailure = false; } else { //we have a problem here. if(successRate <= 40) { //Internet net is not available or very slow //can't process anything now MSD_deviceConfigAndPacket.deviceInternetFailure = true; //connection ERROR MSD_deviceConfigAndPacket.deviceMQTTConnectionError = true; //MQTT connection error MSD_LedMode = MQTT_CONNECTION_ERROR; } } pingResponseDone = false; } static int32_t CheckLanConnection() { SlNetAppPingCommand_t pingParams = {0}; SlNetAppPingReport_t pingReport = {0}; static uint32_t lastPingTime = 0; int32_t retVal = -1; if (pingResponseDone) { uint32_t currentTimeStamp = ClockP_getSystemTicks(); //check the time-out happen or not //wait for the 40 second time-out //if API failed to send the ping request response won't generate //so after the 40 second try to send ping request again if((currentTimeStamp - lastPingTime) > (1000 * 40)) { WMLogInfo(GEN_LOG,"Pinging request time-out happend.!.....send new ping request.."); pingResponseDone = false; //if @sl_NetAppPing failed, ping response won't be generated and may be internet is available //so make false this flag to allow go for the internet connectivity //if this flag is true it will not allow to connect MQTT MSD_deviceConfigAndPacket.deviceInternetFailure = false; lastPingTime = currentTimeStamp; } return retVal; } uint32_t hostIp = 0; retVal = sl_NetAppDnsGetHostByName((_i8*) "www.wimerasys.com", strlen("www.wimerasys.com"), (_u32*) &hostIp, 2); /* Set the ping parameters */ pingParams.PingIntervalTime = PING_INTERVAL; pingParams.PingSize = PING_PKT_SIZE; pingParams.PingRequestTimeout = PING_TIMEOUT; pingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS; pingParams.Flags = 0; pingParams.Ip = sl_Htonl(hostIp); // destination IP address from wimerasys.com /* Ping the GW */ retVal = sl_NetAppPing((SlNetAppPingCommand_t*)&pingParams, \ SL_AF_INET, (SlNetAppPingReport_t*)&pingReport, \ SimpleLinkPingReport); pingResponseDone = true; //take the ping request time lastPingTime = ClockP_getSystemTicks(); ASSERT_ON_ERROR(retVal, "sl_NetAppPing() failed"); WMLogInfo(GEN_LOG,"Pinging GW...! to address (%d.%d.%d.%d) wait for the response!..", ((uint8_t*)&pingParams.Ip)[0], ((uint8_t*)&pingParams.Ip)[1], ((uint8_t*)&pingParams.Ip)[2], ((uint8_t*)&pingParams.Ip)[3]); return(retVal); }
Please find the log of the generated report.
GEN:Ping done. Success rate: 0% GEN:number of packet send 5 and received 0 GEN:Pinging GW...! to address (166.62.28.82) wait for the response!..