PING ICMP Client

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

You'll learn how to use the new function to send a PING request and read the response time (or error codes)

Only Flyport PRO Wi-Fi and Ethernet does support this feature.
Flyport IDE PRO 2.10.0 (or greater) must be used for this feature.

Disclaimer

As always this is all free software provided as is, no explicit and/or implied responsibilities are admitted and/or accepted.

ICMP Client Service

This tutorial works only if ICMP Client Service is enabled on IDE Wizard tool.

Network configuration for Flyport Wi-Fi module

To reach a remote host with PING requests, Flyport must be connected to a Internet-enabled router (DSL or similar).
Please change network parameters on IDE Wizard to let Flyport Wi-Fi module connect to your router.

Code

Explanation

ICMP Client allows to send a PING request to both a remote host or a local LAN host.
A ping request is a sort-of echo signal that starts from Client -> arrives to Server -> then comes back to Client.
The time of the whole operation is the Ping Response Time (or to say in better words
it is the round-trip time for messages sent from the originating host to a destination computer and back).

PING can also be used to understand if used network do have some problems, for example executing a ping to a host which
we know it is certainly working, or to measure some the data packet transmission performances.

Usage

Just compile and download the firmware to a FlyportPRO Wi-Fi or FlyportPRO Ethernet, open the IDE Serial monitor and type the following commands:

  • 1: Send a ping request to provided local IP address. Please change it with your PC or another connected device (a smartphone, a tablet, etc...)
  • 2: Send a ping request to "www.openpicus.com"
  • 3: Send a ping request to a wrong local IP address.
  • 4: Send a ping request to a wrong host name.


Results will be shown on Serial monitor when the operation will be completed.

Source

Here is the entire taskFlyport.c

#include "taskFlyport.h"
 
char buff[250];
 
void FlyportTask()
{    
#if !defined(STACK_USE_ICMP_CLIENT)
    #error Please Enable ICMP Client service from IDE Wizard
#endif        
    vTaskDelay(25);
#ifdef FLYPORT_G
    WFConnect(WF_DEFAULT);
    while(WFGetStat() != CONNECTED);
    vTaskDelay(25);
    _dbgline("Flyport Wi-fi PRO connected...hello world!");
#elif defined FLYPORT_ETH
    while(!MACLinked);
    vTaskDelay(25);
    _dbgline("Flyport Ethernet PRO cable connected...hello world!");
#endif
 
    _dbgline("\nPing test...\n1 - For IP\n2 - For host name\n3 - For bad IP\n4 - For bad host name\n");
 
    while(1)
    {
        if(UARTBufferSize(1) != 0)
        {
            UARTRead(1, buff, 1);
            vTaskDelay(20);
            UARTFlush(1);
 
            _dbgwrite("Cmd: ");
            UARTWriteCh(1, buff[0]);
            _dbgwrite("\r\n");
 
            switch(buff[0])
            {
                case '1':
#warning please change IP address, using your local device (for example a PC or a Smartphone)
                    PINGStart("192.168.0.101", 5);
                    break;
                case '2':
                    PINGStart("www.openpicus.com", 5);
                    break;
                case '3':
                    PINGStart("192.168.0.70", 10);
                    break;
                case '4':
                    PINGStart("www.openpicus121.com", 15);
                    break;
            }
        }
 
        // Since each usage of PINGStat() function actually clears it's value
        // (except of "PING_RUNNING" status) it is a best pratice to use a 
        // temporary variable to store the actual ping status value, 
        // and then process its value with conditional operators:
        int pStat = PINGStat();
 
        if((pStat == PING_OK)||(pStat == PING_ERR))
        {
            int pVal = PINGVal();
            if(pVal >= 0)
            {
                sprintf(buff, "PING response: %d ms", pVal);
                _dbgline(buff);
            }
            else if(pVal == PING_TIMEOUT_ERR)
            {
                _dbgline("Timeout error on PING");
            }
            else if(pVal == PING_LONG_ADDR_ERR)
            {
                _dbgline("Too long address error on PING");
            }
            else if(pVal == PING_DNS_ERR)
            {
                _dbgline("DNS error on PING");
            }
            else if(pVal == PING_NO_WIFI_ERR)
            {
                _dbgline("Task error on PING: ping function must be used with TCP/IP Task active");
            }
            else if(pVal == PING_IN_USE_ERR)
            {
                _dbgline("PING function is busy");
            }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox